lkdtm: fix memory leak of base
authorSudip Mukherjee <sudipm.mukherjee@gmail.com>
Tue, 5 Apr 2016 17:11:06 +0000 (22:41 +0530)
committerKees Cook <keescook@chromium.org>
Wed, 6 Apr 2016 23:22:24 +0000 (16:22 -0700)
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>
Signed-off-by: Kees Cook <keescook@chromium.org>
drivers/misc/lkdtm.c

index 2f0b022..5b3a63c 100644 (file)
@@ -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;