Skip to content

Commit

Permalink
selinux: fix possible memory leak
Browse files Browse the repository at this point in the history
Free 'ctx_str' when necessary.

Signed-off-by: Geyslan G. Bem <[email protected]>
Signed-off-by: Paul Moore <[email protected]>
  • Loading branch information
geyslan authored and pcmoore committed Dec 4, 2013
1 parent dd0a118 commit 0af9016
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions security/selinux/xfrm.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,19 +327,22 @@ int selinux_xfrm_state_alloc_acquire(struct xfrm_state *x,
return rc;

ctx = kmalloc(sizeof(*ctx) + str_len, GFP_ATOMIC);
if (!ctx)
return -ENOMEM;
if (!ctx) {
rc = -ENOMEM;
goto out;
}

ctx->ctx_doi = XFRM_SC_DOI_LSM;
ctx->ctx_alg = XFRM_SC_ALG_SELINUX;
ctx->ctx_sid = secid;
ctx->ctx_len = str_len;
memcpy(ctx->ctx_str, ctx_str, str_len);
kfree(ctx_str);

x->security = ctx;
atomic_inc(&selinux_xfrm_refcount);
return 0;
out:
kfree(ctx_str);
return rc;
}

/*
Expand Down

0 comments on commit 0af9016

Please sign in to comment.