From: Wengang Wang <wen.gang.wang@oracle.com>
To: linux-mm@kvack.org, aryabinin@virtuozzo.com
Cc: wen.gang.wang@oracle.com, glider@google.com, dvyukov@google.com
Subject: [PATCH 5/5] mm/kasan: add advanced check test case
Date: Fri, 17 Nov 2017 14:30:43 -0800 [thread overview]
Message-ID: <20171117223043.7277-6-wen.gang.wang@oracle.com> (raw)
In-Reply-To: <20171117223043.7277-1-wen.gang.wang@oracle.com>
This patch is for Kasan advanced check feature.
It adds the advanced check test case in lib/test_kasan.
Signed-off-by: Wengang Wang <wen.gang.wang@oracle.com>
diff --git a/lib/test_kasan.c b/lib/test_kasan.c
index a25c976..0ff0101 100644
--- a/lib/test_kasan.c
+++ b/lib/test_kasan.c
@@ -473,6 +473,78 @@ static noinline void __init use_after_scope_test(void)
p[1023] = 1;
}
+static noinline void funcA(char *addr)
+{
+ *addr = 'A';
+}
+
+static noinline void funcB(char *addr)
+{
+ *addr = 'B';
+}
+
+static noinline void funcC(char *addr)
+{
+ *addr = 'C';
+}
+
+static noinline void __init kasan_adv(void)
+{
+ struct kasan_owner_set set;
+ int check, ret;
+ char *p;
+
+ pr_info("kasan: advanced check\n");
+
+ set.s_nr = 2;
+ set.s_ptrs[0] = (void *)funcA;
+ set.s_ptrs[1] = (void *)funcC;
+ check = kasan_register_adv_check(KASAN_ADVCHK_OWNER, &set);
+ if (check <= 0) {
+ pr_err("kasan_register_adv_check failedd with %d\n", check);
+ return;
+ }
+
+ p = kmalloc(62, GFP_KERNEL);
+ if (!p) {
+ pr_err("kmalloc failed with 62 bytes request\n");
+ return;
+ }
+
+ ret = kasan_bind_adv_addr(p, 32, check);
+ if (ret < 0) {
+ pr_err("kasan_bind_adv_addr failed with %d\n", ret);
+ kfree(p);
+ return;
+ }
+
+ funcA(&p[12]);
+ funcB(&p[12]);
+ funcC(&p[12]);
+
+ set.s_nr = 1;
+ set.s_ptrs[0] = (void *)funcA;
+
+ check = kasan_register_adv_check(KASAN_ADVCHK_OWNER, &set);
+ if (check <= 0) {
+ pr_err("kasan_register_adv_check failed with %d\n", check);
+ kfree(p);
+ return;
+ }
+
+ ret = kasan_bind_adv_addr(p+32, 30, check);
+ if (ret < 0) {
+ pr_err("kasan_bind_adv_addr failed with %d\n", ret);
+ kfree(p);
+ return;
+ }
+
+ funcA(&p[42]);
+ funcB(&p[42]);
+ funcC(&p[42]);
+
+ kfree(p);
+}
static int __init kmalloc_tests_init(void)
{
/*
@@ -506,6 +578,7 @@ static int __init kmalloc_tests_init(void)
ksize_unpoisons_memory();
copy_user_test();
use_after_scope_test();
+ kasan_adv();
kasan_restore_multi_shot(multishot);
--
2.9.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2017-11-17 22:30 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-17 22:30 [PATCH 0/5] mm/kasan: advanced check Wengang Wang
2017-11-17 22:30 ` [PATCH 1/5] mm/kasan: make space in shadow bytes for " Wengang Wang
2017-11-17 22:30 ` [PATCH 2/5] mm/kasan: pass access mode to poison check functions Wengang Wang
2017-11-17 22:30 ` [PATCH 3/5] mm/kasan: do advanced check Wengang Wang
2017-11-17 22:30 ` [PATCH 4/5] mm/kasan: register check and bind it to memory Wengang Wang
2017-11-17 22:30 ` Wengang Wang [this message]
2017-11-17 22:32 ` [PATCH 0/5] mm/kasan: advanced check Wengang Wang
2017-11-17 22:56 ` Dmitry Vyukov
2017-11-20 1:50 ` Joonsoo Kim
2017-11-20 8:41 ` Dmitry Vyukov
2017-11-20 20:05 ` Wengang
2017-11-20 20:20 ` Dmitry Vyukov
2017-11-20 20:29 ` Wengang
2017-11-21 9:54 ` Dmitry Vyukov
2017-11-21 19:17 ` Wengang Wang
2017-11-22 8:48 ` Dmitry Vyukov
2017-11-22 21:09 ` Wengang Wang
2017-11-20 19:56 ` Wengang
2017-11-22 4:30 ` Joonsoo Kim
2017-11-22 8:51 ` Dmitry Vyukov
2017-11-23 6:07 ` Joonsoo Kim
2017-11-22 19:43 ` Wengang Wang
2017-11-23 6:23 ` Joonsoo Kim
2017-11-23 6:35 ` Joonsoo Kim
2017-11-22 12:04 ` Andrey Ryabinin
2017-11-23 5:57 ` Joonsoo Kim
2017-11-22 12:04 ` Andrey Ryabinin
2017-11-22 19:29 ` Wengang Wang
2017-11-26 19:37 ` Wengang Wang
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=20171117223043.7277-6-wen.gang.wang@oracle.com \
--to=wen.gang.wang@oracle.com \
--cc=aryabinin@virtuozzo.com \
--cc=dvyukov@google.com \
--cc=glider@google.com \
--cc=linux-mm@kvack.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).