linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH mm] fix for "kasan: improve vmalloc tests"
@ 2022-02-15 18:39 andrey.konovalov
  2022-02-16 10:01 ` Marco Elver
  0 siblings, 1 reply; 2+ messages in thread
From: andrey.konovalov @ 2022-02-15 18:39 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Andrey Konovalov, Marco Elver, Alexander Potapenko,
	Dmitry Vyukov, Andrey Ryabinin, kasan-dev, linux-mm,
	linux-kernel, Andrey Konovalov

From: Andrey Konovalov <andreyknvl@google.com>

vmap_tags() and vm_map_ram_tags() pass invalid page array size to
vm_map_ram() and vm_unmap_ram(). It's supposed to be 1, but it's
1 << order == 2 currently.

Remove order variable (it can only be 0 with the current code)
and hardcode the number of pages in these tests.

Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
---
 lib/test_kasan.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/lib/test_kasan.c b/lib/test_kasan.c
index 491a82006f06..8416161d5177 100644
--- a/lib/test_kasan.c
+++ b/lib/test_kasan.c
@@ -1149,7 +1149,6 @@ static void vmap_tags(struct kunit *test)
 {
 	char *p_ptr, *v_ptr;
 	struct page *p_page, *v_page;
-	size_t order = 1;
 
 	/*
 	 * This test is specifically crafted for the software tag-based mode,
@@ -1159,12 +1158,12 @@ static void vmap_tags(struct kunit *test)
 
 	KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_VMALLOC);
 
-	p_page = alloc_pages(GFP_KERNEL, order);
+	p_page = alloc_pages(GFP_KERNEL, 1);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p_page);
 	p_ptr = page_address(p_page);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p_ptr);
 
-	v_ptr = vmap(&p_page, 1 << order, VM_MAP, PAGE_KERNEL);
+	v_ptr = vmap(&p_page, 1, VM_MAP, PAGE_KERNEL);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, v_ptr);
 
 	/*
@@ -1186,14 +1185,13 @@ static void vmap_tags(struct kunit *test)
 	KUNIT_EXPECT_PTR_EQ(test, p_page, v_page);
 
 	vunmap(v_ptr);
-	free_pages((unsigned long)p_ptr, order);
+	free_pages((unsigned long)p_ptr, 1);
 }
 
 static void vm_map_ram_tags(struct kunit *test)
 {
 	char *p_ptr, *v_ptr;
 	struct page *page;
-	size_t order = 1;
 
 	/*
 	 * This test is specifically crafted for the software tag-based mode,
@@ -1201,12 +1199,12 @@ static void vm_map_ram_tags(struct kunit *test)
 	 */
 	KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_SW_TAGS);
 
-	page = alloc_pages(GFP_KERNEL, order);
+	page = alloc_pages(GFP_KERNEL, 1);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, page);
 	p_ptr = page_address(page);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p_ptr);
 
-	v_ptr = vm_map_ram(&page, 1 << order, -1);
+	v_ptr = vm_map_ram(&page, 1, -1);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, v_ptr);
 
 	KUNIT_EXPECT_GE(test, (u8)get_tag(v_ptr), (u8)KASAN_TAG_MIN);
@@ -1216,8 +1214,8 @@ static void vm_map_ram_tags(struct kunit *test)
 	*p_ptr = 0;
 	*v_ptr = 0;
 
-	vm_unmap_ram(v_ptr, 1 << order);
-	free_pages((unsigned long)p_ptr, order);
+	vm_unmap_ram(v_ptr, 1);
+	free_pages((unsigned long)p_ptr, 1);
 }
 
 static void vmalloc_percpu(struct kunit *test)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH mm] fix for "kasan: improve vmalloc tests"
  2022-02-15 18:39 [PATCH mm] fix for "kasan: improve vmalloc tests" andrey.konovalov
@ 2022-02-16 10:01 ` Marco Elver
  0 siblings, 0 replies; 2+ messages in thread
From: Marco Elver @ 2022-02-16 10:01 UTC (permalink / raw)
  To: andrey.konovalov
  Cc: Andrew Morton, Andrey Konovalov, Alexander Potapenko,
	Dmitry Vyukov, Andrey Ryabinin, kasan-dev, linux-mm,
	linux-kernel, Andrey Konovalov

On Tue, 15 Feb 2022 at 19:39, <andrey.konovalov@linux.dev> wrote:
>
> From: Andrey Konovalov <andreyknvl@google.com>
>
> vmap_tags() and vm_map_ram_tags() pass invalid page array size to
> vm_map_ram() and vm_unmap_ram(). It's supposed to be 1, but it's
> 1 << order == 2 currently.
>
> Remove order variable (it can only be 0 with the current code)
> and hardcode the number of pages in these tests.
>
> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>

Acked-by: Marco Elver <elver@google.com>


> ---
>  lib/test_kasan.c | 16 +++++++---------
>  1 file changed, 7 insertions(+), 9 deletions(-)
>
> diff --git a/lib/test_kasan.c b/lib/test_kasan.c
> index 491a82006f06..8416161d5177 100644
> --- a/lib/test_kasan.c
> +++ b/lib/test_kasan.c
> @@ -1149,7 +1149,6 @@ static void vmap_tags(struct kunit *test)
>  {
>         char *p_ptr, *v_ptr;
>         struct page *p_page, *v_page;
> -       size_t order = 1;
>
>         /*
>          * This test is specifically crafted for the software tag-based mode,
> @@ -1159,12 +1158,12 @@ static void vmap_tags(struct kunit *test)
>
>         KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_VMALLOC);
>
> -       p_page = alloc_pages(GFP_KERNEL, order);
> +       p_page = alloc_pages(GFP_KERNEL, 1);
>         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p_page);
>         p_ptr = page_address(p_page);
>         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p_ptr);
>
> -       v_ptr = vmap(&p_page, 1 << order, VM_MAP, PAGE_KERNEL);
> +       v_ptr = vmap(&p_page, 1, VM_MAP, PAGE_KERNEL);
>         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, v_ptr);
>
>         /*
> @@ -1186,14 +1185,13 @@ static void vmap_tags(struct kunit *test)
>         KUNIT_EXPECT_PTR_EQ(test, p_page, v_page);
>
>         vunmap(v_ptr);
> -       free_pages((unsigned long)p_ptr, order);
> +       free_pages((unsigned long)p_ptr, 1);
>  }
>
>  static void vm_map_ram_tags(struct kunit *test)
>  {
>         char *p_ptr, *v_ptr;
>         struct page *page;
> -       size_t order = 1;
>
>         /*
>          * This test is specifically crafted for the software tag-based mode,
> @@ -1201,12 +1199,12 @@ static void vm_map_ram_tags(struct kunit *test)
>          */
>         KASAN_TEST_NEEDS_CONFIG_ON(test, CONFIG_KASAN_SW_TAGS);
>
> -       page = alloc_pages(GFP_KERNEL, order);
> +       page = alloc_pages(GFP_KERNEL, 1);
>         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, page);
>         p_ptr = page_address(page);
>         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, p_ptr);
>
> -       v_ptr = vm_map_ram(&page, 1 << order, -1);
> +       v_ptr = vm_map_ram(&page, 1, -1);
>         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, v_ptr);
>
>         KUNIT_EXPECT_GE(test, (u8)get_tag(v_ptr), (u8)KASAN_TAG_MIN);
> @@ -1216,8 +1214,8 @@ static void vm_map_ram_tags(struct kunit *test)
>         *p_ptr = 0;
>         *v_ptr = 0;
>
> -       vm_unmap_ram(v_ptr, 1 << order);
> -       free_pages((unsigned long)p_ptr, order);
> +       vm_unmap_ram(v_ptr, 1);
> +       free_pages((unsigned long)p_ptr, 1);
>  }
>
>  static void vmalloc_percpu(struct kunit *test)
> --
> 2.25.1
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-02-16 10:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-15 18:39 [PATCH mm] fix for "kasan: improve vmalloc tests" andrey.konovalov
2022-02-16 10:01 ` Marco Elver

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).