svn commit: r360900 - head/sys/kern

Ryan Moeller freqlabs at FreeBSD.org
Mon May 11 15:38:44 UTC 2020


Author: freqlabs
Date: Mon May 11 15:38:44 2020
New Revision: 360900
URL: https://svnweb.freebsd.org/changeset/base/360900

Log:
  vfs_exports: Tighten bounds and assert consistency of numsecflavors
  
  We know the value must be greater than 0 and less than MAXSECFLAVORS.
  
  Reject values outside this range in the initial check in vfs_export and add KASSERTs
  in the later consumers.
  
  Also check that we are called with one of either MNT_DELEXPORT or MNT_EXPORTED set.
  
  Reviewed by:	rmacklem
  Approved by:	mav (mentor)
  MFC after:	1 week
  Sponsored by:	iXsystems, Inc.
  Differential Revision:	https://reviews.freebsd.org/D24753

Modified:
  head/sys/kern/vfs_export.c

Modified: head/sys/kern/vfs_export.c
==============================================================================
--- head/sys/kern/vfs_export.c	Mon May 11 15:32:32 2020	(r360899)
+++ head/sys/kern/vfs_export.c	Mon May 11 15:38:44 2020	(r360900)
@@ -112,6 +112,11 @@ vfs_hang_addrlist(struct mount *mp, struct netexport *
 #endif
 	int error;
 
+	KASSERT(argp->ex_numsecflavors > 0,
+	    ("%s: numsecflavors <= 0", __func__));
+	KASSERT(argp->ex_numsecflavors < MAXSECFLAVORS,
+	    ("%s: numsecflavors >= MAXSECFLAVORS", __func__));
+
 	/*
 	 * XXX: This routine converts from a `struct xucred'
 	 * (argp->ex_anon) to a `struct ucred' (np->netc_anon).  This
@@ -300,10 +305,14 @@ vfs_export(struct mount *mp, struct export_args *argp)
 	struct netexport *nep;
 	int error;
 
-	if (argp->ex_numsecflavors < 0
-	    || argp->ex_numsecflavors >= MAXSECFLAVORS)
+	if ((argp->ex_flags & (MNT_DELEXPORT | MNT_EXPORTED)) == 0)
 		return (EINVAL);
 
+	if ((argp->ex_flags & MNT_EXPORTED) != 0 &&
+	    (argp->ex_numsecflavors <= 0
+	    || argp->ex_numsecflavors >= MAXSECFLAVORS))
+		return (EINVAL);
+
 	error = 0;
 	lockmgr(&mp->mnt_explock, LK_EXCLUSIVE, NULL);
 	nep = mp->mnt_export;
@@ -518,8 +527,13 @@ vfs_stdcheckexp(struct mount *mp, struct sockaddr *nam
 	*extflagsp = np->netc_exflags;
 	if ((*credanonp = np->netc_anon) != NULL)
 		crhold(*credanonp);
-	if (numsecflavors)
+	if (numsecflavors) {
 		*numsecflavors = np->netc_numsecflavors;
+		KASSERT(*numsecflavors > 0,
+		    ("%s: numsecflavors <= 0", __func__));
+		KASSERT(*numsecflavors < MAXSECFLAVORS,
+		    ("%s: numsecflavors >= MAXSECFLAVORS", __func__));
+	}
 	if (secflavors)
 		*secflavors = np->netc_secflavors;
 	lockmgr(&mp->mnt_explock, LK_RELEASE, NULL);


More information about the svn-src-all mailing list