Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 23 Jun 2014 01:28:18 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r267760 - head/sys/kern
Message-ID:  <201406230128.s5N1SIYK097224@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Mon Jun 23 01:28:18 2014
New Revision: 267760
URL: http://svnweb.freebsd.org/changeset/base/267760

Log:
  Tidy up fd-related functions called by do_execve
  
  o assert in each one that fdp is not shared
  o remove unnecessary NULL checks - all userspace processes have fdtables
  and kernel processes cannot execve
  o remove comments about the danger of fd_ofiles getting reallocated - fdtable
  is not shared and fd_ofiles could be only reallocated if new fd was about to be
  added, but if that was possible the code would already be buggy as setugidsafety
  work could be undone
  
  MFC after:	1 week

Modified:
  head/sys/kern/kern_descrip.c

Modified: head/sys/kern/kern_descrip.c
==============================================================================
--- head/sys/kern/kern_descrip.c	Mon Jun 23 01:10:56 2014	(r267759)
+++ head/sys/kern/kern_descrip.c	Mon Jun 23 01:28:18 2014	(r267760)
@@ -2081,15 +2081,8 @@ setugidsafety(struct thread *td)
 	struct file *fp;
 	int i;
 
-	/* Certain daemons might not have file descriptors. */
 	fdp = td->td_proc->p_fd;
-	if (fdp == NULL)
-		return;
-
-	/*
-	 * Note: fdp->fd_ofiles may be reallocated out from under us while
-	 * we are blocked in a close.  Be careful!
-	 */
+	KASSERT(fdp->fd_refcnt == 1, ("the fdtable should not be shared"));
 	FILEDESC_XLOCK(fdp);
 	for (i = 0; i <= fdp->fd_lastfile; i++) {
 		if (i > 2)
@@ -2141,15 +2134,8 @@ fdcloseexec(struct thread *td)
 	struct file *fp;
 	int i;
 
-	/* Certain daemons might not have file descriptors. */
 	fdp = td->td_proc->p_fd;
-	if (fdp == NULL)
-		return;
-
-	/*
-	 * We cannot cache fd_ofiles since operations
-	 * may block and rip them out from under us.
-	 */
+	KASSERT(fdp->fd_refcnt == 1, ("the fdtable should not be shared"));
 	FILEDESC_XLOCK(fdp);
 	for (i = 0; i <= fdp->fd_lastfile; i++) {
 		fde = &fdp->fd_ofiles[i];
@@ -2180,8 +2166,6 @@ fdcheckstd(struct thread *td)
 	int i, error, devnull;
 
 	fdp = td->td_proc->p_fd;
-	if (fdp == NULL)
-		return (0);
 	KASSERT(fdp->fd_refcnt == 1, ("the fdtable should not be shared"));
 	devnull = -1;
 	error = 0;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201406230128.s5N1SIYK097224>