* [PATCH] lib: test_overflow: Avoid taining the kernel and fix wrap size
@ 2019-05-28 22:51 Kees Cook
2019-05-28 23:40 ` Joe Perches
0 siblings, 1 reply; 3+ messages in thread
From: Kees Cook @ 2019-05-28 22:51 UTC (permalink / raw)
To: Andrew Morton; +Cc: Randy Dunlap, Rasmus Villemoes, linux-kernel
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.
Reported-by: Randy Dunlap <rdunlap@infradead.org>
Suggested-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Fixes: ca90800a91ba ("test_overflow: Add memory allocation overflow tests")
Signed-off-by: Kees Cook <keescook@chromium.org>
---
lib/test_overflow.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/lib/test_overflow.c b/lib/test_overflow.c
index fc680562d8b6..4b05143eb538 100644
--- a/lib/test_overflow.c
+++ b/lib/test_overflow.c
@@ -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) \
--
2.17.1
--
Kees Cook
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] lib: test_overflow: Avoid taining the kernel and fix wrap size
2019-05-28 22:51 [PATCH] lib: test_overflow: Avoid taining the kernel and fix wrap size Kees Cook
@ 2019-05-28 23:40 ` Joe Perches
2019-05-29 3:04 ` Kees Cook
0 siblings, 1 reply; 3+ messages in thread
From: Joe Perches @ 2019-05-28 23:40 UTC (permalink / raw)
To: Kees Cook, Andrew Morton; +Cc: Randy Dunlap, Rasmus Villemoes, linux-kernel
On Tue, 2019-05-28 at 15:51 -0700, Kees Cook wrote:
> 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.
[]
> diff --git a/lib/test_overflow.c b/lib/test_overflow.c
[]
> @@ -486,16 +486,17 @@ static int __init test_overflow_shift(void)
[]
> +#define alloc_GFP (GFP_KERNEL | __GFP_NOWARN)
[]
> +#define alloc110(alloc, arg, sz) alloc(arg, sz, alloc_GFP | __GFP_NOWARN)
seems redundant.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] lib: test_overflow: Avoid taining the kernel and fix wrap size
2019-05-28 23:40 ` Joe Perches
@ 2019-05-29 3:04 ` Kees Cook
0 siblings, 0 replies; 3+ messages in thread
From: Kees Cook @ 2019-05-29 3:04 UTC (permalink / raw)
To: Joe Perches; +Cc: Andrew Morton, Randy Dunlap, Rasmus Villemoes, linux-kernel
On Tue, May 28, 2019 at 04:40:06PM -0700, Joe Perches wrote:
> On Tue, 2019-05-28 at 15:51 -0700, Kees Cook wrote:
> > 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.
> []
> > diff --git a/lib/test_overflow.c b/lib/test_overflow.c
> []
> > @@ -486,16 +486,17 @@ static int __init test_overflow_shift(void)
> []
> > +#define alloc_GFP (GFP_KERNEL | __GFP_NOWARN)
> []
> > +#define alloc110(alloc, arg, sz) alloc(arg, sz, alloc_GFP | __GFP_NOWARN)
>
> seems redundant.
Whoops. Missed that one. Fixing...
--
Kees Cook
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-05-29 3:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-28 22:51 [PATCH] lib: test_overflow: Avoid taining the kernel and fix wrap size Kees Cook
2019-05-28 23:40 ` Joe Perches
2019-05-29 3:04 ` Kees Cook
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).