svn commit: r292621 - head/sys/fs/devfs

Konstantin Belousov kib at FreeBSD.org
Tue Dec 22 20:22:19 UTC 2015


Author: kib
Date: Tue Dec 22 20:22:17 2015
New Revision: 292621
URL: https://svnweb.freebsd.org/changeset/base/292621

Log:
  Keep devfs mount locked for the whole duration of the devfs_setattr(),
  and ensure that our dirent is instantiated.
  
  Reported and tested by:	bde
  Sponsored by:	The FreeBSD Foundation
  MFC after:	1 week

Modified:
  head/sys/fs/devfs/devfs_vnops.c

Modified: head/sys/fs/devfs/devfs_vnops.c
==============================================================================
--- head/sys/fs/devfs/devfs_vnops.c	Tue Dec 22 20:12:52 2015	(r292620)
+++ head/sys/fs/devfs/devfs_vnops.c	Tue Dec 22 20:22:17 2015	(r292621)
@@ -1560,11 +1560,15 @@ devfs_setattr(struct vop_setattr_args *a
 		return (EINVAL);
 	}
 
+	error = devfs_populate_vp(vp);
+	if (error != 0)
+		return (error);
+
 	de = vp->v_data;
 	if (vp->v_type == VDIR)
 		de = de->de_dir;
 
-	error = c = 0;
+	c = 0;
 	if (vap->va_uid == (uid_t)VNOVAL)
 		uid = de->de_uid;
 	else
@@ -1577,8 +1581,8 @@ devfs_setattr(struct vop_setattr_args *a
 		if ((ap->a_cred->cr_uid != de->de_uid) || uid != de->de_uid ||
 		    (gid != de->de_gid && !groupmember(gid, ap->a_cred))) {
 			error = priv_check(td, PRIV_VFS_CHOWN);
-			if (error)
-				return (error);
+			if (error != 0)
+				goto ret;
 		}
 		de->de_uid = uid;
 		de->de_gid = gid;
@@ -1588,8 +1592,8 @@ devfs_setattr(struct vop_setattr_args *a
 	if (vap->va_mode != (mode_t)VNOVAL) {
 		if (ap->a_cred->cr_uid != de->de_uid) {
 			error = priv_check(td, PRIV_VFS_ADMIN);
-			if (error)
-				return (error);
+			if (error != 0)
+				goto ret;
 		}
 		de->de_mode = vap->va_mode;
 		c = 1;
@@ -1598,7 +1602,7 @@ devfs_setattr(struct vop_setattr_args *a
 	if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
 		error = vn_utimes_perm(vp, vap, ap->a_cred, td);
 		if (error != 0)
-			return (error);
+			goto ret;
 		if (vap->va_atime.tv_sec != VNOVAL) {
 			if (vp->v_type == VCHR)
 				vp->v_rdev->si_atime = vap->va_atime;
@@ -1620,7 +1624,10 @@ devfs_setattr(struct vop_setattr_args *a
 		else
 			vfs_timestamp(&de->de_mtime);
 	}
-	return (0);
+
+ret:
+	sx_xunlock(&VFSTODEVFS(vp->v_mount)->dm_lock);
+	return (error);
 }
 
 #ifdef MAC


More information about the svn-src-head mailing list