Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 18 May 2020 00:32:43 +0000 (UTC)
From:      Ryan Moeller <freqlabs@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r361147 - in stable: 11/sys/kern 12/sys/kern
Message-ID:  <202005180032.04I0WhFs034018@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: freqlabs
Date: Mon May 18 00:32:42 2020
New Revision: 361147
URL: https://svnweb.freebsd.org/changeset/base/361147

Log:
  MFC r360900:
  
  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)
  Sponsored by:   iXsystems, Inc.
  Differential Revision:  https://reviews.freebsd.org/D24753

Modified:
  stable/12/sys/kern/vfs_export.c
Directory Properties:
  stable/12/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/11/sys/kern/vfs_export.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/12/sys/kern/vfs_export.c
==============================================================================
--- stable/12/sys/kern/vfs_export.c	Mon May 18 00:07:45 2020	(r361146)
+++ stable/12/sys/kern/vfs_export.c	Mon May 18 00:32:42 2020	(r361147)
@@ -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);



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