Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 28 Feb 2018 00:29:52 +0000 (UTC)
From:      Ravi Pokala <rpokala@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r330092 - stable/11/usr.sbin/mountd
Message-ID:  <201802280029.w1S0TqCu022453@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rpokala
Date: Wed Feb 28 00:29:52 2018
New Revision: 330092
URL: https://svnweb.freebsd.org/changeset/base/330092

Log:
  MFC r329682:
  
  mountd: Return proper errno values in a few error paths
  
  When attempting to mount a non-directory which exists, return ENOTDIR
  instead of ENOENT. If stat() or statfs() failed, don't pass part of the
  invalid (struct statfs) to ex_search(). In that same case, preserve the
  value of "bad" rather than overwriting with EACCES.

Modified:
  stable/11/usr.sbin/mountd/mountd.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.sbin/mountd/mountd.c
==============================================================================
--- stable/11/usr.sbin/mountd/mountd.c	Wed Feb 28 00:17:08 2018	(r330091)
+++ stable/11/usr.sbin/mountd/mountd.c	Wed Feb 28 00:29:52 2018	(r330092)
@@ -1051,8 +1051,6 @@ mntsrv(struct svc_req *rqstp, SVCXPRT *transp)
 		 */
 		if (realpath(rpcpath, dirpath) == NULL ||
 		    stat(dirpath, &stb) < 0 ||
-		    (!S_ISDIR(stb.st_mode) &&
-		    (dir_only || !S_ISREG(stb.st_mode))) ||
 		    statfs(dirpath, &fsb) < 0) {
 			chdir("/");	/* Just in case realpath doesn't */
 			syslog(LOG_NOTICE,
@@ -1062,10 +1060,23 @@ mntsrv(struct svc_req *rqstp, SVCXPRT *transp)
 				warnx("stat failed on %s", dirpath);
 			bad = ENOENT;	/* We will send error reply later */
 		}
+		if (!bad &&
+		    !S_ISDIR(stb.st_mode) &&
+		    (dir_only || !S_ISREG(stb.st_mode))) {
+			syslog(LOG_NOTICE,
+			    "mount request from %s for non-directory path %s",
+			    numerichost, dirpath);
+			if (debug)
+				warnx("mounting non-directory %s", dirpath);
+			bad = ENOTDIR;	/* We will send error reply later */
+		}
 
 		/* Check in the exports list */
 		sigprocmask(SIG_BLOCK, &sighup_mask, NULL);
-		ep = ex_search(&fsb.f_fsid);
+		if (bad)
+			ep = NULL;
+		else
+			ep = ex_search(&fsb.f_fsid);
 		hostset = defset = 0;
 		if (ep && (chk_host(ep->ex_defdir, saddr, &defset, &hostset,
 		    &numsecflavors, &secflavorsp) ||
@@ -1116,7 +1127,8 @@ mntsrv(struct svc_req *rqstp, SVCXPRT *transp)
 				    "mount request succeeded from %s for %s",
 				    numerichost, dirpath);
 		} else {
-			bad = EACCES;
+			if (!bad)
+				bad = EACCES;
 			syslog(LOG_NOTICE,
 			    "mount request denied from %s for %s",
 			    numerichost, dirpath);



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