Author: kib
Date: Thu Jan 29 10:33:32 2009
New Revision: 187882
URL: http://svn.freebsd.org/changeset/base/187882

Log:
  MFC r186601:
  Clear the pointers to the file in the struct filedesc before file is closed
  in fdfree. Otherwise, sysctl_kern_proc_filedesc may dereference stale
  struct file * values.

Modified:
  stable/7/sys/   (props changed)
  stable/7/sys/contrib/pf/   (props changed)
  stable/7/sys/dev/cxgb/   (props changed)
  stable/7/sys/kern/kern_descrip.c

Modified: stable/7/sys/kern/kern_descrip.c
==============================================================================
--- stable/7/sys/kern/kern_descrip.c    Thu Jan 29 09:32:56 2009        
(r187881)
+++ stable/7/sys/kern/kern_descrip.c    Thu Jan 29 10:33:32 2009        
(r187882)
@@ -1733,14 +1733,16 @@ fdfree(struct thread *td)
        FILEDESC_XUNLOCK(fdp);
        if (i > 0)
                return;
-       /*
-        * We are the last reference to the structure, so we can
-        * safely assume it will not change out from under us.
-        */
+
        fpp = fdp->fd_ofiles;
        for (i = fdp->fd_lastfile; i-- >= 0; fpp++) {
-               if (*fpp)
-                       (void) closef(*fpp, td);
+               if (*fpp) {
+                       FILEDESC_XLOCK(fdp);
+                       fp = *fpp;
+                       *fpp = NULL;
+                       FILEDESC_XUNLOCK(fdp);
+                       (void) closef(fp, td);
+               }
        }
        FILEDESC_XLOCK(fdp);
 
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to