* [PATCH] kasan: fix more unit tests with CONFIG_UBSAN_LOCAL_BOUNDS enabled
@ 2022-02-19 1:26 Peter Collingbourne
2022-02-21 11:20 ` Marco Elver
0 siblings, 1 reply; 3+ messages in thread
From: Peter Collingbourne @ 2022-02-19 1:26 UTC (permalink / raw)
To: Andrey Konovalov, Marco Elver
Cc: Peter Collingbourne, Kees Cook, Andrew Morton, linux-mm, 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")
---
lib/test_kasan.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/lib/test_kasan.c b/lib/test_kasan.c
index 26a5c9007653..3bf8801d0e66 100644
--- a/lib/test_kasan.c
+++ b/lib/test_kasan.c
@@ -177,7 +177,8 @@ static void kmalloc_node_oob_right(struct kunit *test)
*/
static void kmalloc_pagealloc_oob_right(struct kunit *test)
{
- char *ptr;
+ /* See comment in kasan_global_oob_right. */
+ char *volatile ptr;
size_t size = KMALLOC_MAX_CACHE_SIZE + 10;
KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB);
@@ -272,7 +273,8 @@ static void kmalloc_large_oob_right(struct kunit *test)
static void krealloc_more_oob_helper(struct kunit *test,
size_t size1, size_t size2)
{
- char *ptr1, *ptr2;
+ /* See comment in kasan_global_oob_right. */
+ char *ptr1, *volatile ptr2;
size_t middle;
KUNIT_ASSERT_LT(test, size1, size2);
@@ -304,7 +306,8 @@ static void krealloc_more_oob_helper(struct kunit *test,
static void krealloc_less_oob_helper(struct kunit *test,
size_t size1, size_t size2)
{
- char *ptr1, *ptr2;
+ /* See comment in kasan_global_oob_right. */
+ char *ptr1, *volatile ptr2;
size_t middle;
KUNIT_ASSERT_LT(test, size2, size1);
--
2.35.1.473.g83b2b277ed-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] kasan: fix more unit tests with CONFIG_UBSAN_LOCAL_BOUNDS enabled
2022-02-19 1:26 [PATCH] kasan: fix more unit tests with CONFIG_UBSAN_LOCAL_BOUNDS enabled Peter Collingbourne
@ 2022-02-21 11:20 ` Marco Elver
2022-02-24 0:21 ` Peter Collingbourne
0 siblings, 1 reply; 3+ messages in thread
From: Marco Elver @ 2022-02-21 11:20 UTC (permalink / raw)
To: Peter Collingbourne
Cc: Andrey Konovalov, Kees Cook, Andrew Morton, linux-mm, stable
On Sat, 19 Feb 2022 at 02:26, 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")
> ---
> lib/test_kasan.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/lib/test_kasan.c b/lib/test_kasan.c
> index 26a5c9007653..3bf8801d0e66 100644
> --- a/lib/test_kasan.c
> +++ b/lib/test_kasan.c
> @@ -177,7 +177,8 @@ static void kmalloc_node_oob_right(struct kunit *test)
> */
> static void kmalloc_pagealloc_oob_right(struct kunit *test)
> {
> - char *ptr;
> + /* See comment in kasan_global_oob_right. */
> + char *volatile ptr;
> size_t size = KMALLOC_MAX_CACHE_SIZE + 10;
I think more recently we've been using OPTIMIZER_HIDE_VAR() to hide
things from the compiler. Does OPTIMIZER_HIDE_VAR(ptr) right before
the access also work in this case?
I leave it to you which you think is cleaner - I'm guessing that we
might want to avoid volatile if we can.
> KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_SLUB);
> @@ -272,7 +273,8 @@ static void kmalloc_large_oob_right(struct kunit *test)
> static void krealloc_more_oob_helper(struct kunit *test,
> size_t size1, size_t size2)
> {
> - char *ptr1, *ptr2;
> + /* See comment in kasan_global_oob_right. */
> + char *ptr1, *volatile ptr2;
> size_t middle;
>
> KUNIT_ASSERT_LT(test, size1, size2);
> @@ -304,7 +306,8 @@ static void krealloc_more_oob_helper(struct kunit *test,
> static void krealloc_less_oob_helper(struct kunit *test,
> size_t size1, size_t size2)
> {
> - char *ptr1, *ptr2;
> + /* See comment in kasan_global_oob_right. */
> + char *ptr1, *volatile ptr2;
> size_t middle;
>
> KUNIT_ASSERT_LT(test, size2, size1);
> --
> 2.35.1.473.g83b2b277ed-goog
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] kasan: fix more unit tests with CONFIG_UBSAN_LOCAL_BOUNDS enabled
2022-02-21 11:20 ` Marco Elver
@ 2022-02-24 0:21 ` Peter Collingbourne
0 siblings, 0 replies; 3+ messages in thread
From: Peter Collingbourne @ 2022-02-24 0:21 UTC (permalink / raw)
To: Marco Elver
Cc: Andrey Konovalov, Kees Cook, Andrew Morton,
Linux Memory Management List, # 3.4.x
On Mon, Feb 21, 2022 at 3:20 AM Marco Elver <elver@google.com> wrote:
>
> On Sat, 19 Feb 2022 at 02:26, 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")
> > ---
> > lib/test_kasan.c | 9 ++++++---
> > 1 file changed, 6 insertions(+), 3 deletions(-)
> >
> > diff --git a/lib/test_kasan.c b/lib/test_kasan.c
> > index 26a5c9007653..3bf8801d0e66 100644
> > --- a/lib/test_kasan.c
> > +++ b/lib/test_kasan.c
> > @@ -177,7 +177,8 @@ static void kmalloc_node_oob_right(struct kunit *test)
> > */
> > static void kmalloc_pagealloc_oob_right(struct kunit *test)
> > {
> > - char *ptr;
> > + /* See comment in kasan_global_oob_right. */
> > + char *volatile ptr;
> > size_t size = KMALLOC_MAX_CACHE_SIZE + 10;
>
> I think more recently we've been using OPTIMIZER_HIDE_VAR() to hide
> things from the compiler. Does OPTIMIZER_HIDE_VAR(ptr) right before
> the access also work in this case?
>
> I leave it to you which you think is cleaner - I'm guessing that we
> might want to avoid volatile if we can.
Okay, sent v2 which uses OPTIMIZER_HIDE_VAR.
Peter
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-02-24 0:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-19 1:26 [PATCH] kasan: fix more unit tests with CONFIG_UBSAN_LOCAL_BOUNDS enabled Peter Collingbourne
2022-02-21 11:20 ` Marco Elver
2022-02-24 0:21 ` Peter Collingbourne
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.