Skip to content

Commit 46a2f3b

Browse files
committed
Smack: setprocattr memory leak fix
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 <[email protected]>
1 parent 449543b commit 46a2f3b

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

security/smack/smack_lsm.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2684,9 +2684,7 @@ static int smack_getprocattr(struct task_struct *p, char *name, char **value)
26842684
static int smack_setprocattr(struct task_struct *p, char *name,
26852685
void *value, size_t size)
26862686
{
2687-
int rc;
26882687
struct task_smack *tsp;
2689-
struct task_smack *oldtsp;
26902688
struct cred *new;
26912689
char *newsmack;
26922690

@@ -2716,21 +2714,13 @@ static int smack_setprocattr(struct task_struct *p, char *name,
27162714
if (newsmack == smack_known_web.smk_known)
27172715
return -EPERM;
27182716

2719-
oldtsp = p->cred->security;
27202717
new = prepare_creds();
27212718
if (new == NULL)
27222719
return -ENOMEM;
27232720

2724-
tsp = new_task_smack(newsmack, oldtsp->smk_forked, GFP_KERNEL);
2725-
if (tsp == NULL) {
2726-
kfree(new);
2727-
return -ENOMEM;
2728-
}
2729-
rc = smk_copy_rules(&tsp->smk_rules, &oldtsp->smk_rules, GFP_KERNEL);
2730-
if (rc != 0)
2731-
return rc;
2721+
tsp = new->security;
2722+
tsp->smk_task = newsmack;
27322723

2733-
new->security = tsp;
27342724
commit_creds(new);
27352725
return size;
27362726
}

0 commit comments

Comments
 (0)