summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
authormjg <mjg@FreeBSD.org>2014-07-06 22:58:53 +0000
committermjg <mjg@FreeBSD.org>2014-07-06 22:58:53 +0000
commit134eeca7553ded4c64041465105cebf1c444c9ca (patch)
tree838db6b94fe7c8ad442a8406f6c522f0bab4be9f /sys/kern
parentc9bb8da01167a7b5ceaa16259e6b6bab943b7ea9 (diff)
downloadFreeBSD-src-134eeca7553ded4c64041465105cebf1c444c9ca.zip
FreeBSD-src-134eeca7553ded4c64041465105cebf1c444c9ca.tar.gz
MFC r267760:
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
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_descrip.c20
1 files changed, 2 insertions, 18 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index 83873af..4219b07 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -2114,15 +2114,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)
@@ -2174,15 +2167,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];
@@ -2213,8 +2199,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;
OpenPOWER on IntegriCloud