Smack: setprocattr memory leak fix
authorCasey Schaufler <casey@schaufler-ca.com>
Wed, 22 Aug 2012 18:44:03 +0000 (11:44 -0700)
committerElena Reshetova <elena.reshetova@intel.com>
Fri, 19 Oct 2012 10:48:53 +0000 (13:48 +0300)
The data structure allocations being done in prepare_creds
are duplicated in smack_setprocattr. This results in the
structure allocated in prepare_creds being orphaned and
never freed. The duplicate code is removed from
smack_setprocattr.

Targeted for git://git.gitorious.org/smack-next/kernel.git

Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
security/smack/smack_lsm.c

index c14ea26..d3999f8 100644 (file)
@@ -2680,9 +2680,7 @@ static int smack_getprocattr(struct task_struct *p, char *name, char **value)
 static int smack_setprocattr(struct task_struct *p, char *name,
                             void *value, size_t size)
 {
-       int rc;
        struct task_smack *tsp;
-       struct task_smack *oldtsp;
        struct cred *new;
        char *newsmack;
 
@@ -2712,21 +2710,13 @@ static int smack_setprocattr(struct task_struct *p, char *name,
        if (newsmack == smack_known_web.smk_known)
                return -EPERM;
 
-       oldtsp = p->cred->security;
        new = prepare_creds();
        if (new == NULL)
                return -ENOMEM;
 
-       tsp = new_task_smack(newsmack, oldtsp->smk_forked, GFP_KERNEL);
-       if (tsp == NULL) {
-               kfree(new);
-               return -ENOMEM;
-       }
-       rc = smk_copy_rules(&tsp->smk_rules, &oldtsp->smk_rules, GFP_KERNEL);
-       if (rc != 0)
-               return rc;
+       tsp = new->security;
+       tsp->smk_task = newsmack;
 
-       new->security = tsp;
        commit_creds(new);
        return size;
 }