Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1371804 > unrolled thread

[PATCH 2/2] lkdtm: fix memory leak of base

Started bySudip Mukherjee <sudipm.mukherjee@gmail.com>
First post2016-04-05 19:20 +0200
Last post2016-04-07 00:50 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 2/2] lkdtm: fix memory leak of base Sudip Mukherjee <sudipm.mukherjee@gmail.com> - 2016-04-05 19:20 +0200
    Re: [PATCH 2/2] lkdtm: fix memory leak of base Kees Cook <keescook@chromium.org> - 2016-04-07 00:50 +0200

#1371804 — [PATCH 2/2] lkdtm: fix memory leak of base

FromSudip Mukherjee <sudipm.mukherjee@gmail.com>
Date2016-04-05 19:20 +0200
Subject[PATCH 2/2] lkdtm: fix memory leak of base
Message-ID<rkCNX-7ui-1@gated-at.bofh.it>
This case is supposed to read from a memory after it has been freed,
but we missed freeing base if the memory 'val' could not be allocated.

Signed-off-by: Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>
---
 drivers/misc/lkdtm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
index 2f0b022..5b3a63c 100644
--- a/drivers/misc/lkdtm.c
+++ b/drivers/misc/lkdtm.c
@@ -458,8 +458,10 @@ static void lkdtm_do_action(enum ctype which)
 			break;
 
 		val = kmalloc(len, GFP_KERNEL);
-		if (!val)
+		if (!val) {
+			kfree(base);
 			break;
+		}
 
 		*val = 0x12345678;
 		base[offset] = *val;
-- 
1.9.1

[toc] | [next] | [standalone]


#1372903

FromKees Cook <keescook@chromium.org>
Date2016-04-07 00:50 +0200
Message-ID<rl4qS-2rx-15@gated-at.bofh.it>
In reply to#1371804
On Tue, Apr 5, 2016 at 10:11 AM, Sudip Mukherjee
<sudipm.mukherjee@gmail.com> wrote:
> This case is supposed to read from a memory after it has been freed,
> but we missed freeing base if the memory 'val' could not be allocated.
>
> Signed-off-by: Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>

Also applied. Thanks!

-Kees

> ---
>  drivers/misc/lkdtm.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
> index 2f0b022..5b3a63c 100644
> --- a/drivers/misc/lkdtm.c
> +++ b/drivers/misc/lkdtm.c
> @@ -458,8 +458,10 @@ static void lkdtm_do_action(enum ctype which)
>                         break;
>
>                 val = kmalloc(len, GFP_KERNEL);
> -               if (!val)
> +               if (!val) {
> +                       kfree(base);
>                         break;
> +               }
>
>                 *val = 0x12345678;
>                 base[offset] = *val;
> --
> 1.9.1
>



-- 
Kees Cook
Chrome OS & Brillo Security

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web