Skip to content

Commit 10a973f

Browse files
author
Al Viro
committed
nfs: make nfs_set_verifier() safe for use in RCU pathwalk
nfs_set_verifier() relies upon dentry being pinned; if that's the case, grabbing ->d_lock stabilizes ->d_parent and guarantees that ->d_parent points to a positive dentry. For something we'd run into in RCU mode that is *not* true - dentry might've been through dentry_kill() just as we grabbed ->d_lock, with its parent going through the same just as we get to into nfs_set_verifier_locked(). It might get to detaching inode (and zeroing ->d_inode) before nfs_set_verifier_locked() gets to fetching that; we get an oops as the result. That can happen in nfs{,4} ->d_revalidate(); the call chain in question is nfs_set_verifier_locked() <- nfs_set_verifier() <- nfs_lookup_revalidate_delegated() <- nfs{,4}_do_lookup_revalidate(). We have checked that the parent had been positive, but that's done before we get to nfs_set_verifier() and it's possible for memory pressure to pick our dentry as eviction candidate by that time. If that happens, back-to-back attempts to kill dentry and its parent are quite normal. Sure, in case of eviction we'll fail the ->d_seq check in the caller, but we need to survive until we return there... Acked-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 275655d commit 10a973f

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

fs/nfs/dir.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,9 +1431,9 @@ static bool nfs_verifier_is_delegated(struct dentry *dentry)
14311431
static void nfs_set_verifier_locked(struct dentry *dentry, unsigned long verf)
14321432
{
14331433
struct inode *inode = d_inode(dentry);
1434-
struct inode *dir = d_inode(dentry->d_parent);
1434+
struct inode *dir = d_inode_rcu(dentry->d_parent);
14351435

1436-
if (!nfs_verify_change_attribute(dir, verf))
1436+
if (!dir || !nfs_verify_change_attribute(dir, verf))
14371437
return;
14381438
if (inode && NFS_PROTO(inode)->have_delegation(inode, FMODE_READ))
14391439
nfs_set_verifier_delegated(&verf);

0 commit comments

Comments
 (0)