Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 21 Feb 2014 22:29:09 +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: r262309 - head/sys/kern
Message-ID:  <201402212229.s1LMT9BF093587@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Fri Feb 21 22:29:09 2014
New Revision: 262309
URL: http://svnweb.freebsd.org/changeset/base/262309

Log:
  Fix a race between kern_proc_{o,}filedesc_out and fdescfree leading
  to use-after-free.
  
  fdescfree proceeds to free file pointers once fd_refcnt reaches 0, but
  kern_proc_{o,}filedesc_out only checked for hold count.
  
  MFC after:	3 days

Modified:
  head/sys/kern/kern_descrip.c

Modified: head/sys/kern/kern_descrip.c
==============================================================================
--- head/sys/kern/kern_descrip.c	Fri Feb 21 21:54:36 2014	(r262308)
+++ head/sys/kern/kern_descrip.c	Fri Feb 21 22:29:09 2014	(r262309)
@@ -3056,7 +3056,7 @@ sysctl_kern_proc_ofiledesc(SYSCTL_HANDLE
 	if (fdp->fd_jdir != NULL)
 		export_vnode_for_osysctl(fdp->fd_jdir, KF_FD_TYPE_JAIL, kif,
 				fdp, req);
-	for (i = 0; i < fdp->fd_nfiles; i++) {
+	for (i = 0; fdp->fd_refcnt > 0 && i < fdp->fd_nfiles; i++) {
 		if ((fp = fdp->fd_ofiles[i].fde_file) == NULL)
 			continue;
 		bzero(kif, sizeof(*kif));
@@ -3424,7 +3424,7 @@ kern_proc_filedesc_out(struct proc *p,  
 		export_fd_to_sb(data, KF_TYPE_VNODE, KF_FD_TYPE_JAIL,
 		    FREAD, -1, -1, NULL, efbuf);
 	}
-	for (i = 0; i < fdp->fd_nfiles; i++) {
+	for (i = 0; fdp->fd_refcnt > 0 && i < fdp->fd_nfiles; i++) {
 		if ((fp = fdp->fd_ofiles[i].fde_file) == NULL)
 			continue;
 		data = NULL;



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