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

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