NFS: Fix use-after-free in nfs4_init_client()
Subsystems (2)
PATCH v2 1/1 NFS: Fix use-after-free in nfs4_init_client()
From: Anna Schumaker <[email protected]>
KASAN reports a use-after-free when attempting to mount two different exports through two different NICs that belong to the same server.
Olga was able to hit this with kernels starting somewhere between 5.7 and 5.10, but I traced the patch that introduced the clear_bit() call to 4.13. So something must have changed in the refcounting of the clp pointer to make this call to nfs_put_client() the very last one.
---
v2: No changes except adding the fixes tag that I initially forgot
--- fs/nfs/nfs4client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/nfs4client.c +1 -1
@@ -435,8 +435,8 @@ struct nfs_client *nfs4_init_client(struct nfs_client *clp,*/ nfs_mark_client_ready (clp, -EPERM ); } -nfs_put_client (clp);clear_bit (NFS_CS_TSM_POSSIBLE , &clp->cl_flags); +nfs_put_client (clp);return old; error:
Signature · 1 line
2.29.2
Quoted 26 lines · On Wed, 2021-06-02 at 14:31 -0400, [email protected] wrote:
From: Anna Schumaker <[email protected]>
KASAN reports a use-after-free when attempting to mount two different exports through two different NICs that belong to the same server.
Olga was able to hit this with kernels starting somewhere between 5.7 and 5.10, but I traced the patch that introduced the
clear_bit()call to
4.13. So something must have changed in the refcounting of the clp pointer to make this call tonfs_put_client()the very last one.Fixes 8dcbec6d20 ("NFSv41: Handle EXCHID4_FLAG_CONFIRMED_R duringNFSv4.1 migration")
Cc [email protected] # 4.13+Signed-off-by Anna Schumaker <[email protected]>---
v2: No changes except adding the fixes tag that I initially forgot
---
fs/nfs/nfs4client.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)fs/nfs/nfs4client.c +0
-0
fs/nfs/nfs4client.c struct nfs_client *nfs4_init_client(struct · line 440
Quoted 7 lines
fs/nfs/nfs4client.c +1
-1@@ -435,8 +435,8 @@ struct nfs_client *nfs4_init_client(structnfs_client *clp, */ nfs_mark_client_ready(clp, -EPERM); } - nfs_put_client(clp); clear_bit(NFS_CS_TSM_POSSIBLE, &clp->cl_flags); + nfs_put_client(clp);
OK. I'm reading this, and it is not making sense to me. Why are we changing a flag on an object that is about to be destroyed by the nfs_put_client() anyway? Let's go back to the author of commit 8dcbec6d20 and ask him.
Chuck, is it possible that you were actually intending to clear NFS_CS_TSM_POSSIBLE on &old->cl_flags (i.e. on the object that is actually returned by the call to nfs4_init_client())?
Quoted 3 lines
fs/nfs/nfs4client.c +0
-0return old;
error:
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Quoted 44 lines · Trond Myklebust
Quoted 26 lines · On Wed, 2021-06-02 at 14:31 -0400, [email protected] wrote:
From: Anna Schumaker <[email protected]>
KASAN reports a use-after-free when attempting to mount two different exports through two different NICs that belong to the same server.
Olga was able to hit this with kernels starting somewhere between 5.7 and 5.10, but I traced the patch that introduced the
clear_bit()call to
4.13. So something must have changed in the refcounting of the clp pointer to make this call tonfs_put_client()the very last one.Fixes 8dcbec6d20 ("NFSv41: Handle EXCHID4_FLAG_CONFIRMED_R duringNFSv4.1 migration")
Cc [email protected] # 4.13+Signed-off-by Anna Schumaker <[email protected]>---
v2: No changes except adding the fixes tag that I initially forgot--- fs/nfs/nfs4client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/nfs/nfs4client.c +0
-0fs/nfs/nfs4client.c struct nfs_client *nfs4_init_client(struct · line 440
Quoted 7 lines
fs/nfs/nfs4client.c +1
-1@@ -435,8 +435,8 @@ struct nfs_client *nfs4_init_client(structnfs_client *clp, */ nfs_mark_client_ready (clp, -EPERM ); } -nfs_put_client (clp);clear_bit (NFS_CS_TSM_POSSIBLE , &clp->cl_flags); +nfs_put_client (clp);OK. I'm reading this, and it is not making sense to me. Why are we changing a flag on an object that is about to be destroyed by the
nfs_put_client()anyway? Let's go back to the author of commit8dcbec6d20and ask him.
Quoted 3 lines
Chuck, is it possible that you were actually intending to clear
NFS_CS_TSM_POSSIBLEon&old->cl_flags(i.e. on the object that is actually returned by the call tonfs4_init_client())?
Yes, that's plausible.
Quoted 10 lines
Quoted 3 lines
fs/nfs/nfs4client.c +0
-0return old;error:
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
--
Chuck Lever