The patch titled Subject: kasan: add tests for call_rcu stack recording has been added to the -mm tree. Its filename is kasan-add-tests-for-call_rcu-stack-recording.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/kasan-add-tests-for-call_rcu-stack-recording.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/kasan-add-tests-for-call_rcu-stack-recording.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Walter Wu <walter-zh.wu@xxxxxxxxxxxx> Subject: kasan: add tests for call_rcu stack recording Test call_rcu() call stack recording and verify whether it correctly is printed in KASAN report. Link: http://lkml.kernel.org/r/20200601051045.1294-1-walter-zh.wu@xxxxxxxxxxxx Signed-off-by: Walter Wu <walter-zh.wu@xxxxxxxxxxxx> Reviewed-by: Dmitry Vyukov <dvyukov@xxxxxxxxxx> Tested-by: Dmitry Vyukov <dvyukov@xxxxxxxxxx> Reviewed-by: Andrey Konovalov <andreyknvl@xxxxxxxxxx> Cc: Andrey Ryabinin <aryabinin@xxxxxxxxxxxxx> Cc: Alexander Potapenko <glider@xxxxxxxxxx> Cc: Matthias Brugger <matthias.bgg@xxxxxxxxx> Cc: Joel Fernandes <joel@xxxxxxxxxxxxxxxxx> Cc: Jonathan Corbet <corbet@xxxxxxx> Cc: Josh Triplett <josh@xxxxxxxxxxxxxxxx> Cc: Lai Jiangshan <jiangshanlai@xxxxxxxxx> Cc: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx> Cc: "Paul E . McKenney" <paulmck@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- lib/test_kasan.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) --- a/lib/test_kasan.c~kasan-add-tests-for-call_rcu-stack-recording +++ a/lib/test_kasan.c @@ -801,6 +801,35 @@ static noinline void __init vmalloc_oob( static void __init vmalloc_oob(void) {} #endif +static struct kasan_rcu_info { + int i; + struct rcu_head rcu; +} *global_rcu_ptr; + +static noinline void __init kasan_rcu_reclaim(struct rcu_head *rp) +{ + struct kasan_rcu_info *fp = container_of(rp, + struct kasan_rcu_info, rcu); + + kfree(fp); + fp->i = 1; +} + +static noinline void __init kasan_rcu_uaf(void) +{ + struct kasan_rcu_info *ptr; + + pr_info("use-after-free in kasan_rcu_reclaim\n"); + ptr = kmalloc(sizeof(struct kasan_rcu_info), GFP_KERNEL); + if (!ptr) { + pr_err("Allocation failed\n"); + return; + } + + global_rcu_ptr = rcu_dereference_protected(ptr, NULL); + call_rcu(&global_rcu_ptr->rcu, kasan_rcu_reclaim); +} + static int __init kmalloc_tests_init(void) { /* @@ -848,6 +877,7 @@ static int __init kmalloc_tests_init(voi kasan_bitops(); kmalloc_double_kzfree(); vmalloc_oob(); + kasan_rcu_uaf(); kasan_restore_multi_shot(multishot); _ Patches currently in -mm which might be from walter-zh.wu@xxxxxxxxxxxx are rcu-kasan-record-and-print-call_rcu-call-stack.patch kasan-record-and-print-the-free-track.patch kasan-add-tests-for-call_rcu-stack-recording.patch kasan-update-documentation-for-generic-kasan.patch