* Dag-Erling Smorgrav <[EMAIL PROTECTED]> [020318 08:23] wrote:
> Alfred Perlstein <[EMAIL PROTECTED]> writes:
> > I think you're right, I'm pretty sure the fix is basically moving
> > the p->p_fd = NULL to after the closef will fix things [...]
> 
> There will still be a race...

Are you sure? :)

Btw, is there a way to easily reproduce this bug?

Index: kern/kern_descrip.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/kern_descrip.c,v
retrieving revision 1.128
diff -u -r1.128 kern_descrip.c
--- kern/kern_descrip.c 15 Mar 2002 08:03:46 -0000      1.128
+++ kern/kern_descrip.c 18 Mar 2002 19:04:24 -0000
@@ -1321,10 +1321,11 @@
 fdfree(td)
        struct thread *td;
 {
-       register struct filedesc *fdp = td->td_proc->p_fd;
+       register struct filedesc *fdp;
        struct file **fpp;
        register int i;
 
+       fdp = td->td_proc->p_fd;
        /* Certain daemons might not have file descriptors. */
        if (fdp == NULL)
                return;
@@ -1344,6 +1345,11 @@
                if (*fpp)
                        (void) closef(*fpp, td);
        }
+
+       PROC_LOCK(td->td_proc);
+       td->td_proc->p_fd = NULL;
+       PROC_UNLOCK(td->td_proc);
+
        if (fdp->fd_nfiles > NDFILE)
                FREE(fdp->fd_ofiles, M_FILEDESC);
        if (fdp->fd_cdir)
Index: kern/vfs_syscalls.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/vfs_syscalls.c,v
retrieving revision 1.231
diff -u -r1.231 vfs_syscalls.c
--- kern/vfs_syscalls.c 12 Mar 2002 04:00:10 -0000      1.231
+++ kern/vfs_syscalls.c 18 Mar 2002 19:05:23 -0000
@@ -451,9 +451,12 @@
                return;
        sx_slock(&allproc_lock);
        LIST_FOREACH(p, &allproc, p_list) {
+               PROC_LOCK(p);
                fdp = p->p_fd;
-               if (fdp == NULL)
+               if (fdp == NULL) {
+                       PROC_UNLOCK(p);
                        continue;
+               }
                FILEDESC_LOCK(fdp);
                if (fdp->fd_cdir == olddp) {
                        VREF(newdp);
@@ -469,6 +472,7 @@
                        vrele(olddp);
                } else
                        FILEDESC_UNLOCK(fdp);
+               PROC_UNLOCK(p);
        }
        sx_sunlock(&allproc_lock);
        if (rootvnode == olddp) {

-- 
-Alfred Perlstein [[EMAIL PROTECTED]]
'Instead of asking why a piece of software is using "1970s technology,"
 start asking why software is ignoring 30 years of accumulated wisdom.'
Tax deductible donations for FreeBSD: http://www.freebsdfoundation.org/

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message

Reply via email to