svn commit: r344152 - in stable/12/sys: kern sys

Konstantin Belousov kib at FreeBSD.org
Fri Feb 15 11:13:41 UTC 2019


Author: kib
Date: Fri Feb 15 11:13:39 2019
New Revision: 344152
URL: https://svnweb.freebsd.org/changeset/base/344152

Log:
  MFC r343891:
  Fix renameat(2) for CAPABILITIES kernelsi.
  
  MFC Note: Layout of the struct nameidata is changed.  I specifically
  decided to not move the new field to the end of the new structure since
  it would mostly make the corruption silent.  __FreeBSD_version is bumped.

Modified:
  stable/12/sys/kern/vfs_lookup.c
  stable/12/sys/kern/vfs_syscalls.c
  stable/12/sys/sys/namei.h
  stable/12/sys/sys/param.h
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/kern/vfs_lookup.c
==============================================================================
--- stable/12/sys/kern/vfs_lookup.c	Fri Feb 15 10:40:41 2019	(r344151)
+++ stable/12/sys/kern/vfs_lookup.c	Fri Feb 15 11:13:39 2019	(r344152)
@@ -388,6 +388,7 @@ namei(struct nameidata *ndp)
 	dp = NULL;
 	cnp->cn_nameptr = cnp->cn_pnbuf;
 	if (cnp->cn_pnbuf[0] == '/') {
+		ndp->ni_resflags |= NIRES_ABS;
 		error = namei_handle_root(ndp, &dp);
 	} else {
 		if (ndp->ni_startdir != NULL) {
@@ -1252,6 +1253,7 @@ NDINIT_ALL(struct nameidata *ndp, u_long op, u_long fl
 	ndp->ni_dirp = namep;
 	ndp->ni_dirfd = dirfd;
 	ndp->ni_startdir = startdir;
+	ndp->ni_resflags = 0;
 	if (rightsp != NULL)
 		ndp->ni_rightsneeded = *rightsp;
 	else

Modified: stable/12/sys/kern/vfs_syscalls.c
==============================================================================
--- stable/12/sys/kern/vfs_syscalls.c	Fri Feb 15 10:40:41 2019	(r344151)
+++ stable/12/sys/kern/vfs_syscalls.c	Fri Feb 15 11:13:39 2019	(r344152)
@@ -3511,10 +3511,10 @@ again:
 			goto out;
 		}
 #ifdef CAPABILITIES
-		if (newfd != AT_FDCWD) {
+		if (newfd != AT_FDCWD && (tond.ni_resflags & NIRES_ABS) == 0) {
 			/*
 			 * If the target already exists we require CAP_UNLINKAT
-			 * from 'newfd'.
+			 * from 'newfd', when newfd was used for the lookup.
 			 */
 			error = cap_check(&tond.ni_filecaps.fc_rights,
 			    &cap_unlinkat_rights);

Modified: stable/12/sys/sys/namei.h
==============================================================================
--- stable/12/sys/sys/namei.h	Fri Feb 15 10:40:41 2019	(r344151)
+++ stable/12/sys/sys/namei.h	Fri Feb 15 11:13:39 2019	(r344152)
@@ -88,6 +88,10 @@ struct nameidata {
 	struct	vnode *ni_vp;		/* vnode of result */
 	struct	vnode *ni_dvp;		/* vnode of intermediate directory */
 	/*
+	 * Results: flags returned from namei
+	 */
+	u_int	ni_resflags;
+	/*
 	 * Shared between namei and lookup/commit routines.
 	 */
 	size_t	ni_pathlen;		/* remaining chars in path */
@@ -156,6 +160,11 @@ struct nameidata {
 #define	TRAILINGSLASH	0x10000000 /* path ended in a slash */
 #define	NOCAPCHECK	0x20000000 /* do not perform capability checks */
 #define	PARAMASK	0x3ffffe00 /* mask of parameter descriptors */
+
+/*
+ * Namei results flags
+ */
+#define	NIRES_ABS	0x00000001 /* Path was absolute */
 
 /*
  * Flags in ni_lcf, valid for the duration of the namei call.

Modified: stable/12/sys/sys/param.h
==============================================================================
--- stable/12/sys/sys/param.h	Fri Feb 15 10:40:41 2019	(r344151)
+++ stable/12/sys/sys/param.h	Fri Feb 15 11:13:39 2019	(r344152)
@@ -60,7 +60,7 @@
  *		in the range 5 to 9.
  */
 #undef __FreeBSD_version
-#define __FreeBSD_version 1200502	/* Master, propagated to newvers */
+#define __FreeBSD_version 1200503	/* Master, propagated to newvers */
 
 /*
  * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,


More information about the svn-src-all mailing list