Blame SOURCES/nfs-utils-1.3.0-mountd-v4root-sec.patch

e19a30
commit 4a1ad4aa3028d26d830d9a9003ff9e3337b0e0d5
e19a30
Author: Scott Mayhew <smayhew@redhat.com>
e19a30
Date:   Thu Apr 2 11:15:15 2015 -0400
e19a30
e19a30
    mountd: Enable all auth flavors on pseudofs exports
e19a30
    
e19a30
    With the current mountd code it's possible to craft exports in such a
e19a30
    manner that clients will be unable to mount exports that they *should*
e19a30
    be able to mount.
e19a30
    
e19a30
    Consider the following example:
e19a30
    
e19a30
    /foo	*(rw,insecure,no_root_squash,sec=krb5p)
e19a30
    /bar	client.example.com(rw,insecure,no_root_squash)
e19a30
    
e19a30
    Initially, client.example.com will be able to mount the /foo export
e19a30
    using sec=krb5p, but attempts to mount /bar using sec=sys will return
e19a30
    EPERM.  Once the nfsd.export cache entry expires, client.example.com
e19a30
    will then be able to mount /bar using sec=sys but attempts to mount /foo
e19a30
    using sec=krb5p will return EPERM.
e19a30
    
e19a30
    The reason this happens is because the initial nfsd.export cache entry
e19a30
    is actually pre-populated by nfsd_fh(), which is the handler for the
e19a30
    nfsd.fh cache, while later cache requests (once the initial entry
e19a30
    expires) are handled by nfsd_export().  These functions have slightly
e19a30
    different logic in how they select a v4root export from the cache --
e19a30
    nfsd_fh() takes last matching v4root export it finds, while
e19a30
    nfsd_export() (actually lookup_export()) takes the first.  Either way
e19a30
    it's wrong because the client should be able to mount both exports.
e19a30
    
e19a30
    Both rfc3503bis and rfc5661 say:
e19a30
    
e19a30
       A common and convenient practice, unless strong security requirements
e19a30
       dictate otherwise, is to make the entire pseudo file system
e19a30
       accessible by all of the valid security mechanisms.
e19a30
    
e19a30
    ...so lets do that.
e19a30
    
e19a30
    Acked-by: J. Bruce Fields <bfields@fieldses.org>
e19a30
    Signed-off-by: Scott Mayhew <smayhew@redhat.com>
e19a30
    Signed-off-by: Steve Dickson <steved@redhat.com>
e19a30
e19a30
diff --git a/utils/mountd/v4root.c b/utils/mountd/v4root.c
e19a30
index 34d098a..429ebb8 100644
e19a30
--- a/utils/mountd/v4root.c
e19a30
+++ b/utils/mountd/v4root.c
e19a30
@@ -26,6 +26,7 @@
e19a30
 #include "nfslib.h"
e19a30
 #include "misc.h"
e19a30
 #include "v4root.h"
e19a30
+#include "pseudoflavors.h"
e19a30
 
e19a30
 int v4root_needed;
e19a30
 
e19a30
@@ -56,22 +57,22 @@ static nfs_export pseudo_root = {
e19a30
 };
e19a30
 
e19a30
 static void
e19a30
-set_pseudofs_security(struct exportent *pseudo, struct exportent *source)
e19a30
+set_pseudofs_security(struct exportent *pseudo, int flags)
e19a30
 {
e19a30
-	struct sec_entry *se;
e19a30
+	struct flav_info *flav;
e19a30
 	int i;
e19a30
 
e19a30
-	if (source->e_flags & NFSEXP_INSECURE_PORT)
e19a30
+	if (flags & NFSEXP_INSECURE_PORT)
e19a30
 		pseudo->e_flags |= NFSEXP_INSECURE_PORT;
e19a30
-	if ((source->e_flags & NFSEXP_ROOTSQUASH) == 0)
e19a30
+	if ((flags & NFSEXP_ROOTSQUASH) == 0)
e19a30
 		pseudo->e_flags &= ~NFSEXP_ROOTSQUASH;
e19a30
-	for (se = source->e_secinfo; se->flav; se++) {
e19a30
+	for (flav = flav_map; flav < flav_map + flav_map_size; flav++) {
e19a30
 		struct sec_entry *new;
e19a30
 
e19a30
-		i = secinfo_addflavor(se->flav, pseudo);
e19a30
+		i = secinfo_addflavor(flav, pseudo);
e19a30
 		new = &pseudo->e_secinfo[i];
e19a30
 
e19a30
-		if (se->flags & NFSEXP_INSECURE_PORT)
e19a30
+		if (flags & NFSEXP_INSECURE_PORT)
e19a30
 			new->flags |= NFSEXP_INSECURE_PORT;
e19a30
 	}
e19a30
 }
e19a30
@@ -91,7 +92,7 @@ v4root_create(char *path, nfs_export *export)
e19a30
 	strncpy(eep.e_path, path, sizeof(eep.e_path));
e19a30
 	if (strcmp(path, "/") != 0)
e19a30
 		eep.e_flags &= ~NFSEXP_FSID;
e19a30
-	set_pseudofs_security(&eep, curexp);
e19a30
+	set_pseudofs_security(&eep, curexp->e_flags);
e19a30
 	exp = export_create(&eep, 0);
e19a30
 	if (exp == NULL)
e19a30
 		return NULL;
e19a30
@@ -139,7 +140,7 @@ pseudofs_update(char *hostname, char *path, nfs_export *source)
e19a30
 		return 0;
e19a30
 	}
e19a30
 	/* Update an existing V4ROOT export: */
e19a30
-	set_pseudofs_security(&exp->m_export, &source->m_export);
e19a30
+	set_pseudofs_security(&exp->m_export, source->m_export.e_flags);
e19a30
 	return 0;
e19a30
 }
e19a30