]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
nfs4_setup_readdir(): insufficient locking for ->d_parent->d_inode dereferencing
authorAl Viro <viro@zeniv.linux.org.uk>
Tue, 16 Sep 2025 16:22:45 +0000 (17:22 +0100)
committerAnna Schumaker <anna.schumaker@oracle.com>
Tue, 23 Sep 2025 17:29:51 +0000 (13:29 -0400)
Theoretically it's an oopsable race, but I don't believe one can manage
to hit it on real hardware; might become doable on a KVM, but it still
won't be easy to attack.

Anyway, it's easy to deal with - since xdr_encode_hyper() is just a call of
put_unaligned_be64(), we can put that under ->d_lock and be done with that.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com>
fs/nfs/nfs4proc.c

index a5085820ec0a746a6bd2f51e0d0bb880ba0c8aa5..f58098417142fec1400a57af8c2f93d0d1fecea3 100644 (file)
@@ -391,7 +391,9 @@ static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dent
        *p++ = htonl(attrs);                           /* bitmap */
        *p++ = htonl(12);             /* attribute buffer length */
        *p++ = htonl(NF4DIR);
+       spin_lock(&dentry->d_lock);
        p = xdr_encode_hyper(p, NFS_FILEID(d_inode(dentry->d_parent)));
+       spin_unlock(&dentry->d_lock);
 
        readdir->pgbase = (char *)p - (char *)start;
        readdir->count -= readdir->pgbase;