* [PATCHv2] lib/test_kasan: add roundtrip tests
@ 2019-08-19 16:14 Mark Rutland
2019-08-19 17:25 ` Andrey Ryabinin
2019-08-22 23:48 ` Andrew Morton
0 siblings, 2 replies; 5+ messages in thread
From: Mark Rutland @ 2019-08-19 16:14 UTC (permalink / raw)
To: linux-kernel
Cc: Mark Rutland, Alexander Potapenko, Andrew Morton,
Andrey Ryabinin, Dmitry Vyukov, Will Deacon
In several places we need to be able to operate on pointers which have
gone via a roundtrip:
virt -> {phys,page} -> virt
With KASAN_SW_TAGS, we can't preserve the tag for SLUB objects, and the
{phys,page} -> virt conversion will use KASAN_TAG_KERNEL.
This patch adds tests to ensure that this works as expected, without
false positives which have recently been spotted [1,2] in testing.
[1] https://lore.kernel.org/linux-arm-kernel/20190819114420.2535-1-walter-zh.wu@mediatek.com/
[2] https://lore.kernel.org/linux-arm-kernel/20190819132347.GB9927@lakrids.cambridge.arm.com/
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Andrey Konovalov <andreyknvl@google.com>
Tested-by: Andrey Konovalov <andreyknvl@google.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Will Deacon <will.deacon@arm.com>
---
lib/test_kasan.c | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
Since v1:
* Spin as a separate patch
* Fix typo
* Note examples in commit message.
Mark.
diff --git a/lib/test_kasan.c b/lib/test_kasan.c
index b63b367a94e8..cf7b93f0d90c 100644
--- a/lib/test_kasan.c
+++ b/lib/test_kasan.c
@@ -19,6 +19,8 @@
#include <linux/string.h>
#include <linux/uaccess.h>
+#include <asm/page.h>
+
/*
* Note: test functions are marked noinline so that their names appear in
* reports.
@@ -337,6 +339,42 @@ static noinline void __init kmalloc_uaf2(void)
kfree(ptr2);
}
+static noinline void __init kfree_via_page(void)
+{
+ char *ptr;
+ size_t size = 8;
+ struct page *page;
+ unsigned long offset;
+
+ pr_info("invalid-free false positive (via page)\n");
+ ptr = kmalloc(size, GFP_KERNEL);
+ if (!ptr) {
+ pr_err("Allocation failed\n");
+ return;
+ }
+
+ page = virt_to_page(ptr);
+ offset = offset_in_page(ptr);
+ kfree(page_address(page) + offset);
+}
+
+static noinline void __init kfree_via_phys(void)
+{
+ char *ptr;
+ size_t size = 8;
+ phys_addr_t phys;
+
+ pr_info("invalid-free false positive (via phys)\n");
+ ptr = kmalloc(size, GFP_KERNEL);
+ if (!ptr) {
+ pr_err("Allocation failed\n");
+ return;
+ }
+
+ phys = virt_to_phys(ptr);
+ kfree(phys_to_virt(phys));
+}
+
static noinline void __init kmem_cache_oob(void)
{
char *p;
@@ -737,6 +775,8 @@ static int __init kmalloc_tests_init(void)
kmalloc_uaf();
kmalloc_uaf_memset();
kmalloc_uaf2();
+ kfree_via_page();
+ kfree_via_phys();
kmem_cache_oob();
memcg_accounted_kmem_cache();
kasan_stack_oob();
--
2.11.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCHv2] lib/test_kasan: add roundtrip tests
2019-08-19 16:14 [PATCHv2] lib/test_kasan: add roundtrip tests Mark Rutland
@ 2019-08-19 17:25 ` Andrey Ryabinin
2019-08-22 23:48 ` Andrew Morton
1 sibling, 0 replies; 5+ messages in thread
From: Andrey Ryabinin @ 2019-08-19 17:25 UTC (permalink / raw)
To: Mark Rutland, linux-kernel
Cc: Alexander Potapenko, Andrew Morton, Dmitry Vyukov, Will Deacon,
Andrey Konovalov
On 8/19/19 7:14 PM, Mark Rutland wrote:
> In several places we need to be able to operate on pointers which have
> gone via a roundtrip:
>
> virt -> {phys,page} -> virt
>
> With KASAN_SW_TAGS, we can't preserve the tag for SLUB objects, and the
> {phys,page} -> virt conversion will use KASAN_TAG_KERNEL.
>
> This patch adds tests to ensure that this works as expected, without
> false positives which have recently been spotted [1,2] in testing.
>
> [1] https://lore.kernel.org/linux-arm-kernel/20190819114420.2535-1-walter-zh.wu@mediatek.com/
> [2] https://lore.kernel.org/linux-arm-kernel/20190819132347.GB9927@lakrids.cambridge.arm.com/
>
> Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> Reviewed-by: Andrey Konovalov <andreyknvl@google.com>
> Tested-by: Andrey Konovalov <andreyknvl@google.com>
> Cc: Alexander Potapenko <glider@google.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
> Cc: Dmitry Vyukov <dvyukov@google.com>
> Cc: Will Deacon <will.deacon@arm.com>
> ---
Acked-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCHv2] lib/test_kasan: add roundtrip tests
2019-08-19 16:14 [PATCHv2] lib/test_kasan: add roundtrip tests Mark Rutland
2019-08-19 17:25 ` Andrey Ryabinin
@ 2019-08-22 23:48 ` Andrew Morton
2019-08-23 10:41 ` Mark Rutland
1 sibling, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2019-08-22 23:48 UTC (permalink / raw)
To: Mark Rutland
Cc: linux-kernel, Alexander Potapenko, Andrey Ryabinin,
Dmitry Vyukov, Will Deacon
On Mon, 19 Aug 2019 17:14:49 +0100 Mark Rutland <mark.rutland@arm.com> wrote:
> In several places we need to be able to operate on pointers which have
> gone via a roundtrip:
>
> virt -> {phys,page} -> virt
>
> With KASAN_SW_TAGS, we can't preserve the tag for SLUB objects, and the
> {phys,page} -> virt conversion will use KASAN_TAG_KERNEL.
>
> This patch adds tests to ensure that this works as expected, without
> false positives which have recently been spotted [1,2] in testing.
>
> [1] https://lore.kernel.org/linux-arm-kernel/20190819114420.2535-1-walter-zh.wu@mediatek.com/
> [2] https://lore.kernel.org/linux-arm-kernel/20190819132347.GB9927@lakrids.cambridge.arm.com/
>
>
> ...
>
The only change I'm seeing from v1 is:
--- a/lib/test_kasan.c~lib-test_kasan-add-roundtrip-tests-v2
+++ a/lib/test_kasan.c
@@ -19,7 +19,6 @@
#include <linux/string.h>
#include <linux/uaccess.h>
-#include <asm/io.h>
#include <asm/page.h>
/*
which is really kinda wrong. We should strictly include linux/io.h for
things like virt_to_phys().
So I think I'll stick with v1 plus my fixlet:
--- a/lib/test_kasan.c~lib-test_kasan-add-roundtrip-tests-checkpatch-fixes
+++ a/lib/test_kasan.c
@@ -18,8 +18,8 @@
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/uaccess.h>
+#include <linux/io.h>
-#include <asm/io.h>
#include <asm/page.h>
/*
> Since v1:
> * Spin as a separate patch
> * Fix typo
> * Note examples in commit message.
So I'm not sure what happened to these things. Did you send the correct
patch?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCHv2] lib/test_kasan: add roundtrip tests
2019-08-22 23:48 ` Andrew Morton
@ 2019-08-23 10:41 ` Mark Rutland
2019-08-24 20:30 ` Andrew Morton
0 siblings, 1 reply; 5+ messages in thread
From: Mark Rutland @ 2019-08-23 10:41 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-kernel, Alexander Potapenko, Andrey Ryabinin,
Dmitry Vyukov, Will Deacon
Hi Andrew,
On Thu, Aug 22, 2019 at 04:48:57PM -0700, Andrew Morton wrote:
> On Mon, 19 Aug 2019 17:14:49 +0100 Mark Rutland <mark.rutland@arm.com> wrote:
>
> > In several places we need to be able to operate on pointers which have
> > gone via a roundtrip:
> >
> > virt -> {phys,page} -> virt
> >
> > With KASAN_SW_TAGS, we can't preserve the tag for SLUB objects, and the
> > {phys,page} -> virt conversion will use KASAN_TAG_KERNEL.
> >
> > This patch adds tests to ensure that this works as expected, without
> > false positives which have recently been spotted [1,2] in testing.
> >
> > [1] https://lore.kernel.org/linux-arm-kernel/20190819114420.2535-1-walter-zh.wu@mediatek.com/
> > [2] https://lore.kernel.org/linux-arm-kernel/20190819132347.GB9927@lakrids.cambridge.arm.com/
> >
> >
> > ...
> >
>
> The only change I'm seeing from v1 is:
>
> --- a/lib/test_kasan.c~lib-test_kasan-add-roundtrip-tests-v2
> +++ a/lib/test_kasan.c
> @@ -19,7 +19,6 @@
> #include <linux/string.h>
> #include <linux/uaccess.h>
>
> -#include <asm/io.h>
> #include <asm/page.h>
I think you've confused v1 with v3 (which was the first version to
include <asm/io.h>).
v1: https://lore.kernel.org/linux-arm-kernel/20190819150341.GC9927@lakrids.cambridge.arm.com/
v3: https://lore.kernel.org/linux-arm-kernel/20190819150341.GC9927@lakrids.cambridge.arm.com/
I guess as v1 was part of a reply (without the mail subject matching)
that might have confused things? Sorry about that if so!
>
> /*
>
> which is really kinda wrong. We should strictly include linux/io.h for
> things like virt_to_phys().
>
> So I think I'll stick with v1 plus my fixlet:
>
> --- a/lib/test_kasan.c~lib-test_kasan-add-roundtrip-tests-checkpatch-fixes
> +++ a/lib/test_kasan.c
> @@ -18,8 +18,8 @@
> #include <linux/slab.h>
> #include <linux/string.h>
> #include <linux/uaccess.h>
> +#include <linux/io.h>
>
> -#include <asm/io.h>
> #include <asm/page.h>
>
> /*
>
Assuming that you mean *v3* with that fix, that looks good to me!
Thanks,
Mark.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCHv2] lib/test_kasan: add roundtrip tests
2019-08-23 10:41 ` Mark Rutland
@ 2019-08-24 20:30 ` Andrew Morton
0 siblings, 0 replies; 5+ messages in thread
From: Andrew Morton @ 2019-08-24 20:30 UTC (permalink / raw)
To: Mark Rutland
Cc: linux-kernel, Alexander Potapenko, Andrey Ryabinin,
Dmitry Vyukov, Will Deacon
On Fri, 23 Aug 2019 11:41:08 +0100 Mark Rutland <mark.rutland@arm.com> wrote:
> >
> > /*
> >
> > which is really kinda wrong. We should strictly include linux/io.h for
> > things like virt_to_phys().
> >
> > So I think I'll stick with v1 plus my fixlet:
> >
> > --- a/lib/test_kasan.c~lib-test_kasan-add-roundtrip-tests-checkpatch-fixes
> > +++ a/lib/test_kasan.c
> > @@ -18,8 +18,8 @@
> > #include <linux/slab.h>
> > #include <linux/string.h>
> > #include <linux/uaccess.h>
> > +#include <linux/io.h>
> >
> > -#include <asm/io.h>
> > #include <asm/page.h>
> >
> > /*
> >
>
> Assuming that you mean *v3* with that fix, that looks good to me!
Yes, that's what we have.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-08-24 20:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-19 16:14 [PATCHv2] lib/test_kasan: add roundtrip tests Mark Rutland
2019-08-19 17:25 ` Andrey Ryabinin
2019-08-22 23:48 ` Andrew Morton
2019-08-23 10:41 ` Mark Rutland
2019-08-24 20:30 ` Andrew Morton
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).