knfsd: nfsd: enforce per-flavor id squashing
authorJ. Bruce Fields <bfields@citi.umich.edu>
Tue, 17 Jul 2007 11:04:52 +0000 (04:04 -0700)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Tue, 17 Jul 2007 17:23:08 +0000 (10:23 -0700)
Allow root squashing to vary per-pseudoflavor, so that you can (for example)
allow root access only when sufficiently strong security is in use.

Signed-off-by: "J. Bruce Fields" <bfields@citi.umich.edu>
Signed-off-by: Neil Brown <neilb@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/nfsd/auth.c
include/linux/nfsd/export.h

index 6e92b0fe5323483cd6ce3bd25fd6d5a211d9589b..cf61dc8ae942d664036ad0630b1713cd93435433 100644 (file)
 
 #define        CAP_NFSD_MASK (CAP_FS_MASK|CAP_TO_MASK(CAP_SYS_RESOURCE))
 
+static int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
+{
+       struct exp_flavor_info *f;
+       struct exp_flavor_info *end = exp->ex_flavors + exp->ex_nflavors;
+
+       for (f = exp->ex_flavors; f < end; f++) {
+               if (f->pseudoflavor == rqstp->rq_flavor)
+                       return f->flags;
+       }
+       return exp->ex_flags;
+
+}
+
 int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp)
 {
        struct svc_cred cred = rqstp->rq_cred;
        int i;
+       int flags = nfsexp_flags(rqstp, exp);
        int ret;
 
-       if (exp->ex_flags & NFSEXP_ALLSQUASH) {
+       if (flags & NFSEXP_ALLSQUASH) {
                cred.cr_uid = exp->ex_anon_uid;
                cred.cr_gid = exp->ex_anon_gid;
                cred.cr_group_info = groups_alloc(0);
-       } else if (exp->ex_flags & NFSEXP_ROOTSQUASH) {
+       } else if (flags & NFSEXP_ROOTSQUASH) {
                struct group_info *gi;
                if (!cred.cr_uid)
                        cred.cr_uid = exp->ex_anon_uid;
index a01f775cb9445fb9214c3aab87a4c5080b5c27b8..78feb7beff75a41c535a715887c80aeb16e8c88e 100644 (file)
@@ -43,7 +43,8 @@
 #define NFSEXP_ALLFLAGS                0xFE3F
 
 /* The flags that may vary depending on security flavor: */
-#define NFSEXP_SECINFO_FLAGS   0
+#define NFSEXP_SECINFO_FLAGS   (NFSEXP_READONLY | NFSEXP_ROOTSQUASH \
+                                       | NFSEXP_ALLSQUASH)
 
 #ifdef __KERNEL__