]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
nfsd: fix possible badness in FREE_STATEID
authorOlga Kornievskaia <okorniev@redhat.com>
Fri, 4 Oct 2024 22:04:03 +0000 (18:04 -0400)
committerChuck Lever <chuck.lever@oracle.com>
Sat, 5 Oct 2024 19:44:25 +0000 (15:44 -0400)
When multiple FREE_STATEIDs are sent for the same delegation stateid,
it can lead to a possible either use-after-free or counter refcount
underflow errors.

In nfsd4_free_stateid() under the client lock we find a delegation
stateid, however the code drops the lock before calling nfs4_put_stid(),
that allows another FREE_STATE to find the stateid again. The first one
will proceed to then free the stateid which leads to either
use-after-free or decrementing already zeroed counter.

Fixes: 3f29cc82a84c ("nfsd: split sc_status out of sc_type")
Signed-off-by: Olga Kornievskaia <okorniev@redhat.com>
Reviewed-by: Benjamin Coddington <bcodding@redhat.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
fs/nfsd/nfs4state.c

index ac1859c7cc9dc7684eb47f4ce025c3fc56e02701..56b261608af46c92e62427d5a10778713cc4b756 100644 (file)
@@ -7154,6 +7154,7 @@ nfsd4_free_stateid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        switch (s->sc_type) {
        case SC_TYPE_DELEG:
                if (s->sc_status & SC_STATUS_REVOKED) {
+                       s->sc_status |= SC_STATUS_CLOSED;
                        spin_unlock(&s->sc_lock);
                        dp = delegstateid(s);
                        list_del_init(&dp->dl_recall_lru);