All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kasan: test: Consolidate workarounds for unwanted __alloc_size() protection
@ 2021-10-20 19:38 Kees Cook
  2021-10-20 19:41 ` Arnd Bergmann
  2021-10-20 21:17 ` Andrew Morton
  0 siblings, 2 replies; 3+ messages in thread
From: Kees Cook @ 2021-10-20 19:38 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Kees Cook, Arnd Bergmann, Andrey Ryabinin, Alexander Potapenko,
	Andrey Konovalov, Dmitry Vyukov, kasan-dev, linux-kernel,
	linux-hardening

This fixes kasan-test-use-underlying-string-helpers.patch to avoid needing
new helpers. As done in kasan-test-bypass-__alloc_size-checks.patch,
just use OPTIMIZER_HIDE_VAR(). Additionally converts a use of
"volatile", which was trying to work around similar detection.

Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: kasan-dev@googlegroups.com
Signed-off-by: Kees Cook <keescook@chromium.org>
---
Hi Andrew,

Can you please collapse this into your series? It's cleaner to use the
same method everywhere in this file to avoid the compiler being smart. :)

Thanks!

-Kees
---
 lib/test_kasan.c | 24 ++++++------------------
 1 file changed, 6 insertions(+), 18 deletions(-)

diff --git a/lib/test_kasan.c b/lib/test_kasan.c
index 318fc612e7e7..96a1f085b460 100644
--- a/lib/test_kasan.c
+++ b/lib/test_kasan.c
@@ -525,12 +525,13 @@ static void kmalloc_memmove_invalid_size(struct kunit *test)
 {
 	char *ptr;
 	size_t size = 64;
-	volatile size_t invalid_size = size;
+	size_t invalid_size = size;
 
 	ptr = kmalloc(size, GFP_KERNEL);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
 
 	memset((char *)ptr, 0, 64);
+	OPTIMIZER_HIDE_VAR(invalid_size);
 	KUNIT_EXPECT_KASAN_FAIL(test,
 		memmove((char *)ptr, (char *)ptr + 4, invalid_size));
 	kfree(ptr);
@@ -852,21 +853,6 @@ static void kmem_cache_invalid_free(struct kunit *test)
 	kmem_cache_destroy(cache);
 }
 
-/*
- * noinline wrappers to prevent the compiler from noticing the overflow
- * at compile time rather than having kasan catch it.
- */
-static noinline void *__kasan_memchr(const void *s, int c, size_t n)
-{
-	return memchr(s, c, n);
-}
-
-static noinline int __kasan_memcmp(const void *s1, const void *s2, size_t n)
-{
-	return memcmp(s1, s2, n);
-}
-
-
 static void kasan_memchr(struct kunit *test)
 {
 	char *ptr;
@@ -884,8 +870,9 @@ static void kasan_memchr(struct kunit *test)
 	ptr = kmalloc(size, GFP_KERNEL | __GFP_ZERO);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
 
+	OPTIMIZER_HIDE_VAR(size);
 	KUNIT_EXPECT_KASAN_FAIL(test,
-		kasan_ptr_result = __kasan_memchr(ptr, '1', size + 1));
+		kasan_ptr_result = memchr(ptr, '1', size + 1));
 
 	kfree(ptr);
 }
@@ -909,8 +896,9 @@ static void kasan_memcmp(struct kunit *test)
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
 	memset(arr, 0, sizeof(arr));
 
+	OPTIMIZER_HIDE_VAR(size);
 	KUNIT_EXPECT_KASAN_FAIL(test,
-		kasan_int_result = __kasan_memcmp(ptr, arr, size+1));
+		kasan_int_result = memcmp(ptr, arr, size+1));
 	kfree(ptr);
 }
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] kasan: test: Consolidate workarounds for unwanted __alloc_size() protection
  2021-10-20 19:38 [PATCH] kasan: test: Consolidate workarounds for unwanted __alloc_size() protection Kees Cook
@ 2021-10-20 19:41 ` Arnd Bergmann
  2021-10-20 21:17 ` Andrew Morton
  1 sibling, 0 replies; 3+ messages in thread
From: Arnd Bergmann @ 2021-10-20 19:41 UTC (permalink / raw)
  To: Kees Cook
  Cc: Andrew Morton, Arnd Bergmann, Andrey Ryabinin,
	Alexander Potapenko, Andrey Konovalov, Dmitry Vyukov, kasan-dev,
	Linux Kernel Mailing List, linux-hardening

On Wed, Oct 20, 2021 at 9:38 PM Kees Cook <keescook@chromium.org> wrote:
>
> This fixes kasan-test-use-underlying-string-helpers.patch to avoid needing
> new helpers. As done in kasan-test-bypass-__alloc_size-checks.patch,
> just use OPTIMIZER_HIDE_VAR(). Additionally converts a use of
> "volatile", which was trying to work around similar detection.
>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
> Cc: Alexander Potapenko <glider@google.com>
> Cc: Andrey Konovalov <andreyknvl@gmail.com>
> Cc: Dmitry Vyukov <dvyukov@google.com>
> Cc: kasan-dev@googlegroups.com
> Signed-off-by: Kees Cook <keescook@chromium.org>

Yes, that's much better than my version

Acked-by: Arnd Bergmann <arnd@arndb.de>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] kasan: test: Consolidate workarounds for unwanted __alloc_size() protection
  2021-10-20 19:38 [PATCH] kasan: test: Consolidate workarounds for unwanted __alloc_size() protection Kees Cook
  2021-10-20 19:41 ` Arnd Bergmann
@ 2021-10-20 21:17 ` Andrew Morton
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2021-10-20 21:17 UTC (permalink / raw)
  To: Kees Cook
  Cc: Arnd Bergmann, Andrey Ryabinin, Alexander Potapenko,
	Andrey Konovalov, Dmitry Vyukov, kasan-dev, linux-kernel,
	linux-hardening

On Wed, 20 Oct 2021 12:38:07 -0700 Kees Cook <keescook@chromium.org> wrote:

> This fixes kasan-test-use-underlying-string-helpers.patch to avoid needing
> new helpers. As done in kasan-test-bypass-__alloc_size-checks.patch,
> just use OPTIMIZER_HIDE_VAR(). Additionally converts a use of
> "volatile", which was trying to work around similar detection.
> 
> ...
> 
> Can you please collapse this into your series?

Folding it into something else is messy, due to dependencies and
ordering/timing issues.  I queued it as a standalone thing.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-10-20 21:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-20 19:38 [PATCH] kasan: test: Consolidate workarounds for unwanted __alloc_size() protection Kees Cook
2021-10-20 19:41 ` Arnd Bergmann
2021-10-20 21:17 ` Andrew Morton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.