Skip to contentSkip to conversation

NFS: nfs_delegation_find_inode_server must first reference the superblock

PATCH New [email protected] 1 participant 2 messages Jan 11, 2021

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 1/2 NFS: nfs_delegation_find_inode_server must first reference the superblock

From: Trond Myklebust <[email protected]>

Before referencing the inode, we must ensure that the superblock can be referenced. Otherwise, we can end up with iput() calling superblock operations that are no longer valid or accessible.

Fixes e39d8a186ed0 ("NFSv4: Fix an Oops during delegation callbacks")
---
 fs/nfs/delegation.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
fs/nfs/delegation.c +7 -5
index 816e1427f17e..04bf8066980c 100644
@@ -1011,22 +1011,24 @@ nfs_delegation_find_inode_server(struct nfs_server *server,
 				 const struct nfs_fh *fhandle)
 {
 	struct nfs_delegation *delegation;
-	struct inode *freeme, *res = NULL;
+	struct super_block *freeme = NULL;
+	struct inode *res = NULL;
 
 	list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
 		spin_lock(&delegation->lock);
 		if (delegation->inode != NULL &&
 		    !test_bit(NFS_DELEGATION_REVOKED, &delegation->flags) &&
 		    nfs_compare_fh(fhandle, &NFS_I(delegation->inode)->fh) == 0) {
-			freeme = igrab(delegation->inode);
-			if (freeme && nfs_sb_active(freeme->i_sb))
-				res = freeme;
+			if (nfs_sb_active(server->super)) {
+				freeme = server->super;
+				res = igrab(delegation->inode);
+			}
 			spin_unlock(&delegation->lock);
 			if (res != NULL)
 				return res;
 			if (freeme) {
 				rcu_read_unlock();
-				iput(freeme);
+				nfs_sb_deactive(freeme);
 				rcu_read_lock();
 			}
 			return ERR_PTR(-EAGAIN);
Signature · 1 line
2.29.2
author maintainer
#1 lore raw

PATCH 2/2 NFS: nfs_igrab_and_active must first reference the superblock

From: Trond Myklebust <[email protected]>

Before referencing the inode, we must ensure that the superblock can be referenced. Otherwise, we can end up with iput() calling superblock operations that are no longer valid or accessible.

Fixes ea7c38fef0b7 ("NFSv4: Ensure we reference the inode for return-on-close in delegreturn")
---
 fs/nfs/internal.h | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
fs/nfs/internal.h +7 -5
index 6bdee7ab3a6c..62d3189745cd 100644
@@ -599,12 +599,14 @@ extern void nfs4_test_session_trunk(struct rpc_clnt *clnt,
 
 static inline struct inode *nfs_igrab_and_active(struct inode *inode)
 {
-	inode = igrab(inode);
-	if (inode != NULL && !nfs_sb_active(inode->i_sb)) {
-		iput(inode);
-		inode = NULL;
+	struct super_block *sb = inode->i_sb;
+
+	if (sb && nfs_sb_active(sb)) {
+		if (igrab(inode))
+			return inode;
+		nfs_sb_deactive(sb);
 	}
-	return inode;
+	return NULL;
 }
 
 static inline void nfs_iput_and_deactive(struct inode *inode)
Signature · 1 line
2.29.2