linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selinux: fix possible memory leak
@ 2013-11-24 11:37 Geyslan G. Bem
  2013-11-25 22:02 ` Paul Moore
  0 siblings, 1 reply; 2+ messages in thread
From: Geyslan G. Bem @ 2013-11-24 11:37 UTC (permalink / raw)
  To: linux-kernel
  Cc: Geyslan G. Bem, Stephen Smalley, James Morris, Eric Paris,
	Paul Moore, open list:SECURITY SUBSYSTEM

Free 'ctx_str' when necessary.

Signed-off-by: Geyslan G. Bem <geyslan@gmail.com>
---
 security/selinux/xfrm.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/security/selinux/xfrm.c b/security/selinux/xfrm.c
index a91d205..cf79a45 100644
--- a/security/selinux/xfrm.c
+++ b/security/selinux/xfrm.c
@@ -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;
 }
 
 /*
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] selinux: fix possible memory leak
  2013-11-24 11:37 [PATCH] selinux: fix possible memory leak Geyslan G. Bem
@ 2013-11-25 22:02 ` Paul Moore
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Moore @ 2013-11-25 22:02 UTC (permalink / raw)
  To: Geyslan G. Bem
  Cc: linux-kernel, Stephen Smalley, James Morris, Eric Paris,
	linux-security-module, selinux

On Sunday, November 24, 2013 08:37:01 AM Geyslan G. Bem wrote:
> Free 'ctx_str' when necessary.
> 
> Signed-off-by: Geyslan G. Bem <geyslan@gmail.com>
> ---
>  security/selinux/xfrm.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)

Nice catch, applied.

> diff --git a/security/selinux/xfrm.c b/security/selinux/xfrm.c
> index a91d205..cf79a45 100644
> --- a/security/selinux/xfrm.c
> +++ b/security/selinux/xfrm.c
> @@ -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;
>  }
> 
>  /*

-- 
paul moore
www.paul-moore.com


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-11-25 22:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-24 11:37 [PATCH] selinux: fix possible memory leak Geyslan G. Bem
2013-11-25 22:02 ` Paul Moore

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).