]> git.proxmox.com Git - mirror_spl.git/commitdiff
Fix splat-cred.c cred usage
authorChunwei Chen <david.chen@osnexus.com>
Wed, 19 Oct 2016 00:29:26 +0000 (17:29 -0700)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Thu, 20 Oct 2016 16:33:22 +0000 (09:33 -0700)
No need to crhold current_cred(), fix possible leak in splat_cred_test2

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Chunwei Chen <david.chen@osnexus.com>
Closes #556

module/splat/splat-cred.c

index fadf9bca0c7c724b176576d38572b31d757adaa9..e3d1c4eee061406aa4d587cefad8ff219e82d965 100644 (file)
@@ -53,18 +53,18 @@ splat_cred_test1(struct file *file, void *arg)
        uid_t uid, ruid, suid;
        gid_t gid, rgid, sgid, *groups;
        int ngroups, i, count = 0;
+       cred_t *cr = CRED();
 
-       uid  = crgetuid(CRED());
-       ruid = crgetruid(CRED());
-       suid = crgetsuid(CRED());
+       uid  = crgetuid(cr);
+       ruid = crgetruid(cr);
+       suid = crgetsuid(cr);
 
-       gid  = crgetgid(CRED());
-       rgid = crgetrgid(CRED());
-       sgid = crgetsgid(CRED());
+       gid  = crgetgid(cr);
+       rgid = crgetrgid(cr);
+       sgid = crgetsgid(cr);
 
-       crhold(CRED());
-       ngroups = crgetngroups(CRED());
-       groups  = crgetgroups(CRED());
+       ngroups = crgetngroups(cr);
+       groups = crgetgroups(cr);
 
        memset(str, 0, GROUP_STR_SIZE);
        for (i = 0; i < ngroups; i++) {
@@ -78,8 +78,6 @@ splat_cred_test1(struct file *file, void *arg)
                }
        }
 
-       crfree(CRED());
-
        splat_vprint(file, SPLAT_CRED_TEST1_NAME,
                     "uid: %d ruid: %d suid: %d "
                     "gid: %d rgid: %d sgid: %d\n",
@@ -114,6 +112,8 @@ splat_cred_test2(struct file *file, void *arg)
        gid_t gid, rgid, sgid, *groups;
        int ngroups, i, count = 0;
 
+       crhold(kcred);
+
        uid  = crgetuid(kcred);
        ruid = crgetruid(kcred);
        suid = crgetsuid(kcred);
@@ -122,7 +122,6 @@ splat_cred_test2(struct file *file, void *arg)
        rgid = crgetrgid(kcred);
        sgid = crgetsgid(kcred);
 
-       crhold(kcred);
        ngroups = crgetngroups(kcred);
        groups  = crgetgroups(kcred);
 
@@ -134,6 +133,7 @@ splat_cred_test2(struct file *file, void *arg)
                        splat_vprint(file, SPLAT_CRED_TEST2_NAME,
                                     "Failed too many group entries for temp "
                                     "buffer: %d, %s\n", ngroups, str);
+                       crfree(kcred);
                        return -ENOSPC;
                }
        }