Skip to content

Commit

Permalink
NFS: change nfs_access_get_cached to only report the mask
Browse files Browse the repository at this point in the history
[ Upstream commit b5e7b59 ]

Currently the nfs_access_get_cached family of functions report a
'struct nfs_access_entry' as the result, with both .mask and .cred set.
However the .cred is never used.  This is probably good and there is no
guarantee that it won't be freed before use.

Change to only report the 'mask' - as this is all that is used or needed.

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
neilbrown authored and gregkh committed Feb 16, 2022
1 parent 78c28fd commit 38ae938
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
20 changes: 9 additions & 11 deletions fs/nfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -2697,7 +2697,7 @@ static struct nfs_access_entry *nfs_access_search_rbtree(struct inode *inode, co
return NULL;
}

static int nfs_access_get_cached_locked(struct inode *inode, const struct cred *cred, struct nfs_access_entry *res, bool may_block)
static int nfs_access_get_cached_locked(struct inode *inode, const struct cred *cred, u32 *mask, bool may_block)
{
struct nfs_inode *nfsi = NFS_I(inode);
struct nfs_access_entry *cache;
Expand Down Expand Up @@ -2727,8 +2727,7 @@ static int nfs_access_get_cached_locked(struct inode *inode, const struct cred *
spin_lock(&inode->i_lock);
retry = false;
}
res->cred = cache->cred;
res->mask = cache->mask;
*mask = cache->mask;
list_move_tail(&cache->lru, &nfsi->access_cache_entry_lru);
err = 0;
out:
Expand All @@ -2740,7 +2739,7 @@ static int nfs_access_get_cached_locked(struct inode *inode, const struct cred *
return -ENOENT;
}

static int nfs_access_get_cached_rcu(struct inode *inode, const struct cred *cred, struct nfs_access_entry *res)
static int nfs_access_get_cached_rcu(struct inode *inode, const struct cred *cred, u32 *mask)
{
/* Only check the most recently returned cache entry,
* but do it without locking.
Expand All @@ -2762,22 +2761,21 @@ static int nfs_access_get_cached_rcu(struct inode *inode, const struct cred *cre
goto out;
if (nfs_check_cache_invalid(inode, NFS_INO_INVALID_ACCESS))
goto out;
res->cred = cache->cred;
res->mask = cache->mask;
*mask = cache->mask;
err = 0;
out:
rcu_read_unlock();
return err;
}

int nfs_access_get_cached(struct inode *inode, const struct cred *cred, struct
nfs_access_entry *res, bool may_block)
int nfs_access_get_cached(struct inode *inode, const struct cred *cred,
u32 *mask, bool may_block)
{
int status;

status = nfs_access_get_cached_rcu(inode, cred, res);
status = nfs_access_get_cached_rcu(inode, cred, mask);
if (status != 0)
status = nfs_access_get_cached_locked(inode, cred, res,
status = nfs_access_get_cached_locked(inode, cred, mask,
may_block);

return status;
Expand Down Expand Up @@ -2898,7 +2896,7 @@ static int nfs_do_access(struct inode *inode, const struct cred *cred, int mask)

trace_nfs_access_enter(inode);

status = nfs_access_get_cached(inode, cred, &cache, may_block);
status = nfs_access_get_cached(inode, cred, &cache.mask, may_block);
if (status == 0)
goto out_cached;

Expand Down
18 changes: 9 additions & 9 deletions fs/nfs/nfs4proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -7677,7 +7677,7 @@ static int nfs4_xattr_set_nfs4_user(const struct xattr_handler *handler,
const char *key, const void *buf,
size_t buflen, int flags)
{
struct nfs_access_entry cache;
u32 mask;
int ret;

if (!nfs_server_capable(inode, NFS_CAP_XATTR))
Expand All @@ -7692,8 +7692,8 @@ static int nfs4_xattr_set_nfs4_user(const struct xattr_handler *handler,
* do a cached access check for the XA* flags to possibly avoid
* doing an RPC and getting EACCES back.
*/
if (!nfs_access_get_cached(inode, current_cred(), &cache, true)) {
if (!(cache.mask & NFS_ACCESS_XAWRITE))
if (!nfs_access_get_cached(inode, current_cred(), &mask, true)) {
if (!(mask & NFS_ACCESS_XAWRITE))
return -EACCES;
}

Expand All @@ -7714,14 +7714,14 @@ static int nfs4_xattr_get_nfs4_user(const struct xattr_handler *handler,
struct dentry *unused, struct inode *inode,
const char *key, void *buf, size_t buflen)
{
struct nfs_access_entry cache;
u32 mask;
ssize_t ret;

if (!nfs_server_capable(inode, NFS_CAP_XATTR))
return -EOPNOTSUPP;

if (!nfs_access_get_cached(inode, current_cred(), &cache, true)) {
if (!(cache.mask & NFS_ACCESS_XAREAD))
if (!nfs_access_get_cached(inode, current_cred(), &mask, true)) {
if (!(mask & NFS_ACCESS_XAREAD))
return -EACCES;
}

Expand All @@ -7746,13 +7746,13 @@ nfs4_listxattr_nfs4_user(struct inode *inode, char *list, size_t list_len)
ssize_t ret, size;
char *buf;
size_t buflen;
struct nfs_access_entry cache;
u32 mask;

if (!nfs_server_capable(inode, NFS_CAP_XATTR))
return 0;

if (!nfs_access_get_cached(inode, current_cred(), &cache, true)) {
if (!(cache.mask & NFS_ACCESS_XALIST))
if (!nfs_access_get_cached(inode, current_cred(), &mask, true)) {
if (!(mask & NFS_ACCESS_XALIST))
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions include/linux/nfs_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,8 @@ extern int nfs_instantiate(struct dentry *dentry, struct nfs_fh *fh,
struct nfs_fattr *fattr, struct nfs4_label *label);
extern int nfs_may_open(struct inode *inode, const struct cred *cred, int openflags);
extern void nfs_access_zap_cache(struct inode *inode);
extern int nfs_access_get_cached(struct inode *inode, const struct cred *cred, struct nfs_access_entry *res,
bool may_block);
extern int nfs_access_get_cached(struct inode *inode, const struct cred *cred,
u32 *mask, bool may_block);

/*
* linux/fs/nfs/symlink.c
Expand Down

0 comments on commit 38ae938

Please sign in to comment.