From: Walter Wu <walter-zh.wu@mediatek.com>
To: Andrey Ryabinin <aryabinin@virtuozzo.com>,
Alexander Potapenko <glider@google.com>,
Dmitry Vyukov <dvyukov@google.com>,
Matthias Brugger <matthias.bgg@gmail.com>
Cc: <kasan-dev@googlegroups.com>, <linux-mm@kvack.org>,
<linux-kernel@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
wsd_upstream <wsd_upstream@mediatek.com>,
<linux-mediatek@lists.infradead.org>,
Walter Wu <walter-zh.wu@mediatek.com>
Subject: [PATCH 3/5] lib/test_kasan.c: add timer test case
Date: Mon, 10 Aug 2020 15:26:20 +0800 [thread overview]
Message-ID: <20200810072620.747-1-walter-zh.wu@mediatek.com> (raw)
Adds a test case to verify timer stack recording
and print the last timer stack in KASAN report.
The KASAN report was as follows(cleaned up slightly):
BUG: KASAN: use-after-free in kasan_timer_uaf
Freed by task 0:
kasan_save_stack+0x24/0x50
kasan_set_track+0x24/0x38
kasan_set_free_info+0x20/0x40
__kasan_slab_free+0x10c/0x170
kasan_slab_free+0x10/0x18
kfree+0x98/0x270
kasan_timer_function+0x1c/0x28
Last timer stack:
kasan_save_stack+0x24/0x50
kasan_record_tmr_stack+0xa8/0xb8
init_timer_key+0xf0/0x248
kasan_timer_uaf+0x5c/0xd8
Signed-off-by: Walter Wu <walter-zh.wu@mediatek.com>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Matthias Brugger <matthias.bgg@gmail.com>
---
lib/test_kasan.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/lib/test_kasan.c b/lib/test_kasan.c
index 6e5fb05d42d8..2bd61674c7a3 100644
--- a/lib/test_kasan.c
+++ b/lib/test_kasan.c
@@ -821,6 +821,30 @@ static noinline void __init kasan_rcu_uaf(void)
call_rcu(&global_ptr->rcu, kasan_rcu_reclaim);
}
+static noinline void __init kasan_timer_function(struct timer_list *timer)
+{
+ del_timer(timer);
+ kfree(timer);
+}
+
+static noinline void __init kasan_timer_uaf(void)
+{
+ struct timer_list *timer;
+
+ timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
+ if (!timer) {
+ pr_err("Allocation failed\n");
+ return;
+ }
+
+ timer_setup(timer, kasan_timer_function, 0);
+ add_timer(timer);
+ msleep(100);
+
+ pr_info("use-after-free on timer\n");
+ ((volatile struct timer_list *)timer)->expires;
+}
+
static int __init kmalloc_tests_init(void)
{
/*
@@ -869,6 +893,7 @@ static int __init kmalloc_tests_init(void)
kmalloc_double_kzfree();
vmalloc_oob();
kasan_rcu_uaf();
+ kasan_timer_uaf();
kasan_restore_multi_shot(multishot);
--
2.18.0
WARNING: multiple messages have this Message-ID (diff)
From: Walter Wu <walter-zh.wu@mediatek.com>
To: Andrey Ryabinin <aryabinin@virtuozzo.com>,
Alexander Potapenko <glider@google.com>,
Dmitry Vyukov <dvyukov@google.com>,
Matthias Brugger <matthias.bgg@gmail.com>
Cc: Walter Wu <walter-zh.wu@mediatek.com>,
wsd_upstream <wsd_upstream@mediatek.com>,
linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com,
linux-mm@kvack.org, linux-mediatek@lists.infradead.org,
linux-arm-kernel@lists.infradead.org
Subject: [PATCH 3/5] lib/test_kasan.c: add timer test case
Date: Mon, 10 Aug 2020 15:26:20 +0800 [thread overview]
Message-ID: <20200810072620.747-1-walter-zh.wu@mediatek.com> (raw)
Adds a test case to verify timer stack recording
and print the last timer stack in KASAN report.
The KASAN report was as follows(cleaned up slightly):
BUG: KASAN: use-after-free in kasan_timer_uaf
Freed by task 0:
kasan_save_stack+0x24/0x50
kasan_set_track+0x24/0x38
kasan_set_free_info+0x20/0x40
__kasan_slab_free+0x10c/0x170
kasan_slab_free+0x10/0x18
kfree+0x98/0x270
kasan_timer_function+0x1c/0x28
Last timer stack:
kasan_save_stack+0x24/0x50
kasan_record_tmr_stack+0xa8/0xb8
init_timer_key+0xf0/0x248
kasan_timer_uaf+0x5c/0xd8
Signed-off-by: Walter Wu <walter-zh.wu@mediatek.com>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Matthias Brugger <matthias.bgg@gmail.com>
---
lib/test_kasan.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/lib/test_kasan.c b/lib/test_kasan.c
index 6e5fb05d42d8..2bd61674c7a3 100644
--- a/lib/test_kasan.c
+++ b/lib/test_kasan.c
@@ -821,6 +821,30 @@ static noinline void __init kasan_rcu_uaf(void)
call_rcu(&global_ptr->rcu, kasan_rcu_reclaim);
}
+static noinline void __init kasan_timer_function(struct timer_list *timer)
+{
+ del_timer(timer);
+ kfree(timer);
+}
+
+static noinline void __init kasan_timer_uaf(void)
+{
+ struct timer_list *timer;
+
+ timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
+ if (!timer) {
+ pr_err("Allocation failed\n");
+ return;
+ }
+
+ timer_setup(timer, kasan_timer_function, 0);
+ add_timer(timer);
+ msleep(100);
+
+ pr_info("use-after-free on timer\n");
+ ((volatile struct timer_list *)timer)->expires;
+}
+
static int __init kmalloc_tests_init(void)
{
/*
@@ -869,6 +893,7 @@ static int __init kmalloc_tests_init(void)
kmalloc_double_kzfree();
vmalloc_oob();
kasan_rcu_uaf();
+ kasan_timer_uaf();
kasan_restore_multi_shot(multishot);
--
2.18.0
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
WARNING: multiple messages have this Message-ID (diff)
From: Walter Wu <walter-zh.wu@mediatek.com>
To: Andrey Ryabinin <aryabinin@virtuozzo.com>,
Alexander Potapenko <glider@google.com>,
Dmitry Vyukov <dvyukov@google.com>,
Matthias Brugger <matthias.bgg@gmail.com>
Cc: Walter Wu <walter-zh.wu@mediatek.com>,
wsd_upstream <wsd_upstream@mediatek.com>,
linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com,
linux-mm@kvack.org, linux-mediatek@lists.infradead.org,
linux-arm-kernel@lists.infradead.org
Subject: [PATCH 3/5] lib/test_kasan.c: add timer test case
Date: Mon, 10 Aug 2020 15:26:20 +0800 [thread overview]
Message-ID: <20200810072620.747-1-walter-zh.wu@mediatek.com> (raw)
Adds a test case to verify timer stack recording
and print the last timer stack in KASAN report.
The KASAN report was as follows(cleaned up slightly):
BUG: KASAN: use-after-free in kasan_timer_uaf
Freed by task 0:
kasan_save_stack+0x24/0x50
kasan_set_track+0x24/0x38
kasan_set_free_info+0x20/0x40
__kasan_slab_free+0x10c/0x170
kasan_slab_free+0x10/0x18
kfree+0x98/0x270
kasan_timer_function+0x1c/0x28
Last timer stack:
kasan_save_stack+0x24/0x50
kasan_record_tmr_stack+0xa8/0xb8
init_timer_key+0xf0/0x248
kasan_timer_uaf+0x5c/0xd8
Signed-off-by: Walter Wu <walter-zh.wu@mediatek.com>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Matthias Brugger <matthias.bgg@gmail.com>
---
lib/test_kasan.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/lib/test_kasan.c b/lib/test_kasan.c
index 6e5fb05d42d8..2bd61674c7a3 100644
--- a/lib/test_kasan.c
+++ b/lib/test_kasan.c
@@ -821,6 +821,30 @@ static noinline void __init kasan_rcu_uaf(void)
call_rcu(&global_ptr->rcu, kasan_rcu_reclaim);
}
+static noinline void __init kasan_timer_function(struct timer_list *timer)
+{
+ del_timer(timer);
+ kfree(timer);
+}
+
+static noinline void __init kasan_timer_uaf(void)
+{
+ struct timer_list *timer;
+
+ timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
+ if (!timer) {
+ pr_err("Allocation failed\n");
+ return;
+ }
+
+ timer_setup(timer, kasan_timer_function, 0);
+ add_timer(timer);
+ msleep(100);
+
+ pr_info("use-after-free on timer\n");
+ ((volatile struct timer_list *)timer)->expires;
+}
+
static int __init kmalloc_tests_init(void)
{
/*
@@ -869,6 +893,7 @@ static int __init kmalloc_tests_init(void)
kmalloc_double_kzfree();
vmalloc_oob();
kasan_rcu_uaf();
+ kasan_timer_uaf();
kasan_restore_multi_shot(multishot);
--
2.18.0
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next reply other threads:[~2020-08-10 7:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-10 7:26 Walter Wu [this message]
2020-08-10 7:26 ` [PATCH 3/5] lib/test_kasan.c: add timer test case Walter Wu
2020-08-10 7:26 ` Walter Wu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200810072620.747-1-walter-zh.wu@mediatek.com \
--to=walter-zh.wu@mediatek.com \
--cc=aryabinin@virtuozzo.com \
--cc=dvyukov@google.com \
--cc=glider@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-mm@kvack.org \
--cc=matthias.bgg@gmail.com \
--cc=wsd_upstream@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.