Skip to contentSkip to conversation

lib: test_overflow: Avoid taining the kernel and fix wrap size

PATCH Superseded Kees Cook 2 participants 3 messages May 28, 2019 – May 29, 2019 Library code

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 lib: test_overflow: Avoid taining the kernel and fix wrap size

This adds __GFP_NOWARN to the kmalloc()-portions of the overflow test to avoid tainting the kernel. Additionally fixes up the math on wrap size to be architecture and page size agnostic.

Fixes ca90800a91ba ("test_overflow: Add memory allocation overflow tests")
---
 lib/test_overflow.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
lib/test_overflow.c +6 -5
index fc680562d8b6..4b05143eb538 100644
@@ -486,16 +486,17 @@ static int __init test_overflow_shift(void)
  * Deal with the various forms of allocator arguments. See comments above
  * the DEFINE_TEST_ALLOC() instances for mapping of the "bits".
  */
-#define alloc010(alloc, arg, sz) alloc(sz, GFP_KERNEL)
-#define alloc011(alloc, arg, sz) alloc(sz, GFP_KERNEL, NUMA_NO_NODE)
+#define alloc_GFP		 (GFP_KERNEL | __GFP_NOWARN)
+#define alloc010(alloc, arg, sz) alloc(sz, alloc_GFP)
+#define alloc011(alloc, arg, sz) alloc(sz, alloc_GFP, NUMA_NO_NODE)
 #define alloc000(alloc, arg, sz) alloc(sz)
 #define alloc001(alloc, arg, sz) alloc(sz, NUMA_NO_NODE)
-#define alloc110(alloc, arg, sz) alloc(arg, sz, GFP_KERNEL)
+#define alloc110(alloc, arg, sz) alloc(arg, sz, alloc_GFP | __GFP_NOWARN)
 #define free0(free, arg, ptr)	 free(ptr)
 #define free1(free, arg, ptr)	 free(arg, ptr)
 
-/* Wrap around to 8K */
-#define TEST_SIZE		(9 << PAGE_SHIFT)
+/* Wrap around to 16K */
+#define TEST_SIZE		(5 * 4096)
 
 #define DEFINE_TEST_ALLOC(func, free_func, want_arg, want_gfp, want_node)\
 static int __init test_ ## func (void *arg)				\
Signature · 5 lines
2.17.1


-- 
Kees Cook
#1 lore raw
Quoted 3 lines · Kees Cook

This adds __GFP_NOWARN to the kmalloc()-portions of the overflow test to avoid tainting the kernel. Additionally fixes up the math on wrap size to be architecture and page size agnostic.

[]

lib/test_overflow.c

Quoted 1 line
lib/test_overflow.c +0 -0

[]

lib/test_overflow.c static int __init test_overflow_shift(void)

Quoted 1 line
lib/test_overflow.c +0 -0
@@ -486,16 +486,17 @@ static int __init test_overflow_shift(void)

[]

lib/test_overflow.c static int __init test_overflow_shift(void) · line 489

Quoted 1 line
lib/test_overflow.c +1 -0
+#define alloc_GFP		 (GFP_KERNEL | __GFP_NOWARN)

[]

lib/test_overflow.c static int __init test_overflow_shift(void) · line 494

Quoted 1 line
lib/test_overflow.c +1 -0
+#define alloc110(alloc, arg, sz) alloc(arg, sz, alloc_GFP | __GFP_NOWARN)

seems redundant.

author
#2 lore raw
Quoted 7 lines · Joe Perches
Quoted 3 lines · Kees Cook

This adds __GFP_NOWARN to the kmalloc()-portions of the overflow test to avoid tainting the kernel. Additionally fixes up the math on wrap size to be architecture and page size agnostic.

[]

lib/test_overflow.c

Quoted 1 line
lib/test_overflow.c +0 -0

[]

Quoted 7 lines

lib/test_overflow.c static int __init test_overflow_shift(void)

Quoted 1 line
lib/test_overflow.c +0 -0
@@ -486,16 +486,17 @@ static int __init test_overflow_shift(void)

[]

lib/test_overflow.c static int __init test_overflow_shift(void) · line 489

Quoted 1 line
lib/test_overflow.c +1 -0
+#define alloc_GFP		 (GFP_KERNEL | __GFP_NOWARN)

[]

lib/test_overflow.c static int __init test_overflow_shift(void) · line 494

Quoted 1 line
lib/test_overflow.c +1 -0
+#define alloc110(alloc, arg, sz) alloc(arg, sz, alloc_GFP | __GFP_NOWARN)

seems redundant.

Whoops. Missed that one. Fixing...

Signature · 1 line
Kees Cook