]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
NFS: nfs_igrab_and_active must first reference the superblock
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Sun, 10 Jan 2021 20:58:08 +0000 (15:58 -0500)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Sun, 10 Jan 2021 21:29:28 +0000 (16:29 -0500)
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")
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
fs/nfs/internal.h

index 6bdee7ab3a6c27967f40be9f11fb28352238c468..62d3189745cdc7461e49109156c170ca0f2c988b 100644 (file)
@@ -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)