Re: [PATCH v2] NFS: keep in-flight slots when shrinking the session slot table
From: Cheng Yongkang
Date: Mon Nov 30 2026 - 00:18:23 EST
On Sat, 2026-11-28 at 19:56 -0500, Trond Myklebust wrote:
> NACK. nfs4_reset_slot_table() is never called on a session table that
> is in use. It is called as part of the create_session workflow, and as
> part of the NFSv4.0 client initialisation.
The case I hit is the create_session workflow run from
nfs4_reset_session(). The drain there does not keep the table empty
until nfs4_proc_create_session() runs. nfs4_drain_slot_tbl() returns
once highest_used_slotid is NFS4_NO_SLOT, but nfs4_setup_sequence() and
nfs41_assign_slot() still give slots to privileged RPCs while
NFS4_SLOT_TBL_DRAINING is set. Since commit dfe1fe75e00e ("NFSv4: Fix
deadlock between nfs4_evict_inode() and nfs4_opendata_get_inode()"), the
DELEGRETURN sent from nfs4_evict_inode() is privileged once
nfs_igrab_and_active() fails, so it can take a slot after the drain:
state manager inode eviction
nfs4_reset_session()
nfs4_begin_drain_session()
table empty, returns
nfs4_proc_destroy_session()
nfs4_evict_inode()
DELEGRETURN (privileged)
nfs4_setup_sequence()
takes slot 1
nfs4_proc_create_session()
server returns max_reqs = 1
nfs4_setup_session_slot_tables()
nfs4_realloc_slot_table()
nfs4_reset_slot_table()
nfs4_shrink_slot_table()
kfree(slot 1)
DELEGRETURN reply
decode_sequence()
reads the freed slot
I reproduced it on 7.3 with a test server that answers a GETATTR
compound with NFS4ERR_BADSESSION, delays the DESTROY_SESSION and
DELEGRETURN replies, and returns max_reqs = 1 instead of 4 in the new
session:
BUG: KASAN: slab-use-after-free in decode_sequence+0xb3/0x690
Read of size 8 at addr ... by task kworker/u8:1/13
Workqueue: rpciod rpc_async_schedule
decode_sequence+0xb3/0x690
nfs4_xdr_dec_delegreturn+0x54/0x380
call_decode+0x522/0x930
__rpc_execute+0x520/0x1270
rpc_async_schedule+0x52/0xa0
Freed by task ...:
kfree
nfs4_realloc_slot_table+0x597
nfs4_setup_session_slot_tables
nfs4_proc_create_session
nfs4_run_state_manager
The delays only widen the window. RFC 8881 lets a server destroy a
session while fore channel requests are outstanding (section 18.37.3
only allows it to refuse for unanswered CB_COMPOUNDs), and lets it
change ca_maxrequests for the fore channel in CREATE_SESSION (section
18.36).
v2 keeps the slots that are still in use when the table is shrunk. If
you would rather keep the privileged DELEGRETURN off the slot table
during a session reset, or wait for it before
nfs4_proc_create_session(), I can rework it that way.
Thanks,
Cheng