* [PATCH v2] kasan: fix more unit tests with CONFIG_UBSAN_LOCAL_BOUNDS enabled
@ 2022-02-24 0:20 Peter Collingbourne
2022-02-24 8:54 ` Marco Elver
2022-03-08 13:44 ` Andrey Konovalov
0 siblings, 2 replies; 3+ messages in thread
From: Peter Collingbourne @ 2022-02-24 0:20 UTC (permalink / raw)
To: Andrey Konovalov, Marco Elver
Cc: Peter Collingbourne, Andrey Ryabinin, Alexander Potapenko,
Dmitry Vyukov, Nick Desaulniers, Daniel Micay, kasan-dev,
linux-mm, linux-kernel, stable
This is a followup to commit f649dc0e0d7b ("kasan: fix unit tests
with CONFIG_UBSAN_LOCAL_BOUNDS enabled") that fixes tests that fail
as a result of __alloc_size annotations being added to the kernel
allocator functions.
Link: https://linux-review.googlesource.com/id/I4334cafc5db600fda5cebb851b2ee9fd09fb46cc
Signed-off-by: Peter Collingbourne <pcc@google.com>
Cc: <stable@vger.kernel.org> # 5.16.x
Fixes: c37495d6254c ("slab: add __alloc_size attributes for better bounds checking")
---
v2:
- use OPTIMIZER_HIDE_VAR instead of volatile
lib/test_kasan.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/lib/test_kasan.c b/lib/test_kasan.c
index 26a5c9007653..7c3dfb569445 100644
--- a/lib/test_kasan.c
+++ b/lib/test_kasan.c
@@ -185,6 +185,7 @@ static void kmalloc_pagealloc_oob_right(struct kunit *test)
ptr = kmalloc(size, GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
+ OPTIMIZER_HIDE_VAR(ptr);
KUNIT_EXPECT_KASAN_FAIL(test, ptr[size + OOB_TAG_OFF] = 0);
kfree(ptr);
@@ -295,6 +296,7 @@ static void krealloc_more_oob_helper(struct kunit *test,
KUNIT_EXPECT_KASAN_FAIL(test, ptr2[size2] = 'x');
/* For all modes first aligned offset after size2 must be inaccessible. */
+ OPTIMIZER_HIDE_VAR(ptr2);
KUNIT_EXPECT_KASAN_FAIL(test,
ptr2[round_up(size2, KASAN_GRANULE_SIZE)] = 'x');
@@ -319,6 +321,8 @@ static void krealloc_less_oob_helper(struct kunit *test,
/* Must be accessible for all modes. */
ptr2[size2 - 1] = 'x';
+ OPTIMIZER_HIDE_VAR(ptr2);
+
/* Generic mode is precise, so unaligned size2 must be inaccessible. */
if (IS_ENABLED(CONFIG_KASAN_GENERIC))
KUNIT_EXPECT_KASAN_FAIL(test, ptr2[size2] = 'x');
--
2.35.1.473.g83b2b277ed-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] kasan: fix more unit tests with CONFIG_UBSAN_LOCAL_BOUNDS enabled
2022-02-24 0:20 [PATCH v2] kasan: fix more unit tests with CONFIG_UBSAN_LOCAL_BOUNDS enabled Peter Collingbourne
@ 2022-02-24 8:54 ` Marco Elver
2022-03-08 13:44 ` Andrey Konovalov
1 sibling, 0 replies; 3+ messages in thread
From: Marco Elver @ 2022-02-24 8:54 UTC (permalink / raw)
To: Peter Collingbourne
Cc: Andrey Konovalov, Andrey Ryabinin, Alexander Potapenko,
Dmitry Vyukov, Nick Desaulniers, Daniel Micay, kasan-dev,
linux-mm, linux-kernel, stable
On Thu, 24 Feb 2022 at 01:20, Peter Collingbourne <pcc@google.com> wrote:
>
> This is a followup to commit f649dc0e0d7b ("kasan: fix unit tests
> with CONFIG_UBSAN_LOCAL_BOUNDS enabled") that fixes tests that fail
> as a result of __alloc_size annotations being added to the kernel
> allocator functions.
>
> Link: https://linux-review.googlesource.com/id/I4334cafc5db600fda5cebb851b2ee9fd09fb46cc
> Signed-off-by: Peter Collingbourne <pcc@google.com>
> Cc: <stable@vger.kernel.org> # 5.16.x
> Fixes: c37495d6254c ("slab: add __alloc_size attributes for better bounds checking")
Reviewed-by: Marco Elver <elver@google.com>
Thanks!
> ---
> v2:
> - use OPTIMIZER_HIDE_VAR instead of volatile
>
> lib/test_kasan.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/lib/test_kasan.c b/lib/test_kasan.c
> index 26a5c9007653..7c3dfb569445 100644
> --- a/lib/test_kasan.c
> +++ b/lib/test_kasan.c
> @@ -185,6 +185,7 @@ static void kmalloc_pagealloc_oob_right(struct kunit *test)
> ptr = kmalloc(size, GFP_KERNEL);
> KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
>
> + OPTIMIZER_HIDE_VAR(ptr);
> KUNIT_EXPECT_KASAN_FAIL(test, ptr[size + OOB_TAG_OFF] = 0);
>
> kfree(ptr);
> @@ -295,6 +296,7 @@ static void krealloc_more_oob_helper(struct kunit *test,
> KUNIT_EXPECT_KASAN_FAIL(test, ptr2[size2] = 'x');
>
> /* For all modes first aligned offset after size2 must be inaccessible. */
> + OPTIMIZER_HIDE_VAR(ptr2);
> KUNIT_EXPECT_KASAN_FAIL(test,
> ptr2[round_up(size2, KASAN_GRANULE_SIZE)] = 'x');
>
> @@ -319,6 +321,8 @@ static void krealloc_less_oob_helper(struct kunit *test,
> /* Must be accessible for all modes. */
> ptr2[size2 - 1] = 'x';
>
> + OPTIMIZER_HIDE_VAR(ptr2);
> +
> /* Generic mode is precise, so unaligned size2 must be inaccessible. */
> if (IS_ENABLED(CONFIG_KASAN_GENERIC))
> KUNIT_EXPECT_KASAN_FAIL(test, ptr2[size2] = 'x');
> --
> 2.35.1.473.g83b2b277ed-goog
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] kasan: fix more unit tests with CONFIG_UBSAN_LOCAL_BOUNDS enabled
2022-02-24 0:20 [PATCH v2] kasan: fix more unit tests with CONFIG_UBSAN_LOCAL_BOUNDS enabled Peter Collingbourne
2022-02-24 8:54 ` Marco Elver
@ 2022-03-08 13:44 ` Andrey Konovalov
1 sibling, 0 replies; 3+ messages in thread
From: Andrey Konovalov @ 2022-03-08 13:44 UTC (permalink / raw)
To: Peter Collingbourne
Cc: Marco Elver, Andrey Ryabinin, Alexander Potapenko, Dmitry Vyukov,
Nick Desaulniers, Daniel Micay, kasan-dev,
Linux Memory Management List, LKML, stable, Kees Cook
On Thu, Feb 24, 2022 at 1:20 AM Peter Collingbourne <pcc@google.com> wrote:
>
> This is a followup to commit f649dc0e0d7b ("kasan: fix unit tests
> with CONFIG_UBSAN_LOCAL_BOUNDS enabled") that fixes tests that fail
> as a result of __alloc_size annotations being added to the kernel
> allocator functions.
>
> Link: https://linux-review.googlesource.com/id/I4334cafc5db600fda5cebb851b2ee9fd09fb46cc
> Signed-off-by: Peter Collingbourne <pcc@google.com>
> Cc: <stable@vger.kernel.org> # 5.16.x
> Fixes: c37495d6254c ("slab: add __alloc_size attributes for better bounds checking")
> ---
> v2:
> - use OPTIMIZER_HIDE_VAR instead of volatile
>
> lib/test_kasan.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/lib/test_kasan.c b/lib/test_kasan.c
> index 26a5c9007653..7c3dfb569445 100644
> --- a/lib/test_kasan.c
> +++ b/lib/test_kasan.c
> @@ -185,6 +185,7 @@ static void kmalloc_pagealloc_oob_right(struct kunit *test)
> ptr = kmalloc(size, GFP_KERNEL);
> KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
>
> + OPTIMIZER_HIDE_VAR(ptr);
> KUNIT_EXPECT_KASAN_FAIL(test, ptr[size + OOB_TAG_OFF] = 0);
>
> kfree(ptr);
> @@ -295,6 +296,7 @@ static void krealloc_more_oob_helper(struct kunit *test,
> KUNIT_EXPECT_KASAN_FAIL(test, ptr2[size2] = 'x');
>
> /* For all modes first aligned offset after size2 must be inaccessible. */
> + OPTIMIZER_HIDE_VAR(ptr2);
> KUNIT_EXPECT_KASAN_FAIL(test,
> ptr2[round_up(size2, KASAN_GRANULE_SIZE)] = 'x');
>
> @@ -319,6 +321,8 @@ static void krealloc_less_oob_helper(struct kunit *test,
> /* Must be accessible for all modes. */
> ptr2[size2 - 1] = 'x';
>
> + OPTIMIZER_HIDE_VAR(ptr2);
> +
> /* Generic mode is precise, so unaligned size2 must be inaccessible. */
> if (IS_ENABLED(CONFIG_KASAN_GENERIC))
> KUNIT_EXPECT_KASAN_FAIL(test, ptr2[size2] = 'x');
> --
> 2.35.1.473.g83b2b277ed-goog
>
Acked-by: Andrey Konovalov <andreyknvl@gmail.com>
This patch seems to be in partial conflict with the "kasan: test:
Silence allocation warnings from GCC 12" patch by Kees, which is
already in mm.
Thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-03-08 13:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-24 0:20 [PATCH v2] kasan: fix more unit tests with CONFIG_UBSAN_LOCAL_BOUNDS enabled Peter Collingbourne
2022-02-24 8:54 ` Marco Elver
2022-03-08 13:44 ` Andrey Konovalov
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).