[PATCH 4/4] kasan: Avoid an unrelated RCU warning in the callback test

0 views
Skip to first unread message

Joel Fernandes

unread,
Nov 8, 2026, 6:47:27 PM (11 days ago) Nov 8
to linux-...@vger.kernel.org, Andrey Ryabinin, Alexander Potapenko, Andrey Konovalov, Dmitry Vyukov, Vincenzo Frascino, Andrew Morton, Joel Fernandes, kasa...@googlegroups.com, linu...@kvack.org
rcu_uaf() passes a false protection condition to
rcu_dereference_protected(), which produces a suspicious-RCU-usage
warning before the intended KASAN failure occurs.

The pointer refers to a fresh allocation that has not been published to
readers. State that protection condition explicitly, leaving the intended
tests intact.

Test:
Built with CONFIG_KASAN_KUNIT_TEST=m
Booted Qemu guest (8 CPUs), ran modprobe kasan_test filtered to kasan.*rcu_uaf*

Signed-off-by: Joel Fernandes <joela...@nvidia.com>
---
mm/kasan/kasan_test_c.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mm/kasan/kasan_test_c.c b/mm/kasan/kasan_test_c.c
index b9e167ed5be3..4e23765d722c 100644
--- a/mm/kasan/kasan_test_c.c
+++ b/mm/kasan/kasan_test_c.c
@@ -967,8 +967,9 @@ static void rcu_uaf(struct kunit *test)
ptr = kmalloc_obj(struct kasan_rcu_info);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);

+ /* The freshly allocated object has not been published to readers. */
global_rcu_ptr = rcu_dereference_protected(
- (struct kasan_rcu_info __rcu *)ptr, NULL);
+ (struct kasan_rcu_info __rcu *)ptr, true);

KUNIT_EXPECT_KASAN_FAIL_READ(test,
call_rcu(&global_rcu_ptr->rcu, rcu_uaf_reclaim);
--
2.54.0

Joel Fernandes

unread,
Nov 8, 2026, 7:03:38 PM (11 days ago) Nov 8
to linux-...@vger.kernel.org, Paul E . McKenney, Frederic Weisbecker, Neeraj Upadhyay, Joel Fernandes, Josh Triplett, Boqun Feng, Uladzislau Rezki, Steven Rostedt, Mathieu Desnoyers, Lai Jiangshan, Zqiang, Andrey Ryabinin, Alexander Potapenko, Andrey Konovalov, Dmitry Vyukov, Vincenzo Frascino, Andrew Morton, r...@vger.kernel.org, kasa...@googlegroups.com, linu...@kvack.org

Paul E. McKenney

unread,
Nov 9, 2026, 7:11:35 PM (10 days ago) Nov 9
to Joel Fernandes, linux-...@vger.kernel.org, Frederic Weisbecker, Neeraj Upadhyay, Josh Triplett, Boqun Feng, Uladzislau Rezki, Steven Rostedt, Mathieu Desnoyers, Lai Jiangshan, Zqiang, Andrey Ryabinin, Alexander Potapenko, Andrey Konovalov, Dmitry Vyukov, Vincenzo Frascino, Andrew Morton, r...@vger.kernel.org, kasa...@googlegroups.com, linu...@kvack.org
On Sun, Nov 08, 2026 at 07:02:40PM -0500, Joel Fernandes wrote:
> rcu_uaf() passes a false protection condition to
> rcu_dereference_protected(), which produces a suspicious-RCU-usage
> warning before the intended KASAN failure occurs.
>
> The pointer refers to a fresh allocation that has not been published to
> readers. State that protection condition explicitly, leaving the intended
> tests intact.
>
> Test:
> Built with CONFIG_KASAN_KUNIT_TEST=m
> Booted Qemu guest (8 CPUs), ran modprobe kasan_test filtered to kasan.*rcu_uaf*
>
> Signed-off-by: Joel Fernandes <joela...@nvidia.com>

Reviewed-by: Paul E. McKenney <pau...@kernel.org>

And yes, the second argument to rcu_dereference_protected() is a boolean,
not a pointer. Good catch!

Andrey Ryabinin

unread,
Nov 12, 2026, 11:33:24 AM (7 days ago) Nov 12
to Joel Fernandes, linux-...@vger.kernel.org, Paul E . McKenney, Frederic Weisbecker, Neeraj Upadhyay, Josh Triplett, Boqun Feng, Uladzislau Rezki, Steven Rostedt, Mathieu Desnoyers, Lai Jiangshan, Zqiang, Alexander Potapenko, Andrey Konovalov, Dmitry Vyukov, Vincenzo Frascino, Andrew Morton, r...@vger.kernel.org, kasa...@googlegroups.com, linu...@kvack.org
Joel Fernandes <joela...@nvidia.com> writes:

> rcu_uaf() passes a false protection condition to
> rcu_dereference_protected(), which produces a suspicious-RCU-usage
> warning before the intended KASAN failure occurs.
>
> The pointer refers to a fresh allocation that has not been published to
> readers. State that protection condition explicitly, leaving the intended
> tests intact.
>
> Test:
> Built with CONFIG_KASAN_KUNIT_TEST=m
> Booted Qemu guest (8 CPUs), ran modprobe kasan_test filtered to kasan.*rcu_uaf*
>
> Signed-off-by: Joel Fernandes <joela...@nvidia.com>

Reviewed-by: Andrey Ryabinin <ryabin...@gmail.com>

Joel Fernandes

unread,
Nov 12, 2026, 7:57:58 PM (7 days ago) Nov 12
to linux-...@vger.kernel.org, Paul E . McKenney, Frederic Weisbecker, Neeraj Upadhyay, Joel Fernandes, Josh Triplett, Boqun Feng, Uladzislau Rezki, Steven Rostedt, Mathieu Desnoyers, Lai Jiangshan, Zqiang, Andrey Ryabinin, Alexander Potapenko, Andrey Konovalov, Dmitry Vyukov, Vincenzo Frascino, Andrew Morton, r...@vger.kernel.org, kasa...@googlegroups.com, linu...@kvack.org
rcu_uaf() passes a false protection condition to
rcu_dereference_protected(), which produces a suspicious-RCU-usage
warning before the intended KASAN failure occurs.

The pointer refers to a fresh allocation that has not been published to
readers. State that protection condition explicitly, leaving the intended
tests intact.

Test:
Built with CONFIG_KASAN_KUNIT_TEST=m
Booted Qemu guest (8 CPUs), ran modprobe kasan_test filtered to kasan.*rcu_uaf*

Signed-off-by: Joel Fernandes <jf...@kernel.org>
Reviewed-by: Paul E. McKenney <pau...@kernel.org>
Reply all
Reply to author
Forward
0 new messages