Skip to contentSkip to conversation

nfs-utils: signed filehandle support

PATCH Superseded Benjamin Coddington 1 participant 3 messages Feb 11

Subsystems (2)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v6 cover nfs-utils: signed filehandle support

Here are two patches allowing userspace to set a secret key for kNFSD to sign filehandles, and also set the option to sign filehandles for an export.

The secret key passed to the server is the first 128 bits of a sha1 hash of the contents of a file configured via the nfs.conf server section "fh_key_file". Exports that have the option "sign_fh" set will cause the server to use this key to append an 8-byte siphash of the filehandle onto each filehandle.

This version of the userspace patches correspond with the v6 of the kernel changes which have been posted here:
https://lore.kernel.org/linux-nfs/[email protected]

This work is based on a branch that includes Jeff Layton's patch for min-threads:
https://lore.kernel.org/linux-nfs/[email protected]/

.. and Jeff Layton's v2 series to fix up userspace handling of kernels that may not support the most recent netlink attributes:
https://lore.kernel.org/linux-nfs/[email protected]/

.. and my patch to automatically load required modules:
https://lore.kernel.org/linux-nfs/09076517d782c31cc0a654563b42b78c846c5f38.1770236512.git.bcodding@hammerspace.com

Comments and critique welcomed.

Changes on v5:
- add -k,--fh-key_file= argument to "nfsdctl threads" command (Jeff Layton)
- fail if "nfsdctl threads -k" unsuported by kernel (Jeff Layton)

Changes on v6:
- fix a premature exit from fh-key-file hashing routine

Benjamin Coddington (2):
exportfs: Add support for export option sign_fh nfsdctl/rpc.nfsd: Add support for passing encrypted filehandle key

 nfs.conf                     |  1 +
 support/include/nfs/export.h |  2 +-
 support/include/nfslib.h     |  2 +
 support/nfs/Makefile.am      |  4 +-
 support/nfs/exports.c        |  4 ++
 support/nfs/fh_key_file.c    | 71 ++++++++++++++++++++++++++++++++++++
 systemd/nfs.conf.man         |  1 +
 utils/exportfs/exportfs.c    |  2 +
 utils/exportfs/exports.man   |  9 +++++
 utils/nfsd/nfssvc.h          |  1 +
 utils/nfsdctl/nfsd_netlink.h |  1 +
 utils/nfsdctl/nfsdctl.8      |  8 +++-
 utils/nfsdctl/nfsdctl.c      | 57 ++++++++++++++++++++++++++---
 13 files changed, 153 insertions(+), 10 deletions(-)
 create mode 100644 support/nfs/fh_key_file.c

base-commit: 8f54511aefe1455161a6c4406ed8c770139f61e3
prerequisite-patch-id: b0d57152c98d360daa9a71e6fa9759b7eb9de348
prerequisite-patch-id: 99680869954aef9f878c24ec9ee1302ab7f24b1a
prerequisite-patch-id: 2ab31271461352d11bcce760e45573f9e6459553
prerequisite-patch-id: 22c392c9dba2e63916af6cd8fbf4e9d6bce9d01c
prerequisite-patch-id: 50f6f48932426f89060eb77de58718baa80b979f

Signature · 1 line
2.50.1
#1 lore raw

PATCH v6 1/2 exportfs: Add support for export option sign_fh

If configured with "sign_fh", exports will be flagged to signal that filehandles should be signed with a Message Authentication Code (MAC).

---
 support/include/nfs/export.h | 2 +-
 support/nfs/exports.c        | 4 ++++
 utils/exportfs/exportfs.c    | 2 ++
 utils/exportfs/exports.man   | 9 +++++++++
 4 files changed, 16 insertions(+), 1 deletion(-)
support/include/nfs/export.h +1 -1
index be5867cffc3c..ef3f3e7ea684 100644
@@ -19,7 +19,7 @@
 #define NFSEXP_GATHERED_WRITES	0x0020
 #define NFSEXP_NOREADDIRPLUS	0x0040
 #define NFSEXP_SECURITY_LABEL	0x0080
-/* 0x100 unused */
+#define NFSEXP_SIGN_FH		0x0100
 #define NFSEXP_NOHIDE		0x0200
 #define NFSEXP_NOSUBTREECHECK	0x0400
 #define NFSEXP_NOAUTHNLM	0x0800
support/nfs/exports.c +4 -0
index 21ec6486ba3d..6b4ca87ee957 100644
@@ -310,6 +310,8 @@ putexportent(struct exportent *ep)
 		fprintf(fp, "nordirplus,");
 	if (ep->e_flags & NFSEXP_SECURITY_LABEL)
 		fprintf(fp, "security_label,");
+	if (ep->e_flags & NFSEXP_SIGN_FH)
+		fprintf(fp, "sign_fh,");
 	fprintf(fp, "%spnfs,", (ep->e_flags & NFSEXP_PNFS)? "" : "no_");
 	if (ep->e_flags & NFSEXP_FSID) {
 		fprintf(fp, "fsid=%d,", ep->e_fsid);
@@ -676,6 +678,8 @@ parseopts(char *cp, struct exportent *ep, int *had_subtree_opt_ptr)
 			setflags(NFSEXP_NOREADDIRPLUS, active, ep);
 		else if (!strcmp(opt, "security_label"))
 			setflags(NFSEXP_SECURITY_LABEL, active, ep);
+		else if (!strcmp(opt, "sign_fh"))
+			setflags(NFSEXP_SIGN_FH, active, ep);
 		else if (!strcmp(opt, "nohide"))
 			setflags(NFSEXP_NOHIDE, active, ep);
 		else if (!strcmp(opt, "hide"))
utils/exportfs/exportfs.c +2 -0
index 748c38e3e966..54ce62c5ce9a 100644
@@ -718,6 +718,8 @@ dump(int verbose, int export_format)
 				c = dumpopt(c, "nordirplus");
 			if (ep->e_flags & NFSEXP_SECURITY_LABEL)
 				c = dumpopt(c, "security_label");
+			if (ep->e_flags & NFSEXP_SIGN_FH)
+				c = dumpopt(c, "sign_fh");
 			if (ep->e_flags & NFSEXP_NOACL)
 				c = dumpopt(c, "no_acl");
 			if (ep->e_flags & NFSEXP_PNFS)
utils/exportfs/exports.man +9 -0
index efbc6ef65c5f..7f0278fb8d33 100644
@@ -351,6 +351,15 @@ file.  If you put neither option,
 .B exportfs
 will warn you that the change has occurred.
 
+.TP
+.IR sign_fh
+This option enforces signing filehandles on the export.  If the server has
+been configured with a secret key for such purpose, filehandles will include
+a hash to verify the filehandle was created by the server in order to guard
+against filehandle guessing attacks which can bypass path-name based access
+restrictions.  Note that for NFSv3 some exported filesystems may exceed the
+maximum filehandle size when the signing hash is added.
+
 .TP
 .IR insecure_locks
 .TP
Signature · 1 line
2.50.1
#2 lore raw

PATCH v6 2/2 nfsdctl/rpc.nfsd: Add support for passing encrypted filehandle key

In reply to Benjamin Coddington

If fh-key-file=<path> is set in the nfsd section of nfs.conf, the "nfsdctl autostart" command will hash the contents of the file with libuuid's uuid_generate_sha1 and send the first 16 bytes into the kernel on NFSD_A_SERVER_FH_KEY. A compatible kernel can use this key to sign filehandles.

Also add -k, --fh-key-file=<path> option to the "nfsdctl threads" command effecting the same result.

---
 nfs.conf                     |  1 +
 support/include/nfslib.h     |  2 +
 support/nfs/Makefile.am      |  4 +-
 support/nfs/fh_key_file.c    | 71 ++++++++++++++++++++++++++++++++++++
 systemd/nfs.conf.man         |  1 +
 utils/nfsd/nfssvc.h          |  1 +
 utils/nfsdctl/nfsd_netlink.h |  1 +
 utils/nfsdctl/nfsdctl.8      |  8 +++-
 utils/nfsdctl/nfsdctl.c      | 57 ++++++++++++++++++++++++++---
 9 files changed, 137 insertions(+), 9 deletions(-)
 create mode 100644 support/nfs/fh_key_file.c
nfs.conf +1 -0
index 3cca68c3530d..39068c19d7df 100644
@@ -76,6 +76,7 @@
 # vers4.2=y
 rdma=y
 rdma-port=20049
+# fh-key-file=/etc/nfs_fh.key
 
 [statd]
 # debug=0
support/include/nfslib.h +2 -0
index eff2a486307f..c8601a156cba 100644
@@ -22,6 +22,7 @@
 #include <paths.h>
 #include <rpcsvc/nfs_prot.h>
 #include <nfs/nfs.h>
+#include <uuid/uuid.h>
 #include "xlog.h"
 
 #ifndef _PATH_EXPORTS
@@ -132,6 +133,7 @@ struct rmtabent *	fgetrmtabent(FILE *fp, int log, long *pos);
 void			fputrmtabent(FILE *fp, struct rmtabent *xep, long *pos);
 void			fendrmtabent(FILE *fp);
 void			frewindrmtabent(FILE *fp);
+int				hash_fh_key_file(const char *fh_key_file, uuid_t hash);
 
 _Bool state_setup_basedir(const char *, const char *);
 int setup_state_path_names(const char *, const char *, const char *, const char *, struct state_paths *);
support/nfs/Makefile.am +2 -2
index 2e1577cc12df..775bccc6c5ea 100644
@@ -7,8 +7,8 @@ libnfs_la_SOURCES = exports.c rmtab.c xio.c rpcmisc.c rpcdispatch.c \
 		   xcommon.c wildmat.c mydaemon.c \
 		   rpc_socket.c getport.c \
 		   svc_socket.c cacheio.c closeall.c nfs_mntent.c \
-		   svc_create.c atomicio.c strlcat.c strlcpy.c
-libnfs_la_LIBADD = libnfsconf.la
+		   svc_create.c atomicio.c strlcat.c strlcpy.c fh_key_file.c
+libnfs_la_LIBADD = libnfsconf.la -luuid
 libnfs_la_CPPFLAGS = $(AM_CPPFLAGS) $(CPPFLAGS) -I$(top_srcdir)/support/reexport
 
 libnfsconf_la_SOURCES = conffile.c xlog.c
support/nfs/fh_key_file.c new file +71 -0

71 lines not on this page · raw message

systemd/nfs.conf.man +1 -0
index ecdc4fc90327..a6b5c907b457 100644
@@ -176,6 +176,7 @@ Recognized values:
 .BR vers4.1 ,
 .BR vers4.2 ,
 .BR rdma ,
+.BR fh-key-file ,
 
 Version and protocol values are Boolean values as described above,
 and are also used by
utils/nfsd/nfssvc.h +1 -0
index 4d53af1a8bc3..463110cac804 100644
@@ -30,3 +30,4 @@ void	nfssvc_setvers(unsigned int ctlbits, unsigned int minorvers4,
 		       unsigned int minorvers4set, int force4dot0);
 int	nfssvc_threads(int nrservs);
 void	nfssvc_get_minormask(unsigned int *mask);
+int nfssvc_setfh_key(const char *fh_key_file);
utils/nfsdctl/nfsd_netlink.h +1 -0
index e9efbc9e63d8..97c7447f4d14 100644
@@ -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)
utils/nfsdctl/nfsdctl.8 +7 -1
index a86ffe8e1f4d..1f526e77bebf 100644
@@ -159,6 +159,12 @@ These options are specific to the "threads" subcommand:
     kernel will start the minimum number and dynamically start and stop threads as
     needed. If the minimum is larger than the maximum, then dynamic threadis is
     disabled, and the maximum number is started.
+
+\-k, \-\-fh\-key\-file=
+    If set to the path of a file, use the first 128 bits of the sha1 hash
+    of the file's contents as the server's filehandle signing key.
+    Exports with the "sign_fh" export option will use this key to append an
+    a signature to guard against filehandle guessing attacks.
 .fam
 .fi
 .if n .RE
@@ -336,4 +342,4 @@ privileges.
 nfs.conf(5), rpc.nfsd(8), rpc.mountd(8), exports(5), exportfs(8), rpc.rquotad(8), nfsstat(8), netconfig(5)
 .SH "AUTHOR"
 .sp
-Jeff Layton
\ No newline at end of file
+Jeff Layton
utils/nfsdctl/nfsdctl.c +51 -6

140 lines not on this page · raw message

Signature · 1 line
2.50.1