Browse Source

lkdtm: fix memory leak of base

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>
Sudip Mukherjee 9 years ago
parent
commit
d2e10088ce
1 changed files with 3 additions and 1 deletions
  1. 3 1
      drivers/misc/lkdtm.c

+ 3 - 1
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;