* [PATCH v6 1/3] NFSD: Add a key for signing filehandles
2026-02-11 17:09 [PATCH v6 0/3] kNFSD Signed Filehandles Benjamin Coddington
@ 2026-02-11 17:09 ` Benjamin Coddington
2026-02-11 17:09 ` [PATCH v6 2/3] NFSD/export: Add sign_fh export option Benjamin Coddington
2026-02-11 17:09 ` [PATCH v6 3/3] NFSD: Sign filehandles Benjamin Coddington
2 siblings, 0 replies; 7+ messages in thread
From: Benjamin Coddington @ 2026-02-11 17:09 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 the netlink interface.
Link: https://lore.kernel.org/linux-nfs/cover.1770828956.git.bcodding@hammerspace.com
Signed-off-by: Benjamin Coddington <bcodding@hammerspace.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
---
Documentation/netlink/specs/nfsd.yaml | 6 ++++
fs/nfsd/netlink.c | 5 ++--
fs/nfsd/netns.h | 1 +
fs/nfsd/nfsctl.c | 41 ++++++++++++++++++++++++++-
fs/nfsd/trace.h | 22 ++++++++++++++
include/uapi/linux/nfsd_netlink.h | 1 +
6 files changed, 73 insertions(+), 3 deletions(-)
diff --git a/Documentation/netlink/specs/nfsd.yaml b/Documentation/netlink/specs/nfsd.yaml
index f87b5a05e5e9..8ab43c8253b2 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 maximum 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 9fa600602658..0071cc25fbc2 100644
--- a/fs/nfsd/netns.h
+++ b/fs/nfsd/netns.h
@@ -224,6 +224,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 a58eb1adac0f..bdf7311041d6 100644
--- a/fs/nfsd/nfsctl.c
+++ b/fs/nfsd/nfsctl.c
@@ -1571,6 +1571,35 @@ 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 (nla_len(attr) != sizeof(siphash_key_t))
+ return -EINVAL;
+
+ 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
@@ -1612,7 +1641,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;
@@ -1641,6 +1671,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];
@@ -2240,6 +2278,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.50.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v6 2/3] NFSD/export: Add sign_fh export option
2026-02-11 17:09 [PATCH v6 0/3] kNFSD Signed Filehandles Benjamin Coddington
2026-02-11 17:09 ` [PATCH v6 1/3] NFSD: Add a key for signing filehandles Benjamin Coddington
@ 2026-02-11 17:09 ` Benjamin Coddington
2026-02-11 17:09 ` [PATCH v6 3/3] NFSD: Sign filehandles Benjamin Coddington
2 siblings, 0 replies; 7+ messages in thread
From: Benjamin Coddington @ 2026-02-11 17:09 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.1770828956.git.bcodding@hammerspace.com
Signed-off-by: Benjamin Coddington <bcodding@hammerspace.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
---
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 2a1499f2ad19..19c7a91c5373 100644
--- a/fs/nfsd/export.c
+++ b/fs/nfsd/export.c
@@ -1349,13 +1349,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.50.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v6 3/3] NFSD: Sign filehandles
2026-02-11 17:09 [PATCH v6 0/3] kNFSD Signed Filehandles Benjamin Coddington
2026-02-11 17:09 ` [PATCH v6 1/3] NFSD: Add a key for signing filehandles Benjamin Coddington
2026-02-11 17:09 ` [PATCH v6 2/3] NFSD/export: Add sign_fh export option Benjamin Coddington
@ 2026-02-11 17:09 ` Benjamin Coddington
2026-02-11 22:05 ` Chuck Lever
2 siblings, 1 reply; 7+ messages in thread
From: Benjamin Coddington @ 2026-02-11 17:09 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/nfsfh.c | 70 ++++++++++++++++-
fs/nfsd/trace.h | 1 +
3 files changed, 152 insertions(+), 4 deletions(-)
diff --git a/Documentation/filesystems/nfs/exporting.rst b/Documentation/filesystems/nfs/exporting.rst
index de64d2d002a2..54343f4cc4fd 100644
--- a/Documentation/filesystems/nfs/exporting.rst
+++ b/Documentation/filesystems/nfs/exporting.rst
@@ -238,3 +238,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/nfsfh.c b/fs/nfsd/nfsfh.c
index 68b629fbaaeb..3bab2ad0b21f 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;
}
+/*
+ * Append an 8-byte MAC to the filehandle hashed from the server's fh_key:
+ */
+static int 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 (!(fhp->fh_export->ex_flags & NFSEXP_SIGN_FH))
+ return 0;
+
+ if (!fh_key) {
+ pr_warn_ratelimited("NFSD: unable to sign filehandles, fh_key not set.\n");
+ return -EINVAL;
+ }
+
+ if (fh->fh_size + sizeof(hash) > fhp->fh_maxsize) {
+ pr_warn_ratelimited("NFSD: unable to sign filehandles, fh_size %d would be greater"
+ " than fh_maxsize %d.\n", (int)(fh->fh_size + sizeof(hash)), fhp->fh_maxsize);
+ return -EINVAL;
+ }
+
+ 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 0;
+}
+
+/*
+ * Verify that the filehandle's MAC was hashed from this filehandle
+ * given the server's fh_key:
+ */
+static int 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 -EINVAL;
+ }
+
+ 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));
+}
+
/*
* 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,18 @@ 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;
- if (fileid_type == FILEID_ROOT)
+ if (fileid_type == FILEID_ROOT) {
dentry = dget(exp->ex_path.dentry);
- else {
+ } else {
+ if (exp->ex_flags & NFSEXP_SIGN_FH && fh_verify_mac(fhp, net)) {
+ trace_nfsd_set_fh_dentry_badmac(rqstp, fhp, -EKEYREJECTED);
+ goto out;
+ } else {
+ data_left -= sizeof(u64)/4;
+ }
+
dentry = exportfs_decode_fh_raw(exp->ex_path.mnt, fid,
data_left, fileid_type, 0,
nfsd_acceptable, exp);
@@ -258,6 +315,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 +557,9 @@ 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 (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.50.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v6 3/3] NFSD: Sign filehandles
2026-02-11 17:09 ` [PATCH v6 3/3] NFSD: Sign filehandles Benjamin Coddington
@ 2026-02-11 22:05 ` Chuck Lever
2026-02-12 5:24 ` Benjamin Coddington
0 siblings, 1 reply; 7+ messages in thread
From: Chuck Lever @ 2026-02-11 22:05 UTC (permalink / raw)
To: Benjamin Coddington, Chuck Lever, Jeff Layton, NeilBrown,
Trond Myklebust, Anna Schumaker, Eric Biggers, Rick Macklem
Cc: linux-nfs, linux-fsdevel, linux-crypto
On Wed, Feb 11, 2026, at 12:09 PM, Benjamin Coddington wrote:
> 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.
> diff --git a/fs/nfsd/nfsfh.c b/fs/nfsd/nfsfh.c
> index 68b629fbaaeb..3bab2ad0b21f 100644
> --- a/fs/nfsd/nfsfh.c
> +++ b/fs/nfsd/nfsfh.c
> @@ -236,13 +288,18 @@ 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;
>
> - if (fileid_type == FILEID_ROOT)
> + if (fileid_type == FILEID_ROOT) {
Still need a comment here explaining why ROOT is exempt from
file handle signing checks.
> dentry = dget(exp->ex_path.dentry);
> - else {
> + } else {
> + if (exp->ex_flags & NFSEXP_SIGN_FH && fh_verify_mac(fhp, net)) {
> + trace_nfsd_set_fh_dentry_badmac(rqstp, fhp, -EKEYREJECTED);
> + goto out;
> + } else {
> + data_left -= sizeof(u64)/4;
> + }
The data_left bug identified during v5 review:
https://lore.kernel.org/linux-nfs/8574c412-31fb-4810-a675-edf72240ae29@oracle.com/
does not appear to be addressed in v6 3/3. Likewise, the
"sizeof(u64)/4" has not been replaced by a symbolic constant.
Additionally, the goto out path when MAC verification fails has an
error value problem in the !NOSUBTREECHECK case:
error = nfsd_setuser_and_check_port(rqstp, cred, exp);
if (error)
goto out;
/* error is now nfs_ok (0) */
...
if (exp->ex_flags & NFSEXP_SIGN_FH && fh_verify_mac(fhp, net)) {
trace_nfsd_set_fh_dentry_badmac(...);
goto out; /* returns nfs_ok */
}
nfsd_set_fh_dentry() returns 0 without setting fhp->fh_dentry or
fhp->fh_export. The caller __fh_verify() then proceeds with:
dentry = fhp->fh_dentry; /* NULL */
exp = fhp->fh_export; /* NULL */
check_pseudo_root(dentry, exp);
check_pseudo_root() dereferences exp on its first line:
if (!(exp->ex_flags & NFSEXP_V4ROOT))
Can this NULL dereference occur for signed exports that also have
subtree checking enabled?
> +
> dentry = exportfs_decode_fh_raw(exp->ex_path.mnt, fid,
> data_left, fileid_type, 0,
> nfsd_acceptable, exp);
--
Chuck Lever
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v6 3/3] NFSD: Sign filehandles
2026-02-11 22:05 ` Chuck Lever
@ 2026-02-12 5:24 ` Benjamin Coddington
2026-02-12 14:02 ` Chuck Lever
0 siblings, 1 reply; 7+ messages in thread
From: Benjamin Coddington @ 2026-02-12 5:24 UTC (permalink / raw)
To: Chuck Lever
Cc: Chuck Lever, Jeff Layton, NeilBrown, Trond Myklebust,
Anna Schumaker, Eric Biggers, Rick Macklem, linux-nfs,
linux-fsdevel, linux-crypto
On 11 Feb 2026, at 17:05, Chuck Lever wrote:
> On Wed, Feb 11, 2026, at 12:09 PM, Benjamin Coddington wrote:
>> 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.
>
>> diff --git a/fs/nfsd/nfsfh.c b/fs/nfsd/nfsfh.c
>> index 68b629fbaaeb..3bab2ad0b21f 100644
>> --- a/fs/nfsd/nfsfh.c
>> +++ b/fs/nfsd/nfsfh.c
>
>> @@ -236,13 +288,18 @@ 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;
>>
>> - if (fileid_type == FILEID_ROOT)
>> + if (fileid_type == FILEID_ROOT) {
>
> Still need a comment here explaining why ROOT is exempt from
> file handle signing checks.
Right on all points.
I'm really sorry Chuck, I sent the wrong patch here. I am going to resend
v6 with the correct 3/3 patch.
Ben
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v6 3/3] NFSD: Sign filehandles
2026-02-12 5:24 ` Benjamin Coddington
@ 2026-02-12 14:02 ` Chuck Lever
0 siblings, 0 replies; 7+ messages in thread
From: Chuck Lever @ 2026-02-12 14:02 UTC (permalink / raw)
To: Benjamin Coddington
Cc: Chuck Lever, Jeff Layton, NeilBrown, Trond Myklebust,
Anna Schumaker, Eric Biggers, Rick Macklem, linux-nfs,
linux-fsdevel, linux-crypto
On 2/12/26 12:24 AM, Benjamin Coddington wrote:
> On 11 Feb 2026, at 17:05, Chuck Lever wrote:
>
>> On Wed, Feb 11, 2026, at 12:09 PM, Benjamin Coddington wrote:
>>> 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.
>>
>>> diff --git a/fs/nfsd/nfsfh.c b/fs/nfsd/nfsfh.c
>>> index 68b629fbaaeb..3bab2ad0b21f 100644
>>> --- a/fs/nfsd/nfsfh.c
>>> +++ b/fs/nfsd/nfsfh.c
>>
>>> @@ -236,13 +288,18 @@ 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;
>>>
>>> - if (fileid_type == FILEID_ROOT)
>>> + if (fileid_type == FILEID_ROOT) {
>>
>> Still need a comment here explaining why ROOT is exempt from
>> file handle signing checks.
>
> Right on all points.
>
> I'm really sorry Chuck, I sent the wrong patch here. I am going to resend
> v6 with the correct 3/3 patch.
No worries, it looked to me like a tooling issue because the v6 3/3
diff was exactly the same as v5's. The other two v6 patches in the
series are ready to apply IMO, so I'll have a look at the RESEND.
--
Chuck Lever
^ permalink raw reply [flat|nested] 7+ messages in thread