NFS: Reduce stack footprint of nfs_setattr()
[safe/jmp/linux-2.6] / fs / nfsd / auth.c
index 836ffa1..79717a4 100644 (file)
@@ -1,15 +1,7 @@
-/*
- * linux/fs/nfsd/auth.c
- *
- * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
- */
+/* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
 
-#include <linux/types.h>
 #include <linux/sched.h>
-#include <linux/sunrpc/svc.h>
-#include <linux/sunrpc/svcauth.h>
-#include <linux/nfsd/nfsd.h>
-#include <linux/nfsd/export.h>
+#include "nfsd.h"
 #include "auth.h"
 
 int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
@@ -34,6 +26,10 @@ int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp)
        int flags = nfsexp_flags(rqstp, exp);
        int ret;
 
+       validate_process_creds();
+
+       /* discard any old override before preparing the new set */
+       revert_creds(get_cred(current->real_cred));
        new = prepare_creds();
        if (!new)
                return -ENOMEM;
@@ -47,6 +43,8 @@ int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp)
                new->fsuid = exp->ex_anon_uid;
                new->fsgid = exp->ex_anon_gid;
                gi = groups_alloc(0);
+               if (!gi)
+                       goto oom;
        } else if (flags & NFSEXP_ROOTSQUASH) {
                if (!new->fsuid)
                        new->fsuid = exp->ex_anon_uid;
@@ -74,15 +72,19 @@ int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp)
 
        ret = set_groups(new, gi);
        put_group_info(gi);
-       if (!ret)
+       if (ret < 0)
                goto error;
 
-       if (new->uid)
+       if (new->fsuid)
                new->cap_effective = cap_drop_nfsd_set(new->cap_effective);
        else
                new->cap_effective = cap_raise_nfsd_set(new->cap_effective,
                                                        new->cap_permitted);
-       return commit_creds(new);
+       validate_process_creds();
+       put_cred(override_creds(new));
+       put_cred(new);
+       validate_process_creds();
+       return 0;
 
 oom:
        ret = -ENOMEM;