NFS: nfs_igrab_and_active must first reference the superblock

commit 896567ee7f upstream.

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: ea7c38fef0 ("NFSv4: Ensure we reference the inode for return-on-close in delegreturn")
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Trond Myklebust 2021-01-10 15:58:08 -05:00 committed by Greg Kroah-Hartman
parent bc04f6f240
commit d00e517fa8

View file

@ -575,12 +575,14 @@ extern int nfs4_test_session_trunk(struct rpc_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)