Skip to contentSkip to conversation

rpc.mountd CVE-2025-12801 announcement

PATCH In review Steve Dickson 1 participant 6 messages Mar 5 – Mar 7

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover rpc.mountd CVE-2025-12801 announcement

Vulnerability discovered in rpc.mountd in the nfs-utils package

A vulnerability was recently discovered in the rpc.mountd daemon in the nfs-utils package for Linux, that allows a NFSv3 client to escalate the privileges assigned to it in the /etc/exports file at mount time. In particular, it allows the client to access any subdirectory or subtree of an exported directory, regardless of the set file permissions, and regardless of any 'root_squash' or 'all_squash' attributes that would normally be expected to apply to that client.

The vulnerability does affect all known instances of the Linux kernel NFS server exporting the NFSv2 and/or NFSv3 protocols. It does not affect those Linux kernel NFS servers that only export filesystems using the NFSv4 protocol.

This issue has been fixed in nfs-utils 2.8.6 and later, with an upgrade advised for all users.

Trond Myklebust (4):
mountd: Minor refactor of get_rootfh()
mountd: Separate lookup of the exported directory and the mount path
support: Add a mini-library to extract and apply RPC credentials Fix access checks when mounting subdirectories in NFSv3

 aclocal/libtirpc.m4         |  12 +++
 nfs.conf                    |   1 +
 support/include/Makefile.am |   1 +
 support/include/nfs_ucred.h |  44 ++++++++++
 support/include/nfsd_path.h |   8 ++
 support/misc/Makefile.am    |   2 +-
 support/misc/nfsd_path.c    |  59 +++++++++++++
 support/misc/ucred.c        | 162 ++++++++++++++++++++++++++++++++++++
 support/nfs/Makefile.am     |   2 +-
 support/nfs/ucred.c         | 147 ++++++++++++++++++++++++++++++++
 utils/mountd/mountd.c       | 111 +++++++++++++++++++-----
 utils/mountd/mountd.man     |  26 ++++++
 12 files changed, 552 insertions(+), 23 deletions(-)
 create mode 100644 support/include/nfs_ucred.h
 create mode 100644 support/misc/ucred.c
 create mode 100644 support/nfs/ucred.c
Signature · 1 line
2.53.0
#2 lore raw

PATCH 2/4 mountd: Separate lookup of the exported directory and the mount path

From: Trond Myklebust <[email protected]>

When the caller asks to mount a path that does not terminate with an exported directory, we want to split up the lookups so that we can look up the exported directory using the mountd privileged credential, and the remaining subdirectory lookups using the RPC caller's credential.

---
 support/include/nfsd_path.h |  1 +
 support/misc/nfsd_path.c    | 31 ++++++++++++++++++
 utils/mountd/mountd.c       | 63 +++++++++++++++++++++++++++++++------
 3 files changed, 86 insertions(+), 9 deletions(-)
support/include/nfsd_path.h +1 -0
index f600fb5a..3e5a2f5d 100644
@@ -18,6 +18,7 @@ char *		nfsd_path_prepend_dir(const char *dir, const char *pathname);
 
 int 		nfsd_path_stat(const char *pathname, struct stat *statbuf);
 int 		nfsd_path_lstat(const char *pathname, struct stat *statbuf);
+int		nfsd_openat(int dirfd, const char *path, int flags);
 
 int		nfsd_path_statfs(const char *pathname,
 				   struct statfs *statbuf);
support/misc/nfsd_path.c +31 -0
index caec33ca..dfe88e4f 100644
@@ -203,6 +203,37 @@ nfsd_realpath(const char *path, char *resolved_buf)
         return realpath_buf.res_ptr;
 }
 
+struct nfsd_openat_t {
+	const char *path;
+	int dirfd;
+	int flags;
+	int res_fd;
+	int res_error;
+};
+
+static void nfsd_openatfunc(void *data)
+{
+	struct nfsd_openat_t *d = data;
+
+	d->res_fd = openat(d->dirfd, d->path, d->flags);
+	if (d->res_fd == -1)
+		d->res_error = errno;
+}
+
+int nfsd_openat(int dirfd, const char *path, int flags)
+{
+	struct nfsd_openat_t open_buf = {
+		.path = path,
+		.dirfd = dirfd,
+		.flags = flags,
+	};
+
+	nfsd_run_task(nfsd_openatfunc, &open_buf);
+	if (open_buf.res_fd == -1)
+		errno = open_buf.res_error;
+	return open_buf.res_fd;
+}
+
 struct nfsd_rw_data {
 	int             fd;
 	void*           buf;
utils/mountd/mountd.c +54 -9

91 lines not on this page · raw message

Signature · 1 line
2.53.0
#1 lore raw

PATCH 1/4 mountd: Minor refactor of get_rootfh()

In reply to Steve Dickson

From: Trond Myklebust <[email protected]>

Perform the mountpoint checks before checking the user path.

---
 utils/mountd/mountd.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)
utils/mountd/mountd.c +17 -17
index dbd5546d..39afd4aa 100644
@@ -412,6 +412,23 @@ get_rootfh(struct svc_req *rqstp, dirpath *path, nfs_export **expret,
 		*error = MNT3ERR_ACCES;
 		return NULL;
 	}
+	if (nfsd_path_stat(exp->m_export.e_path, &estb) < 0) {
+		xlog(L_WARNING, "can't stat export point %s: %s",
+		     p, strerror(errno));
+		*error = MNT3ERR_NOENT;
+		return NULL;
+	}
+	if (exp->m_export.e_mountpoint &&
+		   !check_is_mountpoint(exp->m_export.e_mountpoint[0]?
+				  exp->m_export.e_mountpoint:
+				  exp->m_export.e_path,
+				  nfsd_path_lstat)) {
+		xlog(L_WARNING, "request to export an unmounted filesystem: %s",
+		     p);
+		*error = MNT3ERR_NOENT;
+		return NULL;
+	}
+
 	if (nfsd_path_stat(p, &stb) < 0) {
 		xlog(L_WARNING, "can't stat exported dir %s: %s",
 				p, strerror(errno));
@@ -426,12 +443,6 @@ get_rootfh(struct svc_req *rqstp, dirpath *path, nfs_export **expret,
 		*error = MNT3ERR_NOTDIR;
 		return NULL;
 	}
-	if (nfsd_path_stat(exp->m_export.e_path, &estb) < 0) {
-		xlog(L_WARNING, "can't stat export point %s: %s",
-		     p, strerror(errno));
-		*error = MNT3ERR_NOENT;
-		return NULL;
-	}
 	if (estb.st_dev != stb.st_dev
 	    && !(exp->m_export.e_flags & NFSEXP_CROSSMOUNT)) {
 		xlog(L_WARNING, "request to export directory %s below nearest filesystem %s",
@@ -439,17 +450,6 @@ get_rootfh(struct svc_req *rqstp, dirpath *path, nfs_export **expret,
 		*error = MNT3ERR_ACCES;
 		return NULL;
 	}
-	if (exp->m_export.e_mountpoint &&
-		   !check_is_mountpoint(exp->m_export.e_mountpoint[0]?
-				  exp->m_export.e_mountpoint:
-				  exp->m_export.e_path,
-				  nfsd_path_lstat)) {
-		xlog(L_WARNING, "request to export an unmounted filesystem: %s",
-		     p);
-		*error = MNT3ERR_NOENT;
-		return NULL;
-	}
-
 	/* This will be a static private nfs_export with just one
 	 * address.  We feed it to kernel then extract the filehandle,
 	 */
Signature · 1 line
2.53.0
#3 lore raw

PATCH 3/4 support: Add a mini-library to extract and apply RPC credentials

In reply to Steve Dickson

From: Trond Myklebust <[email protected]>

Add server functionality to extract the credentials from the client RPC call, and apply them. This is needed in order to perform access checking on the requested path in the mountd daemon.

---
 aclocal/libtirpc.m4         |  12 +++
 support/include/Makefile.am |   1 +
 support/include/nfs_ucred.h |  44 ++++++++++
 support/misc/Makefile.am    |   2 +-
 support/misc/ucred.c        | 162 ++++++++++++++++++++++++++++++++++++
 support/nfs/Makefile.am     |   2 +-
 support/nfs/ucred.c         | 147 ++++++++++++++++++++++++++++++++
 7 files changed, 368 insertions(+), 2 deletions(-)
 create mode 100644 support/include/nfs_ucred.h
 create mode 100644 support/misc/ucred.c
 create mode 100644 support/nfs/ucred.c
aclocal/libtirpc.m4 +12 -0
index ef48a2ae..06629db9 100644
@@ -31,6 +31,18 @@ AC_DEFUN([AC_LIBTIRPC], [
                          [AC_DEFINE([HAVE_TIRPC_GSS_SECCREATE], [1],
                                     [Define to 1 if your tirpc library provides rpc_gss_seccreate])],,
                          [${LIBS}])])
+
+     AS_IF([test -n "${LIBTIRPC}"],
+           [AC_CHECK_LIB([tirpc], [rpc_gss_getcred],
+                         [AC_DEFINE([HAVE_TIRPC_GSS_GETCRED], [1],
+                                    [Define to 1 if your tirpc library provides rpc_gss_getcred])],,
+                         [${LIBS}])])
+
+     AS_IF([test -n "${LIBTIRPC}"],
+           [AC_CHECK_LIB([tirpc], [authdes_getucred],
+                         [AC_DEFINE([HAVE_TIRPC_AUTHDES_GETUCRED], [1],
+                                    [Define to 1 if your tirpc library provides authdes_getucred])],,
+                         [${LIBS}])])
   AC_SUBST([AM_CPPFLAGS])
   AC_SUBST(LIBTIRPC)
 
support/include/Makefile.am +1 -0
index 1373891a..631a84f8 100644
@@ -10,6 +10,7 @@ noinst_HEADERS = \
 	misc.h \
 	nfs_mntent.h \
 	nfs_paths.h \
+	nfs_ucred.h \
 	nfsd_path.h \
 	nfslib.h \
 	nfsrpc.h \
support/include/nfs_ucred.h new file +44 -0

44 lines not on this page · raw message

support/misc/Makefile.am +1 -1
index f9993e3a..7ea2d798 100644
@@ -2,6 +2,6 @@
 
 noinst_LIBRARIES = libmisc.a
 libmisc_a_SOURCES = tcpwrapper.c from_local.c mountpoint.c file.c \
-		    nfsd_path.c workqueue.c xstat.c
+		    nfsd_path.c ucred.c workqueue.c xstat.c
 
 MAINTAINERCLEANFILES = Makefile.in
support/misc/ucred.c new file +162 -0

162 lines not on this page · raw message

support/nfs/Makefile.am +1 -1
index 2e1577cc..f6921265 100644
@@ -7,7 +7,7 @@ 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
+		   svc_create.c atomicio.c strlcat.c strlcpy.c ucred.c
 libnfs_la_LIBADD = libnfsconf.la
 libnfs_la_CPPFLAGS = $(AM_CPPFLAGS) $(CPPFLAGS) -I$(top_srcdir)/support/reexport
 
support/nfs/ucred.c new file +147 -0

147 lines not on this page · raw message

Signature · 1 line
2.53.0
#4 lore raw

PATCH 4/4 Fix access checks when mounting subdirectories in NFSv3

In reply to Steve Dickson

From: Trond Myklebust <[email protected]>

If a NFSv3 client asks to mount a subdirectory of one of the exported directories, then apply the RPC credential together with any root or all squash rules that would apply to the client in question.

---
 nfs.conf                    |  1 +
 support/include/nfsd_path.h |  9 ++++++++-
 support/misc/nfsd_path.c    | 32 ++++++++++++++++++++++++++++++--
 utils/mountd/mountd.c       | 28 ++++++++++++++++++++++++++--
 utils/mountd/mountd.man     | 26 ++++++++++++++++++++++++++
 5 files changed, 91 insertions(+), 5 deletions(-)
nfs.conf +1 -0
index 3cca68c3..ddf0c143 100644
@@ -46,6 +46,7 @@
 # ttl=1800
 [mountd]
 # debug="all|auth|call|general|parse"
+# apply-root-cred=n
 # manage-gids=n
 # descriptors=0
 # port=0
support/include/nfsd_path.h +8 -1
index 3e5a2f5d..06c0f2f4 100644
@@ -9,6 +9,7 @@
 struct file_handle;
 struct statfs;
 struct nfsd_task_t;
+struct nfs_ucred;
 
 void 		nfsd_path_init(void);
 
@@ -18,7 +19,8 @@ char *		nfsd_path_prepend_dir(const char *dir, const char *pathname);
 
 int 		nfsd_path_stat(const char *pathname, struct stat *statbuf);
 int 		nfsd_path_lstat(const char *pathname, struct stat *statbuf);
-int		nfsd_openat(int dirfd, const char *path, int flags);
+int		nfsd_cred_openat(const struct nfs_ucred *cred, int dirfd,
+				 const char *path, int flags);
 
 int		nfsd_path_statfs(const char *pathname,
 				   struct statfs *statbuf);
@@ -31,4 +33,9 @@ ssize_t		nfsd_path_write(int fd, void* buf, size_t len);
 int		nfsd_name_to_handle_at(int fd, const char *path,
 				       struct file_handle *fh,
 				       int *mount_id, int flags);
+
+static inline int nfsd_openat(int dirfd, const char *path, int flags)
+{
+	return nfsd_cred_openat(NULL, dirfd, path, flags);
+}
 #endif
support/misc/nfsd_path.c +30 -2
index dfe88e4f..6466666d 100644
@@ -17,6 +17,7 @@
 #include "xstat.h"
 #include "nfslib.h"
 #include "nfsd_path.h"
+#include "nfs_ucred.h"
 #include "workqueue.h"
 
 static struct xthread_workqueue *nfsd_wq = NULL;
@@ -204,6 +205,7 @@ nfsd_realpath(const char *path, char *resolved_buf)
 }
 
 struct nfsd_openat_t {
+	const struct nfs_ucred *cred;
 	const char *path;
 	int dirfd;
 	int flags;
@@ -220,15 +222,41 @@ static void nfsd_openatfunc(void *data)
 		d->res_error = errno;
 }
 
-int nfsd_openat(int dirfd, const char *path, int flags)
+static void nfsd_cred_openatfunc(void *data)
+{
+	struct nfsd_openat_t *d = data;
+	struct nfs_ucred *saved = NULL;
+	int ret;
+
+	ret = nfs_ucred_swap_effective(d->cred, &saved);
+	if (ret != 0) {
+		d->res_fd = -1;
+		d->res_error = ret;
+		return;
+	}
+
+	nfsd_openatfunc(data);
+
+	if (saved != NULL) {
+		nfs_ucred_swap_effective(saved, NULL);
+		nfs_ucred_free(saved);
+	}
+}
+
+int nfsd_cred_openat(const struct nfs_ucred *cred, int dirfd, const char *path,
+		     int flags)
 {
 	struct nfsd_openat_t open_buf = {
+		.cred = cred,
 		.path = path,
 		.dirfd = dirfd,
 		.flags = flags,
 	};
 
-	nfsd_run_task(nfsd_openatfunc, &open_buf);
+	if (cred)
+		nfsd_run_task(nfsd_cred_openatfunc, &open_buf);
+	else
+		nfsd_run_task(nfsd_openatfunc, &open_buf);
 	if (open_buf.res_fd == -1)
 		errno = open_buf.res_error;
 	return open_buf.res_fd;
utils/mountd/mountd.c +26 -2
index f43ebef5..6e6777cd 100644
@@ -31,6 +31,7 @@
 #include "nfsd_path.h"
 #include "nfslib.h"
 #include "export.h"
+#include "nfs_ucred.h"
 
 extern void my_svc_run(void);
 
@@ -40,6 +41,7 @@ static struct nfs_fh_len *get_rootfh(struct svc_req *, dirpath *, nfs_export **,
 
 int reverse_resolve = 0;
 int manage_gids;
+int apply_root_cred;
 int use_ipaddr = -1;
 
 /* PRC: a high-availability callout program can be specified with -H
@@ -74,9 +76,10 @@ static struct option longopts[] =
 	{ "log-auth", 0, 0, 'l'},
 	{ "cache-use-ipaddr", 0, 0, 'i'},
 	{ "ttl", 1, 0, 'T'},
+	{ "apply-root-cred", 0, 0, 'c' },
 	{ NULL, 0, 0, 0 }
 };
-static char shortopts[] = "o:nFd:p:P:hH:N:V:vurs:t:gliT:";
+static char shortopts[] = "o:nFd:p:P:hH:N:V:vurs:t:gliT:c";
 
 #define NFSVERSBIT(vers)	(0x1 << (vers - 1))
 #define NFSVERSBIT_ALL		(NFSVERSBIT(2) | NFSVERSBIT(3) | NFSVERSBIT(4))
@@ -453,11 +456,27 @@ get_rootfh(struct svc_req *rqstp, dirpath *path, nfs_export **expret,
 	while (*subpath == '/')
 		subpath++;
 	if (*subpath != '\0') {
+		struct nfs_ucred *cred = NULL;
 		int fd;
 
+		/* Load the user cred */
+		if (!apply_root_cred) {
+			nfs_ucred_get(&cred, rqstp, &exp->m_export);
+			if (cred == NULL) {
+				xlog(L_WARNING, "can't retrieve credential");
+				*error = MNT3ERR_ACCES;
+				close(dirfd);
+				return NULL;
+			}
+			if (manage_gids)
+				nfs_ucred_reload_groups(cred, &exp->m_export);
+		}
+
 		/* Just perform a lookup of the path */
-		fd = nfsd_openat(dirfd, subpath, O_PATH);
+		fd = nfsd_cred_openat(cred, dirfd, subpath, O_PATH);
 		close(dirfd);
+		if (cred)
+			nfs_ucred_free(cred);
 		if (fd == -1) {
 			xlog(L_WARNING, "can't open exported dir %s: %s", p,
 			     strerror(errno));
@@ -681,6 +700,8 @@ read_mountd_conf(char **argv)
 	ttl = conf_get_num("mountd", "ttl", default_ttl);
 	if (ttl > 0)
 		default_ttl = ttl;
+	apply_root_cred = conf_get_bool("mountd", "apply-root-cred",
+					apply_root_cred);
 }
 
 int
@@ -794,6 +815,9 @@ main(int argc, char **argv)
 			}
 			default_ttl = ttl;
 			break;
+		case 'c':
+			apply_root_cred = 1;
+			break;
 		case 0:
 			break;
 		case '?':
utils/mountd/mountd.man +26 -0
index a206a3e2..f4f1fc23 100644
@@ -242,6 +242,32 @@ can support both NFS version 2 and the newer version 3.
 Print the version of
 .B rpc.mountd
 and exit.
+.TP
+.B \-c " or " \-\-apply-root-cred
+When mountd is asked to allow a NFSv3 mount to a subdirectory of the
+exported directory, then it will check if the user asking to mount has
+lookup rights to the directories below that exported directory. When
+performing the check, mountd will apply any root squash or all squash
+rules that were specified for that client.
+
+Performing lookup checks as the user requires that the mountd daemon
+be run as root or that it be given CAP_SETUID and CAP_SETGID privileges
+so that it can change its own effective user and effective group settings.
+When troubleshooting, please also note that LSM frameworks such as SELinux
+can sometimes prevent the daemon from changing the effective user/groups
+despite the capability settings.
+
+In earlier versions of mountd, the same checks were performed using the
+mountd daemon's root privileges, meaning that it could authorise access
+to directories that are not normally accessible to the user requesting
+to mount them. This option enables that legacy behaviour.
+
+.BR Note:
+If there is a need to provide access to specific subdirectories that
+are not normally accessible to a client, it is always possible to add
+export entries that explicitly grant such access. That ability does
+not depend on this option being enabled.
+
 .TP
 .B \-g " or " \-\-manage-gids
 Accept requests from the kernel to map user id numbers into  lists of
Signature · 1 line
2.53.0
#5 lore raw
In reply to Steve Dickson
Quoted 37 lines · Steve Dickson

Vulnerability discovered in rpc.mountd in the nfs-utils package

A vulnerability was recently discovered in the rpc.mountd daemon in the nfs-utils package for Linux, that allows a NFSv3 client to escalate the privileges assigned to it in the /etc/exports file at mount time. In particular, it allows the client to access any subdirectory or subtree of an exported directory, regardless of the set file permissions, and regardless of any 'root_squash' or 'all_squash' attributes that would normally be expected to apply to that client.

The vulnerability does affect all known instances of the Linux kernel NFS server exporting the NFSv2 and/or NFSv3 protocols. It does not affect those Linux kernel NFS servers that only export filesystems using the NFSv4 protocol.

This issue has been fixed in nfs-utils 2.8.6 and later, with an upgrade advised for all users.

Trond Myklebust (4):
mountd: Minor refactor of get_rootfh()
mountd: Separate lookup of the exported directory and the mount path
support: Add a mini-library to extract and apply RPC credentials Fix access checks when mounting subdirectories in NFSv3

  aclocal/libtirpc.m4         |  12 +++
  nfs.conf                    |   1 +
  support/include/Makefile.am |   1 +
  support/include/nfs_ucred.h |  44 ++++++++++
  support/include/nfsd_path.h |   8 ++
  support/misc/Makefile.am    |   2 +-
  support/misc/nfsd_path.c    |  59 +++++++++++++
  support/misc/ucred.c        | 162 ++++++++++++++++++++++++++++++++++++
  support/nfs/Makefile.am     |   2 +-
  support/nfs/ucred.c         | 147 ++++++++++++++++++++++++++++++++
  utils/mountd/mountd.c       | 111 +++++++++++++++++++-----
  utils/mountd/mountd.man     |  26 ++++++
  12 files changed, 552 insertions(+), 23 deletions(-)
Quoted 4 lines

create mode 100644 support/include/nfs_ucred.h
create mode 100644 support/misc/ucred.c
create mode 100644 support/nfs/ucred.c

Committed... (tag: nfs-utils-2-8-6-rc5)

steved.