]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
nfsd: avoid leaking pre-allocated openowner on unconfirmed retry race
authorJeff Layton <jlayton@kernel.org>
Fri, 22 May 2026 14:36:14 +0000 (10:36 -0400)
committerChuck Lever <cel@kernel.org>
Tue, 9 Jun 2026 20:32:59 +0000 (16:32 -0400)
When find_or_alloc_open_stateowner() encounters an unconfirmed owner, it
calls release_openowner() and sets oo = NULL. Control then falls through
past the `if (oo)` guard -- which would have freed any pre-allocated
`new` -- and unconditionally executes `new = alloc_stateowner(...)`. If
`new` was already allocated on a prior iteration, the pointer is
silently overwritten and the previous allocation (slab object + owner
name buffer) is leaked.

This requires a race: two NFSv4.0 OPEN threads with the same owner
string, where a concurrent thread inserts a new unconfirmed owner into
the hash between retry iterations. The window is narrow but repeatable
under adversarial conditions.

Fix by adding `goto retry` after `oo = NULL` so the already-allocated
`new` is reused on the next iteration rather than overwritten.

Reported-by: Chris Mason <clm@meta.com>
Fixes: 23df17788c62 ("nfsd: perform all find_openstateowner_str calls in the one place.")
Cc: stable@vger.kernel.org
Assisted-by: kres:claude-opus-4-6
Signed-off-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
fs/nfsd/nfs4state.c

index 2cf021b202a64d6c69ca995f75b026a85ede23d9..a42f34842d776460378672f684ec428487e8fba7 100644 (file)
@@ -5276,6 +5276,7 @@ retry:
                /* Replace unconfirmed owners without checking for replay. */
                release_openowner(oo);
                oo = NULL;
+               goto retry;
        }
        if (oo) {
                if (new)