* [RESEND PATCH v7 0/3] kNFSD Signed Filehandles
@ 2026-02-25 12:51 Benjamin Coddington
2026-02-25 12:51 ` [PATCH v7 1/3] NFSD: Add a key for signing filehandles Benjamin Coddington
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Benjamin Coddington @ 2026-02-25 12:51 UTC (permalink / raw)
To: Chuck Lever, Jeff Layton, NeilBrown, Trond Myklebust,
Anna Schumaker, Benjamin Coddington, Eric Biggers, Rick Macklem
Cc: linux-nfs, linux-fsdevel, linux-crypto
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/510E10A4-11BE-412D-93AF-C4CC969954E7@hammerspace.com
- 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/cover.1768573690.git.bcodding@hammerspace.com
- 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/cover.1769026777.git.bcodding@hammerspace.com
- 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/cover.1770046529.git.bcodding@hammerspace.com
- /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/cover.1770390036.git.bcodding@hammerspace.com
- 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/cover.1770660136.git.bcodding@hammerspace.com
- 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/cover.1770873427.git.bcodding@hammerspace.com
- 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
--
2.53.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v7 1/3] NFSD: Add a key for signing filehandles
2026-02-25 12:51 [RESEND PATCH v7 0/3] kNFSD Signed Filehandles Benjamin Coddington
@ 2026-02-25 12:51 ` Benjamin Coddington
2026-02-25 12:51 ` [PATCH v7 2/3] NFSD/export: Add sign_fh export option Benjamin Coddington
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Benjamin Coddington @ 2026-02-25 12:51 UTC (permalink / raw)
To: Chuck Lever, Jeff Layton, NeilBrown, Trond Myklebust,
Anna Schumaker, Benjamin Coddington, Eric Biggers, Rick Macklem
Cc: linux-nfs, linux-fsdevel, linux-crypto
A future patch will enable NFSD to sign filehandles by appending a Message
Authentication Code(MAC). To do this, NFSD requires a secret 128-bit key
that can persist across reboots. A persisted key allows the server to
accept filehandles after a restart. Enable NFSD to be configured with this
key via the netlink interface.
Link: https://lore.kernel.org/linux-nfs/cover.1772022373.git.bcodding@hammerspace.com
Signed-off-by: Benjamin Coddington <bcodding@hammerspace.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
Documentation/netlink/specs/nfsd.yaml | 6 +++++
fs/nfsd/netlink.c | 5 ++--
fs/nfsd/netns.h | 1 +
fs/nfsd/nfsctl.c | 38 ++++++++++++++++++++++++++-
fs/nfsd/trace.h | 22 ++++++++++++++++
include/uapi/linux/nfsd_netlink.h | 1 +
6 files changed, 70 insertions(+), 3 deletions(-)
diff --git a/Documentation/netlink/specs/nfsd.yaml b/Documentation/netlink/specs/nfsd.yaml
index badb2fe57c98..d348648033d9 100644
--- a/Documentation/netlink/specs/nfsd.yaml
+++ b/Documentation/netlink/specs/nfsd.yaml
@@ -81,6 +81,11 @@ attribute-sets:
-
name: min-threads
type: u32
+ -
+ name: fh-key
+ type: binary
+ checks:
+ exact-len: 16
-
name: version
attributes:
@@ -163,6 +168,7 @@ operations:
- leasetime
- scope
- min-threads
+ - fh-key
-
name: threads-get
doc: get the number of running threads
diff --git a/fs/nfsd/netlink.c b/fs/nfsd/netlink.c
index 887525964451..4e08c1a6b394 100644
--- a/fs/nfsd/netlink.c
+++ b/fs/nfsd/netlink.c
@@ -24,12 +24,13 @@ const struct nla_policy nfsd_version_nl_policy[NFSD_A_VERSION_ENABLED + 1] = {
};
/* NFSD_CMD_THREADS_SET - do */
-static const struct nla_policy nfsd_threads_set_nl_policy[NFSD_A_SERVER_MIN_THREADS + 1] = {
+static const struct nla_policy nfsd_threads_set_nl_policy[NFSD_A_SERVER_FH_KEY + 1] = {
[NFSD_A_SERVER_THREADS] = { .type = NLA_U32, },
[NFSD_A_SERVER_GRACETIME] = { .type = NLA_U32, },
[NFSD_A_SERVER_LEASETIME] = { .type = NLA_U32, },
[NFSD_A_SERVER_SCOPE] = { .type = NLA_NUL_STRING, },
[NFSD_A_SERVER_MIN_THREADS] = { .type = NLA_U32, },
+ [NFSD_A_SERVER_FH_KEY] = NLA_POLICY_EXACT_LEN(16),
};
/* NFSD_CMD_VERSION_SET - do */
@@ -58,7 +59,7 @@ static const struct genl_split_ops nfsd_nl_ops[] = {
.cmd = NFSD_CMD_THREADS_SET,
.doit = nfsd_nl_threads_set_doit,
.policy = nfsd_threads_set_nl_policy,
- .maxattr = NFSD_A_SERVER_MIN_THREADS,
+ .maxattr = NFSD_A_SERVER_MAX,
.flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO,
},
{
diff --git a/fs/nfsd/netns.h b/fs/nfsd/netns.h
index 3a89d4708e8a..6ad3fe5d7e12 100644
--- a/fs/nfsd/netns.h
+++ b/fs/nfsd/netns.h
@@ -227,6 +227,7 @@ struct nfsd_net {
spinlock_t local_clients_lock;
struct list_head local_clients;
#endif
+ siphash_key_t *fh_key;
};
/* Simple check to find out if a given net was properly initialized */
diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c
index a745b97b45fb..032ab44feb70 100644
--- a/fs/nfsd/nfsctl.c
+++ b/fs/nfsd/nfsctl.c
@@ -1581,6 +1581,32 @@ int nfsd_nl_rpc_status_get_dumpit(struct sk_buff *skb,
return ret;
}
+/**
+ * nfsd_nl_fh_key_set - helper to copy fh_key from userspace
+ * @attr: nlattr NFSD_A_SERVER_FH_KEY
+ * @nn: nfsd_net
+ *
+ * Callers should hold nfsd_mutex, returns 0 on success or negative errno.
+ * Callers must ensure the server is shut down (sv_nrthreads == 0),
+ * userspace documentation asserts the key may only be set when the server
+ * is not running.
+ */
+static int nfsd_nl_fh_key_set(const struct nlattr *attr, struct nfsd_net *nn)
+{
+ siphash_key_t *fh_key = nn->fh_key;
+
+ if (!fh_key) {
+ fh_key = kmalloc(sizeof(siphash_key_t), GFP_KERNEL);
+ if (!fh_key)
+ return -ENOMEM;
+ nn->fh_key = fh_key;
+ }
+
+ fh_key->key[0] = get_unaligned_le64(nla_data(attr));
+ fh_key->key[1] = get_unaligned_le64(nla_data(attr) + 8);
+ return 0;
+}
+
/**
* nfsd_nl_threads_set_doit - set the number of running threads
* @skb: reply buffer
@@ -1622,7 +1648,8 @@ int nfsd_nl_threads_set_doit(struct sk_buff *skb, struct genl_info *info)
if (info->attrs[NFSD_A_SERVER_GRACETIME] ||
info->attrs[NFSD_A_SERVER_LEASETIME] ||
- info->attrs[NFSD_A_SERVER_SCOPE]) {
+ info->attrs[NFSD_A_SERVER_SCOPE] ||
+ info->attrs[NFSD_A_SERVER_FH_KEY]) {
ret = -EBUSY;
if (nn->nfsd_serv && nn->nfsd_serv->sv_nrthreads)
goto out_unlock;
@@ -1651,6 +1678,14 @@ int nfsd_nl_threads_set_doit(struct sk_buff *skb, struct genl_info *info)
attr = info->attrs[NFSD_A_SERVER_SCOPE];
if (attr)
scope = nla_data(attr);
+
+ attr = info->attrs[NFSD_A_SERVER_FH_KEY];
+ if (attr) {
+ ret = nfsd_nl_fh_key_set(attr, nn);
+ trace_nfsd_ctl_fh_key_set((const char *)nn->fh_key, ret);
+ if (ret)
+ goto out_unlock;
+ }
}
attr = info->attrs[NFSD_A_SERVER_MIN_THREADS];
@@ -2250,6 +2285,7 @@ static __net_exit void nfsd_net_exit(struct net *net)
{
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
+ kfree_sensitive(nn->fh_key);
nfsd_proc_stat_shutdown(net);
percpu_counter_destroy_many(nn->counter, NFSD_STATS_COUNTERS_NUM);
nfsd_idmap_shutdown(net);
diff --git a/fs/nfsd/trace.h b/fs/nfsd/trace.h
index d1d0b0dd0545..185a998996a0 100644
--- a/fs/nfsd/trace.h
+++ b/fs/nfsd/trace.h
@@ -2240,6 +2240,28 @@ TRACE_EVENT(nfsd_end_grace,
)
);
+TRACE_EVENT(nfsd_ctl_fh_key_set,
+ TP_PROTO(
+ const char *key,
+ int result
+ ),
+ TP_ARGS(key, result),
+ TP_STRUCT__entry(
+ __field(u32, key_hash)
+ __field(int, result)
+ ),
+ TP_fast_assign(
+ if (key)
+ __entry->key_hash = ~crc32_le(0xFFFFFFFF, key, 16);
+ else
+ __entry->key_hash = 0;
+ __entry->result = result;
+ ),
+ TP_printk("key=0x%08x result=%d",
+ __entry->key_hash, __entry->result
+ )
+);
+
DECLARE_EVENT_CLASS(nfsd_copy_class,
TP_PROTO(
const struct nfsd4_copy *copy
diff --git a/include/uapi/linux/nfsd_netlink.h b/include/uapi/linux/nfsd_netlink.h
index e9efbc9e63d8..97c7447f4d14 100644
--- a/include/uapi/linux/nfsd_netlink.h
+++ b/include/uapi/linux/nfsd_netlink.h
@@ -36,6 +36,7 @@ enum {
NFSD_A_SERVER_LEASETIME,
NFSD_A_SERVER_SCOPE,
NFSD_A_SERVER_MIN_THREADS,
+ NFSD_A_SERVER_FH_KEY,
__NFSD_A_SERVER_MAX,
NFSD_A_SERVER_MAX = (__NFSD_A_SERVER_MAX - 1)
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v7 2/3] NFSD/export: Add sign_fh export option
2026-02-25 12:51 [RESEND PATCH v7 0/3] kNFSD Signed Filehandles Benjamin Coddington
2026-02-25 12:51 ` [PATCH v7 1/3] NFSD: Add a key for signing filehandles Benjamin Coddington
@ 2026-02-25 12:51 ` Benjamin Coddington
2026-02-25 12:51 ` [PATCH v7 3/3] NFSD: Sign filehandles Benjamin Coddington
2026-02-25 15:20 ` [RESEND PATCH v7 0/3] kNFSD Signed Filehandles Chuck Lever
3 siblings, 0 replies; 5+ messages in thread
From: Benjamin Coddington @ 2026-02-25 12:51 UTC (permalink / raw)
To: Chuck Lever, Jeff Layton, NeilBrown, Trond Myklebust,
Anna Schumaker, Benjamin Coddington, Eric Biggers, Rick Macklem
Cc: linux-nfs, linux-fsdevel, linux-crypto
In order to signal that filehandles on this export should be signed, add a
"sign_fh" export option. Filehandle signing can help the server defend
against certain filehandle guessing attacks.
Setting the "sign_fh" export option sets NFSEXP_SIGN_FH. In a future patch
NFSD uses this signal to append a MAC onto filehandles for that export.
While we're in here, tidy a few stray expflags to more closely align to the
export flag order.
Link: https://lore.kernel.org/linux-nfs/cover.1772022373.git.bcodding@hammerspace.com
Signed-off-by: Benjamin Coddington <bcodding@hammerspace.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
fs/nfsd/export.c | 5 +++--
include/uapi/linux/nfsd/export.h | 4 ++--
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c
index 8e8a76a44ff0..7f4a51b832ef 100644
--- a/fs/nfsd/export.c
+++ b/fs/nfsd/export.c
@@ -1362,13 +1362,14 @@ static struct flags {
{ NFSEXP_ASYNC, {"async", "sync"}},
{ NFSEXP_GATHERED_WRITES, {"wdelay", "no_wdelay"}},
{ NFSEXP_NOREADDIRPLUS, {"nordirplus", ""}},
+ { NFSEXP_SECURITY_LABEL, {"security_label", ""}},
+ { NFSEXP_SIGN_FH, {"sign_fh", ""}},
{ NFSEXP_NOHIDE, {"nohide", ""}},
- { NFSEXP_CROSSMOUNT, {"crossmnt", ""}},
{ NFSEXP_NOSUBTREECHECK, {"no_subtree_check", ""}},
{ NFSEXP_NOAUTHNLM, {"insecure_locks", ""}},
+ { NFSEXP_CROSSMOUNT, {"crossmnt", ""}},
{ NFSEXP_V4ROOT, {"v4root", ""}},
{ NFSEXP_PNFS, {"pnfs", ""}},
- { NFSEXP_SECURITY_LABEL, {"security_label", ""}},
{ 0, {"", ""}}
};
diff --git a/include/uapi/linux/nfsd/export.h b/include/uapi/linux/nfsd/export.h
index a73ca3703abb..de647cf166c3 100644
--- a/include/uapi/linux/nfsd/export.h
+++ b/include/uapi/linux/nfsd/export.h
@@ -34,7 +34,7 @@
#define NFSEXP_GATHERED_WRITES 0x0020
#define NFSEXP_NOREADDIRPLUS 0x0040
#define NFSEXP_SECURITY_LABEL 0x0080
-/* 0x100 currently unused */
+#define NFSEXP_SIGN_FH 0x0100
#define NFSEXP_NOHIDE 0x0200
#define NFSEXP_NOSUBTREECHECK 0x0400
#define NFSEXP_NOAUTHNLM 0x0800 /* Don't authenticate NLM requests - just trust */
@@ -55,7 +55,7 @@
#define NFSEXP_PNFS 0x20000
/* All flags that we claim to support. (Note we don't support NOACL.) */
-#define NFSEXP_ALLFLAGS 0x3FEFF
+#define NFSEXP_ALLFLAGS 0x3FFFF
/* The flags that may vary depending on security flavor: */
#define NFSEXP_SECINFO_FLAGS (NFSEXP_READONLY | NFSEXP_ROOTSQUASH \
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v7 3/3] NFSD: Sign filehandles
2026-02-25 12:51 [RESEND PATCH v7 0/3] kNFSD Signed Filehandles Benjamin Coddington
2026-02-25 12:51 ` [PATCH v7 1/3] NFSD: Add a key for signing filehandles Benjamin Coddington
2026-02-25 12:51 ` [PATCH v7 2/3] NFSD/export: Add sign_fh export option Benjamin Coddington
@ 2026-02-25 12:51 ` Benjamin Coddington
2026-02-25 15:20 ` [RESEND PATCH v7 0/3] kNFSD Signed Filehandles Chuck Lever
3 siblings, 0 replies; 5+ messages in thread
From: Benjamin Coddington @ 2026-02-25 12:51 UTC (permalink / raw)
To: Chuck Lever, Jeff Layton, NeilBrown, Trond Myklebust,
Anna Schumaker, Benjamin Coddington, Eric Biggers, Rick Macklem
Cc: linux-nfs, linux-fsdevel, linux-crypto
NFS clients may bypass restrictive directory permissions by using
open_by_handle() (or other available OS system call) to guess the
filehandles for files below that directory.
In order to harden knfsd servers against this attack, create a method to
sign and verify filehandles using SipHash-2-4 as a MAC (Message
Authentication Code). According to
https://cr.yp.to/siphash/siphash-20120918.pdf, SipHash can be used as a
MAC, and our use of SipHash-2-4 provides a low 1 in 2^64 chance of forgery.
Filehandles that have been signed cannot be tampered with, nor can
clients reasonably guess correct filehandles and hashes that may exist in
parts of the filesystem they cannot access due to directory permissions.
Append the 8 byte SipHash to encoded filehandles for exports that have set
the "sign_fh" export option. Filehandles received from clients are
verified by comparing the appended hash to the expected hash. If the MAC
does not match the server responds with NFS error _STALE. If unsigned
filehandles are received for an export with "sign_fh" they are rejected
with NFS error _STALE.
Signed-off-by: Benjamin Coddington <bcodding@hammerspace.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
---
Documentation/filesystems/nfs/exporting.rst | 85 +++++++++++++++++++++
fs/nfsd/Kconfig | 2 +-
fs/nfsd/nfsfh.c | 74 +++++++++++++++++-
fs/nfsd/trace.h | 1 +
4 files changed, 157 insertions(+), 5 deletions(-)
diff --git a/Documentation/filesystems/nfs/exporting.rst b/Documentation/filesystems/nfs/exporting.rst
index a01d9b9b5bc3..4aa59b0bf253 100644
--- a/Documentation/filesystems/nfs/exporting.rst
+++ b/Documentation/filesystems/nfs/exporting.rst
@@ -206,3 +206,88 @@ following flags are defined:
all of an inode's dirty data on last close. Exports that behave this
way should set EXPORT_OP_FLUSH_ON_CLOSE so that NFSD knows to skip
waiting for writeback when closing such files.
+
+Signed Filehandles
+------------------
+
+To protect against filehandle guessing attacks, the Linux NFS server can be
+configured to sign filehandles with a Message Authentication Code (MAC).
+
+Standard NFS filehandles are often predictable. If an attacker can guess
+a valid filehandle for a file they do not have permission to access via
+directory traversal, they may be able to bypass path-based permissions
+(though they still remain subject to inode-level permissions).
+
+Signed filehandles prevent this by appending a MAC to the filehandle
+before it is sent to the client. Upon receiving a filehandle back from a
+client, the server re-calculates the MAC using its internal key and
+verifies it against the one provided. If the signatures do not match,
+the server treats the filehandle as invalid (returning NFS[34]ERR_STALE).
+
+Note that signing filehandles provides integrity and authenticity but
+not confidentiality. The contents of the filehandle remain visible to
+the client; they simply cannot be forged or modified.
+
+Configuration
+~~~~~~~~~~~~~
+
+To enable signed filehandles, the administrator must provide a signing
+key to the kernel and enable the "sign_fh" export option.
+
+1. Providing a Key
+ The signing key is managed via the nfsd netlink interface. This key
+ is per-network-namespace and must be set before any exports using
+ "sign_fh" become active.
+
+2. Export Options
+ The feature is controlled on a per-export basis in /etc/exports:
+
+ sign_fh
+ Enables signing for all filehandles generated under this export.
+
+ no_sign_fh
+ (Default) Disables signing.
+
+Key Management and Rotation
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The security of this mechanism relies entirely on the secrecy of the
+signing key.
+
+Initial Setup:
+ The key should be generated using a high-quality random source and
+ loaded early in the boot process or during the nfs-server startup
+ sequence.
+
+Changing Keys:
+ If a key is changed while clients have active mounts, existing
+ filehandles held by those clients will become invalid, resulting in
+ "Stale file handle" errors on the client side.
+
+Safe Rotation:
+ Currently, there is no mechanism for "graceful" key rotation
+ (maintaining multiple valid keys). Changing the key is an atomic
+ operation that immediately invalidates all previous signatures.
+
+Transitioning Exports
+~~~~~~~~~~~~~~~~~~~~~
+
+When adding or removing the "sign_fh" flag from an active export, the
+following behaviors should be expected:
+
++-------------------+---------------------------------------------------+
+| Change | Result for Existing Clients |
++===================+===================================================+
+| Adding sign_fh | Clients holding unsigned filehandles will find |
+| | them rejected, as the server now expects a |
+| | signature. |
++-------------------+---------------------------------------------------+
+| Removing sign_fh | Clients holding signed filehandles will find them |
+| | rejected, as the server now expects the |
+| | filehandle to end at its traditional boundary |
+| | without a MAC. |
++-------------------+---------------------------------------------------+
+
+Because filehandles are often cached persistently by clients, adding or
+removing this option should generally be done during a scheduled maintenance
+window involving a NFS client unmount/remount.
diff --git a/fs/nfsd/Kconfig b/fs/nfsd/Kconfig
index fc0e87eaa257..ffb76761d6a8 100644
--- a/fs/nfsd/Kconfig
+++ b/fs/nfsd/Kconfig
@@ -7,6 +7,7 @@ config NFSD
select CRC32
select CRYPTO_LIB_MD5 if NFSD_LEGACY_CLIENT_TRACKING
select CRYPTO_LIB_SHA256 if NFSD_V4
+ select CRYPTO # required by RPCSEC_GSS_KRB5 and signed filehandles
select LOCKD
select SUNRPC
select EXPORTFS
@@ -78,7 +79,6 @@ config NFSD_V4
depends on NFSD && PROC_FS
select FS_POSIX_ACL
select RPCSEC_GSS_KRB5
- select CRYPTO # required by RPCSEC_GSS_KRB5
select GRACE_PERIOD
select NFS_V4_2_SSC_HELPER if NFS_V4_2
help
diff --git a/fs/nfsd/nfsfh.c b/fs/nfsd/nfsfh.c
index 68b629fbaaeb..bce8784aa92e 100644
--- a/fs/nfsd/nfsfh.c
+++ b/fs/nfsd/nfsfh.c
@@ -11,6 +11,7 @@
#include <linux/exportfs.h>
#include <linux/sunrpc/svcauth_gss.h>
+#include <crypto/utils.h>
#include "nfsd.h"
#include "vfs.h"
#include "auth.h"
@@ -140,6 +141,57 @@ static inline __be32 check_pseudo_root(struct dentry *dentry,
return nfs_ok;
}
+/* Size of a file handle MAC, in 4-octet words */
+#define FH_MAC_WORDS (sizeof(__le64) / 4)
+
+static bool fh_append_mac(struct svc_fh *fhp, struct net *net)
+{
+ struct nfsd_net *nn = net_generic(net, nfsd_net_id);
+ struct knfsd_fh *fh = &fhp->fh_handle;
+ siphash_key_t *fh_key = nn->fh_key;
+ __le64 hash;
+
+ if (!fh_key)
+ goto out_no_key;
+ if (fh->fh_size + sizeof(hash) > fhp->fh_maxsize)
+ goto out_no_space;
+
+ hash = cpu_to_le64(siphash(&fh->fh_raw, fh->fh_size, fh_key));
+ memcpy(&fh->fh_raw[fh->fh_size], &hash, sizeof(hash));
+ fh->fh_size += sizeof(hash);
+ return true;
+
+out_no_key:
+ pr_warn_ratelimited("NFSD: unable to sign filehandles, fh_key not set.\n");
+ return false;
+
+out_no_space:
+ pr_warn_ratelimited("NFSD: unable to sign filehandles, fh_size %zu would be greater than fh_maxsize %d.\n",
+ fh->fh_size + sizeof(hash), fhp->fh_maxsize);
+ return false;
+}
+
+/*
+ * Verify that the filehandle's MAC was hashed from this filehandle
+ * given the server's fh_key:
+ */
+static bool fh_verify_mac(struct svc_fh *fhp, struct net *net)
+{
+ struct nfsd_net *nn = net_generic(net, nfsd_net_id);
+ struct knfsd_fh *fh = &fhp->fh_handle;
+ siphash_key_t *fh_key = nn->fh_key;
+ __le64 hash;
+
+ if (!fh_key) {
+ pr_warn_ratelimited("NFSD: unable to verify signed filehandles, fh_key not set.\n");
+ return false;
+ }
+
+ hash = cpu_to_le64(siphash(&fh->fh_raw, fh->fh_size - sizeof(hash), fh_key));
+ return crypto_memneq(&fh->fh_raw[fh->fh_size - sizeof(hash)],
+ &hash, sizeof(hash)) == 0;
+}
+
/*
* Use the given filehandle to look up the corresponding export and
* dentry. On success, the results are used to set fh_export and
@@ -236,13 +288,21 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct net *net,
/*
* Look up the dentry using the NFS file handle.
*/
- error = nfserr_badhandle;
-
fileid_type = fh->fh_fileid_type;
+ error = nfserr_stale;
- if (fileid_type == FILEID_ROOT)
+ if (fileid_type == FILEID_ROOT) {
+ /* We don't sign or verify the root, no per-file identity */
dentry = dget(exp->ex_path.dentry);
- else {
+ } else {
+ if (exp->ex_flags & NFSEXP_SIGN_FH) {
+ if (!fh_verify_mac(fhp, net)) {
+ trace_nfsd_set_fh_dentry_badmac(rqstp, fhp, -ESTALE);
+ goto out;
+ }
+ data_left -= FH_MAC_WORDS;
+ }
+
dentry = exportfs_decode_fh_raw(exp->ex_path.mnt, fid,
data_left, fileid_type, 0,
nfsd_acceptable, exp);
@@ -258,6 +318,8 @@ static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct net *net,
}
}
}
+
+ error = nfserr_badhandle;
if (dentry == NULL)
goto out;
if (IS_ERR(dentry)) {
@@ -498,6 +560,10 @@ static void _fh_update(struct svc_fh *fhp, struct svc_export *exp,
fhp->fh_handle.fh_fileid_type =
fileid_type > 0 ? fileid_type : FILEID_INVALID;
fhp->fh_handle.fh_size += maxsize * 4;
+
+ if (exp->ex_flags & NFSEXP_SIGN_FH)
+ if (!fh_append_mac(fhp, exp->cd->net))
+ fhp->fh_handle.fh_fileid_type = FILEID_INVALID;
} else {
fhp->fh_handle.fh_fileid_type = FILEID_ROOT;
}
diff --git a/fs/nfsd/trace.h b/fs/nfsd/trace.h
index 185a998996a0..5ad38f50836d 100644
--- a/fs/nfsd/trace.h
+++ b/fs/nfsd/trace.h
@@ -373,6 +373,7 @@ DEFINE_EVENT_CONDITION(nfsd_fh_err_class, nfsd_##name, \
DEFINE_NFSD_FH_ERR_EVENT(set_fh_dentry_badexport);
DEFINE_NFSD_FH_ERR_EVENT(set_fh_dentry_badhandle);
+DEFINE_NFSD_FH_ERR_EVENT(set_fh_dentry_badmac);
TRACE_EVENT(nfsd_exp_find_key,
TP_PROTO(const struct svc_expkey *key,
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [RESEND PATCH v7 0/3] kNFSD Signed Filehandles
2026-02-25 12:51 [RESEND PATCH v7 0/3] kNFSD Signed Filehandles Benjamin Coddington
` (2 preceding siblings ...)
2026-02-25 12:51 ` [PATCH v7 3/3] NFSD: Sign filehandles Benjamin Coddington
@ 2026-02-25 15:20 ` Chuck Lever
3 siblings, 0 replies; 5+ messages in thread
From: Chuck Lever @ 2026-02-25 15:20 UTC (permalink / raw)
To: Jeff Layton, NeilBrown, Trond Myklebust, Anna Schumaker,
Eric Biggers, Rick Macklem, Benjamin Coddington
Cc: Chuck Lever, linux-nfs, linux-fsdevel, linux-crypto
From: Chuck Lever <chuck.lever@oracle.com>
On Wed, 25 Feb 2026 07:51:35 -0500, Benjamin Coddington wrote:
> 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.
>
> [...]
Applied to nfsd-testing, thanks!
[1/3] NFSD: Add a key for signing filehandles
commit: 168286a8a886b760d3beb2ef41f0f69200393ea7
[2/3] NFSD/export: Add sign_fh export option
commit: a90745b646b3f207e34c559b6a9d0e7e6c551f36
[3/3] NFSD: Sign filehandles
commit: 5a51cb5090c646656958a008b8813ac7a849edaf
--
Chuck Lever
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-02-25 15:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-25 12:51 [RESEND PATCH v7 0/3] kNFSD Signed Filehandles Benjamin Coddington
2026-02-25 12:51 ` [PATCH v7 1/3] NFSD: Add a key for signing filehandles Benjamin Coddington
2026-02-25 12:51 ` [PATCH v7 2/3] NFSD/export: Add sign_fh export option Benjamin Coddington
2026-02-25 12:51 ` [PATCH v7 3/3] NFSD: Sign filehandles Benjamin Coddington
2026-02-25 15:20 ` [RESEND PATCH v7 0/3] kNFSD Signed Filehandles Chuck Lever
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox