From: trondmy@kernel.org
To: Steve Dickson <SteveD@redhat.com>
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH 7/7] mountd: Check the stat() return values in match_fsid()
Date: Thu, 16 Apr 2020 18:12:52 -0400 [thread overview]
Message-ID: <20200416221252.82102-8-trondmy@kernel.org> (raw)
In-Reply-To: <20200416221252.82102-7-trondmy@kernel.org>
From: Trond Myklebust <trond.myklebust@hammerspace.com>
Propagate errors from the stat() calls in match_fsid() so that the
caller can be more careful about how they are handled.
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
---
utils/mountd/cache.c | 45 +++++++++++++++++++++++++++++---------------
1 file changed, 30 insertions(+), 15 deletions(-)
diff --git a/utils/mountd/cache.c b/utils/mountd/cache.c
index 79d3ee085a90..6cba2883026f 100644
--- a/utils/mountd/cache.c
+++ b/utils/mountd/cache.c
@@ -659,55 +659,66 @@ static int parse_fsid(int fsidtype, int fsidlen, char *fsid,
return 0;
}
-static bool match_fsid(struct parsed_fsid *parsed, nfs_export *exp, char *path)
+static int match_fsid(struct parsed_fsid *parsed, nfs_export *exp, char *path)
{
struct stat stb;
int type;
char u[16];
if (nfsd_path_stat(path, &stb) != 0)
- return false;
+ goto path_error;
if (!S_ISDIR(stb.st_mode) && !S_ISREG(stb.st_mode))
- return false;
+ goto nomatch;
switch (parsed->fsidtype) {
case FSID_DEV:
case FSID_MAJOR_MINOR:
case FSID_ENCODE_DEV:
if (stb.st_ino != parsed->inode)
- return false;
+ goto nomatch;
if (parsed->major != major(stb.st_dev) ||
parsed->minor != minor(stb.st_dev))
- return false;
- return true;
+ goto nomatch;
+ goto match;
case FSID_NUM:
if (((exp->m_export.e_flags & NFSEXP_FSID) == 0 ||
exp->m_export.e_fsid != parsed->fsidnum))
- return false;
- return true;
+ goto nomatch;
+ goto match;
case FSID_UUID4_INUM:
case FSID_UUID16_INUM:
if (stb.st_ino != parsed->inode)
- return false;
+ goto nomatch;
goto check_uuid;
case FSID_UUID8:
case FSID_UUID16:
- if (!is_mountpoint(path))
- return false;
+ errno = 0;
+ if (!is_mountpoint(path)) {
+ if (!errno)
+ goto nomatch;
+ goto path_error;
+ }
check_uuid:
if (exp->m_export.e_uuid) {
get_uuid(exp->m_export.e_uuid, parsed->uuidlen, u);
if (memcmp(u, parsed->fhuuid, parsed->uuidlen) == 0)
- return true;
+ goto match;
}
else
for (type = 0;
uuid_by_path(path, type, parsed->uuidlen, u);
type++)
if (memcmp(u, parsed->fhuuid, parsed->uuidlen) == 0)
- return true;
+ goto match;
}
- return false;
+nomatch:
+ return 0;
+match:
+ return 1;
+path_error:
+ if (path_lookup_error(errno))
+ goto nomatch;
+ return -1;
}
static struct addrinfo *lookup_client_addr(char *dom)
@@ -815,8 +826,12 @@ static void nfsd_fh(int f)
exp->m_export.e_path))
dev_missing ++;
- if (!match_fsid(&parsed, exp, path))
+ switch(match_fsid(&parsed, exp, path)) {
+ case 0:
continue;
+ case -1:
+ goto out;
+ }
if (is_ipaddr_client(dom)
&& !ipaddr_client_matches(exp, ai))
continue;
--
2.25.2
next prev parent reply other threads:[~2020-04-16 22:15 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-16 22:12 [PATCH 0/7] nfs-utils fixes trondmy
2020-04-16 22:12 ` [PATCH 1/7] mountd: Add a helper nfsd_path_statfs64() for uuid_by_path() trondmy
2020-04-16 22:12 ` [PATCH 2/7] nfsd: Support running nfsd_name_to_handle_at() in the root jail trondmy
2020-04-16 22:12 ` [PATCH 3/7] mountd: Fix up path checking helper same_path() trondmy
2020-04-16 22:12 ` [PATCH 4/7] Fix autoconf probe for 'struct nfs_filehandle' trondmy
2020-04-16 22:12 ` [PATCH 5/7] mountd: Ensure dump_to_cache() sets errno appropriately trondmy
2020-04-16 22:12 ` [PATCH 6/7] mountd: Ignore transient and non-fatal filesystem errors in nfsd_fh() trondmy
2020-04-16 22:12 ` trondmy [this message]
2020-04-27 18:38 ` J. Bruce Fields
2020-04-27 18:39 ` J. Bruce Fields
2020-05-08 14:13 ` [PATCH 0/7] nfs-utils fixes Steve Dickson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200416221252.82102-8-trondmy@kernel.org \
--to=trondmy@kernel.org \
--cc=SteveD@redhat.com \
--cc=linux-nfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.