Skip to content

Commit 0af9016

Browse files
geyslanpcmoore
authored andcommitted
selinux: fix possible memory leak
Free 'ctx_str' when necessary. Signed-off-by: Geyslan G. Bem <geyslan@gmail.com> Signed-off-by: Paul Moore <pmoore@redhat.com>
1 parent dd0a118 commit 0af9016

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

‎security/selinux/xfrm.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,19 +327,22 @@ int selinux_xfrm_state_alloc_acquire(struct xfrm_state *x,
327327
return rc;
328328

329329
ctx = kmalloc(sizeof(*ctx) + str_len, GFP_ATOMIC);
330-
if (!ctx)
331-
return -ENOMEM;
330+
if (!ctx) {
331+
rc = -ENOMEM;
332+
goto out;
333+
}
332334

333335
ctx->ctx_doi = XFRM_SC_DOI_LSM;
334336
ctx->ctx_alg = XFRM_SC_ALG_SELINUX;
335337
ctx->ctx_sid = secid;
336338
ctx->ctx_len = str_len;
337339
memcpy(ctx->ctx_str, ctx_str, str_len);
338-
kfree(ctx_str);
339340

340341
x->security = ctx;
341342
atomic_inc(&selinux_xfrm_refcount);
342-
return 0;
343+
out:
344+
kfree(ctx_str);
345+
return rc;
343346
}
344347

345348
/*

0 commit comments

Comments
 (0)