2019-10-24 10:56:44

by Trond Myklebust

[permalink] [raw]
Subject: [PATCH 01/14] NFSv4: Don't allow a cached open with a revoked delegation

If the delegation is marked as being revoked, we must not use it
for cached opens.

Fixes: 869f9dfa4d6d ("NFSv4: Fix races between nfs_remove_bad_delegation() and delegation return")
Signed-off-by: Trond Myklebust <[email protected]>
---
fs/nfs/delegation.c | 3 +--
fs/nfs/delegation.h | 1 +
fs/nfs/nfs4proc.c | 6 +-----
3 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
index 071b90a45933..5f3eea926af5 100644
--- a/fs/nfs/delegation.c
+++ b/fs/nfs/delegation.c
@@ -42,8 +42,7 @@ void nfs_mark_delegation_referenced(struct nfs_delegation *delegation)
set_bit(NFS_DELEGATION_REFERENCED, &delegation->flags);
}

-static bool
-nfs4_is_valid_delegation(const struct nfs_delegation *delegation,
+bool nfs4_is_valid_delegation(const struct nfs_delegation *delegation,
fmode_t flags)
{
if (delegation != NULL && (delegation->type & flags) == flags &&
diff --git a/fs/nfs/delegation.h b/fs/nfs/delegation.h
index 9eb87ae4c982..2b35a99929a0 100644
--- a/fs/nfs/delegation.h
+++ b/fs/nfs/delegation.h
@@ -69,6 +69,7 @@ bool nfs4_copy_delegation_stateid(struct inode *inode, fmode_t flags, nfs4_state
bool nfs4_refresh_delegation_stateid(nfs4_stateid *dst, struct inode *inode);

void nfs_mark_delegation_referenced(struct nfs_delegation *delegation);
+bool nfs4_is_valid_delegation(const struct nfs_delegation *delegation, fmode_t flags);
int nfs4_have_delegation(struct inode *inode, fmode_t flags);
int nfs4_check_delegation(struct inode *inode, fmode_t flags);
bool nfs4_delegation_flush_on_close(const struct inode *inode);
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index ab8ca20fd579..294ea8c1a163 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -1436,11 +1436,7 @@ static int can_open_cached(struct nfs4_state *state, fmode_t mode,
static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode,
enum open_claim_type4 claim)
{
- if (delegation == NULL)
- return 0;
- if ((delegation->type & fmode) != fmode)
- return 0;
- if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags))
+ if (!nfs4_is_valid_delegation(delegation, fmode))
return 0;
switch (claim) {
case NFS4_OPEN_CLAIM_NULL:
--
2.21.0


2019-10-24 10:56:44

by Trond Myklebust

[permalink] [raw]
Subject: [PATCH 02/14] NFSv4: Fix delegation handling in update_open_stateid()

If the delegation is marked as being revoked, then don't use it in
the open state structure.

Signed-off-by: Trond Myklebust <[email protected]>
---
fs/nfs/nfs4proc.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 294ea8c1a163..c407e2eed3d5 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -1740,14 +1740,12 @@ static int update_open_stateid(struct nfs4_state *state,
goto no_delegation;

spin_lock(&deleg_cur->lock);
- if (rcu_dereference(nfsi->delegation) != deleg_cur ||
- test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) ||
- (deleg_cur->type & fmode) != fmode)
+ if (!nfs4_is_valid_delegation(deleg_cur, fmode))
goto no_delegation_unlock;

if (delegation == NULL)
delegation = &deleg_cur->stateid;
- else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation))
+ else if (!nfs4_stateid_match_other(&deleg_cur->stateid, delegation))
goto no_delegation_unlock;

nfs_mark_delegation_referenced(deleg_cur);
--
2.21.0