Skip to content

NFSD: Randomize clientids, session IDs, and COPY_NOTIFY tokens

Chuck Lever linux-nfs 2 versions – New

Get series with b4
b4 am [email protected] change-id 20261029-random-stateids-c66f263d7800

Versions newest first

  1. v2 Latest10 patches 0 repliesNew
  2. v110 patches 3 repliesSuperseded

Changes in v2 from the cover letter

- Re-organized the KUnit tests per recommendations in Documentation/
- Free the KUnit COPY_NOTIFY entry if idr_alloc_u32() fails (sashiko)
- Link to v1: https://patch.msgid.link/[email protected]

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/10NFSD: Serialize forced client expiry with state shutdownfs/nfsd/nfs4state.c+20 -60 replies
2/10NFSD: Check machine credentials before expiring a client in DESTROY_CLIENTIDfs/nfsd/nfs4state.c+8 -30 replies
3/10NFSD: Make nn->boot_time strictly increase across state startsfs/nfsd/nfs4state.c+4 -00 replies
4/10NFSD: Give each client a display id independent of cl_idfs/nfsd/netns.h fs/nfsd/nfs4layouts.c fs/nfsd/nfs4state.c +1 more+10 -70 replies
5/10NFSD: Generate the clientid at random instead of from a counterfs/nfsd/netns.h fs/nfsd/nfs4state.c+100 -100 replies
6/10NFSD: Stop disclosing the conflicting lock holder in a lock denialfs/nfsd/nfs4proc.c fs/nfsd/nfs4state.c fs/nfsd/xdr4.h+9 -370 replies
7/10NFSD: Destroy the COPY_NOTIFY stateid IDR at netns teardownfs/nfsd/nfs4state.c+15 -00 replies
8/10NFSD: Put a random word in each COPY_NOTIFY stateidfs/nfsd/netns.h fs/nfsd/nfs4state.c+17 -200 replies
9/10NFSD: Fill the session ID's sequence and reserved words at randomfs/nfsd/nfs4state.c fs/nfsd/state.h+60 -140 replies
10/10NFSD: Add KUnit tests for the random identifier generatorsfs/nfsd/Kconfig fs/nfsd/Makefile fs/nfsd/nfs4state.c +4 more+740 -340 replies

Reviews trailers per patch

9 of 10 patches have a Reviewed-by or Acked-by.

PatchJeff Layton
1/10R-b
2/10R-b
3/10R-b
4/10R-b
5/10R-b
6/10R-b
7/10R-b
8/10R-b
9/10R-b
10/10

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 00/10] NFSD: Randomize clientids, session IDs, and COPY_NOTIFY tokens

NFSD currently assigns a clientid from a per-netns counter, a session ID's sequence word from a global counter, and a COPY_NOTIFY stateid's so_id from a cyclic allocator with a fixed clientid word. Each of the three is a bearer token. NFSv4.0 resolves a presented stateid against the client named inside it rather than the caller, and the errors the protocol mandates (EXPIRED for an unknown clientid, BAD_STATEID for a known clientid with an unknown index) let the two halves be searched separately. Under SP4_NONE, nfsd4_sequence() does not check a credential, so a session ID alone can reach another client's slot table. Adjacent counter values let a malicious requester find a neighbor's token in a few dozen probes by counting outward from its own.

After this series, the clientid, the session ID, and the COPY_NOTIFY token's clientid word are random. Predicting a live clientid costs about 2^32 / C probes for C clients of the probe's minor version, and a session ID 2^64. An ordinary stateid's so_id stays cyclic, so it stays cheap to search once a clientid is known. RFC 8881 forbids reusing an "other" value for a different purpose, and the cyclic allocator is the non-reuse mechanism clients rely on.

Tested with the new KUnit suite, pynfs 4.0 and 4.1 over loopback, and pynfs-based probes that confirm the three tokens are unpredictable, that a LOCKT denial no longer carries a clientid, and that a COPY_NOTIFY stateid with a wrong clientid word is rejected. A same-second restart loop confirmed STALE_CLIENTID on RENEW and a clean shutdown with live COPY_NOTIFY state.

---
Changes in v2:
- Re-organized the KUnit tests per recommendations in Documentation/
- Free the KUnit COPY_NOTIFY entry if idr_alloc_u32() fails (sashiko)
- Link to v1: https://patch.msgid.link/[email protected]

---
Chuck Lever (10):
NFSD: Serialize forced client expiry with state shutdown
NFSD: Check machine credentials before expiring a client in DESTROY_CLIENTID
NFSD: Make nn->boot_time strictly increase across state starts
NFSD: Give each client a display id independent of cl_id
NFSD: Generate the clientid at random instead of from a counter
NFSD: Stop disclosing the conflicting lock holder in a lock denial
NFSD: Destroy the COPY_NOTIFY stateid IDR at netns teardown
NFSD: Put a random word in each COPY_NOTIFY stateid
NFSD: Fill the session ID's sequence and reserved words at random
NFSD: Add KUnit tests for the random identifier generators

 fs/nfsd/Kconfig                  |  14 +
 fs/nfsd/Makefile                 |   2 +
 fs/nfsd/netns.h                  |   9 +-
 fs/nfsd/nfs4layouts.c            |  10 +-
 fs/nfsd/nfs4proc.c               |   2 -
 fs/nfsd/nfs4state.c              | 313 ++++++++++++++-----
 fs/nfsd/nfsctl.c                 |   2 +
 fs/nfsd/state.h                  |  45 ++-
 fs/nfsd/tests/Makefile           |   3 +
 fs/nfsd/tests/nfsd_state_kunit.c | 634 +++++++++++++++++++++++++++++++++++++++
 fs/nfsd/xdr4.h                   |   2 -
 11 files changed, 944 insertions(+), 92 deletions(-)

---
base-commit: 6ab6af61dba3facd7684c303763bb15da8a959fb
change-id: 20261029-random-stateids-c66f263d7800

Best regards,

Signature · 1 line
Chuck Lever <[email protected]>