diff mbox series

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

Message ID 20191023235600.10880-2-trond.myklebust@hammerspace.com (mailing list archive)
State New, archived
Headers show
Series Delegation bugfixes | expand

Commit Message

Trond Myklebust Oct. 23, 2019, 11:55 p.m. UTC
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 <trond.myklebust@hammerspace.com>
---
 fs/nfs/delegation.c | 3 +--
 fs/nfs/delegation.h | 1 +
 fs/nfs/nfs4proc.c   | 6 +-----
 3 files changed, 3 insertions(+), 7 deletions(-)
diff mbox series

Patch

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: