linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] kunit: kasan_test: disable fortify string checker on kasan_strings() test
@ 2025-08-01 12:02 Yeoreum Yun
  2025-08-01 20:13 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Yeoreum Yun @ 2025-08-01 12:02 UTC (permalink / raw)
  To: thomas.weissschuh, ryabinin.a.a, glider, andreyknvl, dvyukov,
	vincenzo.frascino, akpm
  Cc: kasan-dev, linux-mm, linux-kernel, Yeoreum Yun

Similar to commit 09c6304e38e4 ("kasan: test: fix compatibility with
FORTIFY_SOURCE") the kernel is panicing in kasan_string().

This is due to the `src` and `ptr` not being hidden from the optimizer
which would disable the runtime fortify string checker.

Call trace:
  __fortify_panic+0x10/0x20 (P)
  kasan_strings+0x980/0x9b0
  kunit_try_run_case+0x68/0x190
  kunit_generic_run_threadfn_adapter+0x34/0x68
  kthread+0x1c4/0x228
  ret_from_fork+0x10/0x20
 Code: d503233f a9bf7bfd 910003fd 9424b243 (d4210000)
 ---[ end trace 0000000000000000 ]---
 note: kunit_try_catch[128] exited with irqs disabled
 note: kunit_try_catch[128] exited with preempt_count 1
     # kasan_strings: try faulted: last
** replaying previous printk message **
     # kasan_strings: try faulted: last line seen mm/kasan/kasan_test_c.c:1600
     # kasan_strings: internal error occurred preventing test case from running: -4

Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
Patch History
=============
from v2 to v3:
  - rewrite commit message.
  - Using OPTIMIZER_HIDE_VAR() instead of __NO_FORTIFY
  - https://lore.kernel.org/all/20250801092805.2602490-1-yeoreum.yun@arm.com/

from v1 to v2:
  - Using __NO_FORTIFY instead of skipping kasan_strings() when
    CONFIG_FORTIFY_SOURCE is enabled.
  - https://lore.kernel.org/all/aIs4rwZ1o53iTuP%2F@e129823.arm.com/
---
 mm/kasan/kasan_test_c.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/mm/kasan/kasan_test_c.c b/mm/kasan/kasan_test_c.c
index 5f922dd38ffa..a1a0e60645da 100644
--- a/mm/kasan/kasan_test_c.c
+++ b/mm/kasan/kasan_test_c.c
@@ -1578,9 +1578,11 @@ static void kasan_strings(struct kunit *test)

 	ptr = kmalloc(size, GFP_KERNEL | __GFP_ZERO);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
+	OPTIMIZER_HIDE_VAR(ptr);

 	src = kmalloc(KASAN_GRANULE_SIZE, GFP_KERNEL | __GFP_ZERO);
 	strscpy(src, "f0cacc1a0000000", KASAN_GRANULE_SIZE);
+	OPTIMIZER_HIDE_VAR(src);

 	/*
 	 * Make sure that strscpy() does not trigger KASAN if it overreads into
--
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}



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

* Re: [PATCH v3] kunit: kasan_test: disable fortify string checker on kasan_strings() test
  2025-08-01 12:02 [PATCH v3] kunit: kasan_test: disable fortify string checker on kasan_strings() test Yeoreum Yun
@ 2025-08-01 20:13 ` Andrew Morton
  2025-08-01 20:24   ` Yeoreum Yun
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2025-08-01 20:13 UTC (permalink / raw)
  To: Yeoreum Yun
  Cc: thomas.weissschuh, ryabinin.a.a, glider, andreyknvl, dvyukov,
	vincenzo.frascino, kasan-dev, linux-mm, linux-kernel

On Fri,  1 Aug 2025 13:02:36 +0100 Yeoreum Yun <yeoreum.yun@arm.com> wrote:

> Similar to commit 09c6304e38e4 ("kasan: test: fix compatibility with
> FORTIFY_SOURCE") the kernel is panicing in kasan_string().
> 
> This is due to the `src` and `ptr` not being hidden from the optimizer
> which would disable the runtime fortify string checker.
> 
> Call trace:
>   __fortify_panic+0x10/0x20 (P)
>   kasan_strings+0x980/0x9b0
>   kunit_try_run_case+0x68/0x190
>   kunit_generic_run_threadfn_adapter+0x34/0x68
>   kthread+0x1c4/0x228
>   ret_from_fork+0x10/0x20
>  Code: d503233f a9bf7bfd 910003fd 9424b243 (d4210000)
>  ---[ end trace 0000000000000000 ]---
>  note: kunit_try_catch[128] exited with irqs disabled
>  note: kunit_try_catch[128] exited with preempt_count 1
>      # kasan_strings: try faulted: last
> ** replaying previous printk message **
>      # kasan_strings: try faulted: last line seen mm/kasan/kasan_test_c.c:1600
>      # kasan_strings: internal error occurred preventing test case from running: -4
> 

We don't want -stable kernels to panic either.  I'm thinking

Fixes: 73228c7ecc5e ("KASAN: port KASAN Tests to KUnit")
Cc: <stable@vger.kernel.org>

What do you think?

We could perhaps go back earlier in time, but 73228c7ecc5e is 5 years
old.


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

* Re: [PATCH v3] kunit: kasan_test: disable fortify string checker on kasan_strings() test
  2025-08-01 20:13 ` Andrew Morton
@ 2025-08-01 20:24   ` Yeoreum Yun
  0 siblings, 0 replies; 3+ messages in thread
From: Yeoreum Yun @ 2025-08-01 20:24 UTC (permalink / raw)
  To: Andrew Morton
  Cc: thomas.weissschuh, ryabinin.a.a, glider, andreyknvl, dvyukov,
	vincenzo.frascino, kasan-dev, linux-mm, linux-kernel

Hi Andrew,

> > Similar to commit 09c6304e38e4 ("kasan: test: fix compatibility with
> > FORTIFY_SOURCE") the kernel is panicing in kasan_string().
> >
> > This is due to the `src` and `ptr` not being hidden from the optimizer
> > which would disable the runtime fortify string checker.
> >
> > Call trace:
> >   __fortify_panic+0x10/0x20 (P)
> >   kasan_strings+0x980/0x9b0
> >   kunit_try_run_case+0x68/0x190
> >   kunit_generic_run_threadfn_adapter+0x34/0x68
> >   kthread+0x1c4/0x228
> >   ret_from_fork+0x10/0x20
> >  Code: d503233f a9bf7bfd 910003fd 9424b243 (d4210000)
> >  ---[ end trace 0000000000000000 ]---
> >  note: kunit_try_catch[128] exited with irqs disabled
> >  note: kunit_try_catch[128] exited with preempt_count 1
> >      # kasan_strings: try faulted: last
> > ** replaying previous printk message **
> >      # kasan_strings: try faulted: last line seen mm/kasan/kasan_test_c.c:1600
> >      # kasan_strings: internal error occurred preventing test case from running: -4
> >
>
> We don't want -stable kernels to panic either.  I'm thinking
>
> Fixes: 73228c7ecc5e ("KASAN: port KASAN Tests to KUnit")
> Cc: <stable@vger.kernel.org>
>
> What do you think?
>
> We could perhaps go back earlier in time, but 73228c7ecc5e is 5 years
> old.

Unless others feel differently, your suggestion works for me.
I had considered including it earlier, but wasn’t entirely sure.

Thanks

--
Sincerely,
Yeoreum Yun


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

end of thread, other threads:[~2025-08-01 20:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-01 12:02 [PATCH v3] kunit: kasan_test: disable fortify string checker on kasan_strings() test Yeoreum Yun
2025-08-01 20:13 ` Andrew Morton
2025-08-01 20:24   ` Yeoreum Yun

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox