Skip to content

kNFSD Signed Filehandles

Benjamin Coddington linux-crypto linux-fsdevel linux-nfs 9 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v7 Latest posting 2/23 patches 1 replyIn review
  2. v7 posting 1/23 patches 3 repliesSuperseded
  3. v6 posting 2/23 patches 2 repliesSuperseded
Earlier versions · 6
VersionPostedPatchesRepliesStatus
v6 posting 1/23 patches3 repliesSuperseded
v53 patches10 repliesSuperseded
v43 patches9 repliesSuperseded
v33 patches3 repliesSuperseded
v23 patches46 repliesSuperseded
v14 patches42 repliesSuperseded

Patches in v7 posting 2/2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3NFSD: Add a key for signing filehandlesDocumentation/netlink/specs/nfsd.yaml fs/nfsd/netlink.c fs/nfsd/netns.h +3 more+70 -30 replies
2/3NFSD/export: Add sign_fh export optionfs/nfsd/export.c include/uapi/linux/nfsd/export.h+5 -40 replies
3/3NFSD: Sign filehandlesDocumentation/filesystems/nfs/exporting.rst fs/nfsd/Kconfig fs/nfsd/nfsfh.c +1 more+157 -50 replies

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by.

PatchJeff Layton
1/3R-b
2/3R-b
3/3R-b

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

Read the v7 thread

Cover letter [RESEND PATCH v7 0/3] kNFSD Signed Filehandles

The following series enables the linux NFS server to add a Message Authentication Code (MAC) to the filehandles it gives to clients. This provides additional protection to the exported filesystem against filehandle guessing attacks.

Filesystems generate their own filehandles through the export_operation "encode_fh" and a filehandle provides sufficient access to open a file without needing to perform a lookup. A trusted NFS client holding a valid filehandle can remotely access the corresponding file without reference to access-path restrictions that might be imposed by the ancestor directories or the server exports.

In order to acquire a filehandle, you must perform lookup operations on the parent directory(ies), and the permissions on those directories may prohibit you from walking into them to find the files within. This would normally be considered sufficient protection on a local filesystem to prohibit users from accessing those files, however when the filesystem is exported via NFS an exported file can be accessed whenever the NFS server is presented with the correct filehandle, which can be guessed or acquired by means other than LOOKUP.

Filehandles are easy to guess because they are well-formed. The open_by_handle_at(2) man page contains an example C program (t_name_to_handle_at.c) that can display a filehandle given a path. Here's an example filehandle from a fairly modern XFS:

# ./t_name_to_handle_at /exports/foo 
57
12 129    99 00 00 00 00 00 00 00 b4 10 0b 8c
          ^---------  filehandle  ----------^
          ^------- inode -------^ ^-- gen --^

This filehandle consists of a 64-bit inode number and 32-bit generation number. Because the handle is well-formed, its easy to fabricate filehandles that match other files within the same filesystem. You can simply insert inode numbers and iterate on the generation number. Eventually you'll be able to access the file using open_by_handle_at(2). For a local system, open_by_handle_at(2) requires CAP_DAC_READ_SEARCH, which protects against guessing attacks by unprivileged users.

Simple testing confirms that the correct generation number can be found within ~1200 minutes using open_by_handle_at() over NFS on a local system and it is estimated that adding network delay with genuine NFS calls may only increase this to around 24 hours.

In contrast to a local user using open_by_handle(2), the NFS server must permissively allow remote clients to open by filehandle without being able to check or trust the remote caller's access. Therefore additional protection against this attack is needed for NFS case. We propose to sign filehandles by appending an 8-byte MAC which is the siphash of the filehandle from a key set from the nfs-utilities. NFS server can then ensure that guessing a valid filehandle+MAC is practically impossible without knowledge of the MAC's key. The NFS server performs optional signing by possessing a key set from userspace and having the "sign_fh" export option.

Because filehandles are long-lived, and there's no method for expiring them, the server's key should be set once and not changed. It also should be persisted across restarts. The methods to set the key allow only setting it once, afterward it cannot be changed. A separate patchset for nfs-utils contains the userspace changes required to set the server's key.

I had planned on adding additional work to enable the server to check whether the 8-byte MAC will overflow maximum filehandle length for the protocol at export time. There could be some filesystems with 40-byte fileid and 24-byte fsid which would break NFSv3's 64-byte filehandle maximum with an 8-byte MAC appended. The server should refuse to export those filesystems when "sign_fh" is requested. However, the way the export caches work (the server may not even be running when a user sets up the export) its impossible to do this check at export time. Instead, the server will refuse to give out filehandles at mount time and emit a pr_warn().

Thanks for any comments and critique.

Changes from encrypt_fh posting:
https://lore.kernel.org/linux-nfs/[email protected]
- sign filehandles instead of encrypt them (Eric Biggers)
- fix the NFSEXP_ macros, specifically NFSEXP_ALLFLAGS (NeilBrown)
- rebase onto cel/nfsd-next (Chuck Lever)
- condensed/clarified problem explantion (thanks Chuck Lever)
- add nfsctl file "fh_key" for rpc.nfsd to also set the key

Changes from v1 posting:
https://lore.kernel.org/linux-nfs/[email protected]
- remove fh_fileid_offset() (Chuck Lever)
- fix pr_warns, fix memcmp (Chuck Lever)
- remove incorrect rootfh comment (NeilBrown)
- make fh_key setting an optional attr to threads verb (Jeff Layton)
- drop BIT() EXP_ flag conversion
- cover-letter tune-ups (NeilBrown, Chuck Lever)
- fix NFSEXP_ALLFLAGS on 2/3
- cast fh->fh_size + sizeof(hash) result to int (avoid x86_64 WARNING)
- move MAC signing into __fh_update() (Chuck Lever)

Changes from v2 posting:
https://lore.kernel.org/linux-nfs/[email protected]
- more cover-letter detail (NeilBrown)
- Documentation/filesystems/nfs/exporting.rst section (Jeff Layton)
- fix key copy (Eric Biggers)
- use NFSD_A_SERVER_MAX (NeilBrown)
- remove procfs fh_key interface (Chuck Lever)
- remove FH_AT_MAC (Chuck Lever)
- allow fh_key change when server is not running (Chuck/Jeff)
- accept fh_key as netlink attribute instead of command (Jeff Layton)

Changes from v3 posting:
https://lore.kernel.org/linux-nfs/[email protected]
- /actually/ fix up endianness problems (Eric Biggers)
- comment typo
- fix Documentation underline warnings
- fix possible uninitialized fh_key var

Changes from v4 posting:
https://lore.kernel.org/linux-nfs/[email protected]
- again (!!) fix endian copy from userspace (Chuck Lever)
- fixup protocol return error for MAC verification failure (Chuck Lever)
- fix filehandle size after MAC verification (Chuck Lever)
- fix two sparse errors (LKP)

Changes from v5 posting:
https://lore.kernel.org/linux-nfs/[email protected]
- fixup 3/3 commit message to match code return _STALE (Chuck Lever)
- convert fh sign functions to return bool (Chuck Lever)
- comment for FILEID_ROOT always unsigned (Chuck Lever)
- tracepoint error value match return -ESTALE (Chuck Lever)
- fix a fh data_left bug (Chuck Lever)
- symbolize size of signing value in words (Chuck Lever)
- 3/3 add simple rational for choice of hash (Chuck Lever)
- fix an incorrect error return leak introduced on v5
- remove a duplicate include (Chuck Lever)
- inform callers of nfsd_nl_fh_key_set of shutdown req (Chuck Lever)
- hash key in tracepoint output (Chuck Lever)

Changes from v6 posting:
https://lore.kernel.org/linux-nfs/[email protected]
- rebase onto current cel/nfsd-testing, take maintainer changes
- move Kconfig "select CRYPTO" from NFSD_V4 to NFSD for crypto_memneq()

Benjamin Coddington (3):
NFSD: Add a key for signing filehandles
NFSD/export: Add sign_fh export option
NFSD: Sign filehandles

 Documentation/filesystems/nfs/exporting.rst | 85 +++++++++++++++++++++
 Documentation/netlink/specs/nfsd.yaml       |  6 ++
 fs/nfsd/Kconfig                             |  2 +-
 fs/nfsd/export.c                            |  5 +-
 fs/nfsd/netlink.c                           |  5 +-
 fs/nfsd/netns.h                             |  1 +
 fs/nfsd/nfsctl.c                            | 38 ++++++++-
 fs/nfsd/nfsfh.c                             | 74 +++++++++++++++++-
 fs/nfsd/trace.h                             | 23 ++++++
 include/uapi/linux/nfsd/export.h            |  4 +-
 include/uapi/linux/nfsd_netlink.h           |  1 +
 11 files changed, 232 insertions(+), 12 deletions(-)

base-commit: 74be0455c8fccc56f668c443f3e6c784f1b7dbc5
prerequisite-patch-id: aa7471b70863a8d50f76cbe59a459e2b174b9bde
prerequisite-patch-id: 86c22e04dc3f7e13012f7df35062332662aabeb1
prerequisite-patch-id: 785b66a20e714c68c70b2bc5d04ffecd3f5e8886
prerequisite-patch-id: 0e1bca4703bda3ea8cdc22c4f9aaef8626d412e6
prerequisite-patch-id: e2cadbb6b38006e1ddefc537800d63755e519534
prerequisite-patch-id: 70b31c12fec31e7608ec69e81d0e69ae191eecd8
prerequisite-patch-id: 70e076fbc3d74787f486f6498a43aca06be10a5b
prerequisite-patch-id: 20cd3620f99e8c4f883b7edff4bfebabb449cea0
prerequisite-patch-id: cdea6cd214f376f123ca91075407d47713d502c0
prerequisite-patch-id: ce569f2d71f639ba0de805756b8c562211d02b65
prerequisite-patch-id: 2b9b54ebcf4937f90118efc142f0b34552cb47a8
prerequisite-patch-id: 6e6e2a8341e922efb72f04bab7498451600295f3
prerequisite-patch-id: 833653d35ba03741e6a0181d20941e9f91438ff2
prerequisite-patch-id: 86b33df9b7b7682c118623f5d2714560d9c90c6a
prerequisite-patch-id: 2659cfe2294725cc8038264888fd59a850e70451
prerequisite-patch-id: b8bc9d34cdaf2b215634944621e560acf7cd2f4b
prerequisite-patch-id: 390396f3d28938249168c0bcd140c1c7ebe70b72
prerequisite-patch-id: 13387919d55666c852d129d6fe3f766754c3bae5
prerequisite-patch-id: a8ec6d86976a9858d7614aa0c42de1e8420d02de
prerequisite-patch-id: aab718e5cc8e166f2b7314a20e4d36bb08d3a505
prerequisite-patch-id: 1ddf7fb4dec908557e2f21bbcadb3121d47cb217
prerequisite-patch-id: 7ddf30b5167554d95edb645ee02178a1ae4116a1
prerequisite-patch-id: 5b6b107835b937d683ff314cf259ee37ac3e36e6
prerequisite-patch-id: 3f5805b2cd187262c3c04d0a316a003a61258655
prerequisite-patch-id: 03dcee5b42778363e76d2cc41a5a9a38bef7e6ce
prerequisite-patch-id: 54fee412c1056676539d98531fd5c9cc38f7a452
prerequisite-patch-id: c99d5e206d7c832360fd5e5b87fb452155eee43b
prerequisite-patch-id: 34f61e845328b7f669759988d952a1eee2df51aa
prerequisite-patch-id: 91080c262771e2d108185ba18ee8c4ad62067284
prerequisite-patch-id: a0ecf2b16e4e2729e85bcec7b38140d6690cdf4f
prerequisite-patch-id: aeb1879e01039209c6e1e82f01027126c9caa5f6
prerequisite-patch-id: 5c2ffb43f148547ad3e44411a2150fa9cc1c1317
prerequisite-patch-id: 367a74e761b36c68545db41051e1e7831b1cfb18
prerequisite-patch-id: 0ed88b7a0fbc9ce65f3f7c5110221fe137cdba33
prerequisite-patch-id: dd337779d72bd16340d6addb49f472f816ab0095
prerequisite-patch-id: 9827cb023f9277d52951fb89bf018d400455dfd7
prerequisite-patch-id: 03dfbd11d7665cde9c7f2ab55abe67d81bca00eb
prerequisite-patch-id: df5a4e0d677d46ee7a1f7c24ae0982b6a1dc7479
prerequisite-patch-id: a668a219b466ff8a5f3fdde3c39b807eb4773bc4
prerequisite-patch-id: 7af5afc30a82624160fcb5264334f5aac6af023d
prerequisite-patch-id: 61f6e24aecec981d6e9e86841436191d36a0d66a

Signature · 1 line
2.53.0