From owner-svn-src-head@freebsd.org Wed Feb 21 00:19:05 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 539CDF14B8D; Wed, 21 Feb 2018 00:19:05 +0000 (UTC) (envelope-from rpokala@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D1554792CD; Wed, 21 Feb 2018 00:19:03 +0000 (UTC) (envelope-from rpokala@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id CF47610F81; Wed, 21 Feb 2018 00:19:02 +0000 (UTC) (envelope-from rpokala@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w1L0J2CM070157; Wed, 21 Feb 2018 00:19:02 GMT (envelope-from rpokala@FreeBSD.org) Received: (from rpokala@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w1L0J2Jg070156; Wed, 21 Feb 2018 00:19:02 GMT (envelope-from rpokala@FreeBSD.org) Message-Id: <201802210019.w1L0J2Jg070156@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rpokala set sender to rpokala@FreeBSD.org using -f From: Ravi Pokala Date: Wed, 21 Feb 2018 00:19:02 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r329682 - head/usr.sbin/mountd X-SVN-Group: head X-SVN-Commit-Author: rpokala X-SVN-Commit-Paths: head/usr.sbin/mountd X-SVN-Commit-Revision: 329682 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Feb 2018 00:19:05 -0000 Author: rpokala Date: Wed Feb 21 00:19:02 2018 New Revision: 329682 URL: https://svnweb.freebsd.org/changeset/base/329682 Log: 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. Submitted by: Bruce Leverett (Panasas) Reviewed by: rmacklem MFC after: 1 week Sponsored by: Panasas Differential Revision: https://reviews.freebsd.org/D14438 Modified: head/usr.sbin/mountd/mountd.c Modified: head/usr.sbin/mountd/mountd.c ============================================================================== --- head/usr.sbin/mountd/mountd.c Wed Feb 21 00:18:57 2018 (r329681) +++ head/usr.sbin/mountd/mountd.c Wed Feb 21 00:19:02 2018 (r329682) @@ -1053,8 +1053,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, @@ -1064,10 +1062,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) || @@ -1118,7 +1129,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);