diff mbox

[v1,15/16] khwasan, mm, arm64: tag non slab memory allocated via pagealloc

Message ID 0043ffdf-4a75-d41c-966e-073eac3dc557@virtuozzo.com (mailing list archive)
State New, archived
Headers show

Commit Message

Andrey Ryabinin May 15, 2018, 2:06 p.m. UTC
On 05/08/2018 08:21 PM, Andrey Konovalov wrote:

> +#ifndef CONFIG_KASAN_HW
>  #define page_to_virt(page)	((void *)((__page_to_voff(page)) | PAGE_OFFSET))
> +#else
> +#define page_to_virt(page)	({					\
> +	unsigned long __addr =						\
> +		((__page_to_voff(page)) | PAGE_OFFSET);			\
> +	if (!PageSlab((struct page *)page))				\
> +		__addr = KASAN_SET_TAG(__addr, page_kasan_tag(page));	\

You could avoid 'if (!PageSlab())' check by adding page_kasan_tag_reset() into kasan_poison_slab().


> +	((void *)__addr);						\
> +})
> +#endif
> +
>  #define virt_to_page(vaddr)	((struct page *)((__virt_to_pgoff(vaddr)) | VMEMMAP_START))
>  
>  #define _virt_addr_valid(kaddr)	pfn_valid((((u64)(kaddr) & ~PAGE_OFFSET) \



> diff --git a/mm/cma.c b/mm/cma.c
> index aa40e6c7b042..f657db289bba 100644
> --- a/mm/cma.c
> +++ b/mm/cma.c
> @@ -526,6 +526,7 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align,
>  	}
>  
>  	trace_cma_alloc(pfn, page, count, align);
> +	page_kasan_tag_reset(page);
  

Why? Comment needed.


>  	if (ret && !(gfp_mask & __GFP_NOWARN)) {
>  		pr_err("%s: alloc failed, req-size: %zu pages, ret: %d\n",
> diff --git a/mm/kasan/common.c b/mm/kasan/common.c
> index 0654bf97257b..7cd4a4e8c3be 100644
> --- a/mm/kasan/common.c
> +++ b/mm/kasan/common.c
> @@ -207,8 +207,18 @@ void kasan_unpoison_stack_above_sp_to(const void *watermark)
>  
>  void kasan_alloc_pages(struct page *page, unsigned int order)
>  {
> +#ifdef CONFIG_KASAN_GENERIC
>  	if (likely(!PageHighMem(page)))
>  		kasan_unpoison_shadow(page_address(page), PAGE_SIZE << order);
> +#else
> +	if (!PageSlab(page)) {
> +		u8 tag = random_tag();
> +
> +		kasan_poison_shadow(page_address(page), PAGE_SIZE << order,
> +					tag);
> +		page_kasan_tag_set(page, tag);
> +	}
> +#endif
>  }

Comments

Andrey Konovalov May 25, 2018, 12:44 p.m. UTC | #1
On Tue, May 15, 2018 at 4:06 PM, Andrey Ryabinin
<aryabinin@virtuozzo.com> wrote:
>
> You could avoid 'if (!PageSlab())' check by adding page_kasan_tag_reset() into kasan_poison_slab().

>> @@ -526,6 +526,7 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align,
>>       }
>>
>>       trace_cma_alloc(pfn, page, count, align);
>> +     page_kasan_tag_reset(page);
>
>
> Why? Comment needed.

> diff --git a/mm/kasan/common.c b/mm/kasan/common.c
> index b8e0a8215021..f9f2181164a2 100644
> --- a/mm/kasan/common.c
> +++ b/mm/kasan/common.c
> @@ -207,18 +207,11 @@ void kasan_unpoison_stack_above_sp_to(const void *watermark)
>
>  void kasan_alloc_pages(struct page *page, unsigned int order)
>  {
> -#ifdef CONFIG_KASAN_GENERIC
> -       if (likely(!PageHighMem(page)))
> -               kasan_unpoison_shadow(page_address(page), PAGE_SIZE << order);
> -#else
> -       if (!PageSlab(page)) {
> -               u8 tag = random_tag();
> +       if (unlikely(PageHighMem(page)))
> +               return;
>
> -               kasan_poison_shadow(page_address(page), PAGE_SIZE << order,
> -                                       tag);
> -               page_kasan_tag_set(page, tag);
> -       }
> -#endif
> +       page_kasan_tag_set(page, random_tag());
> +       kasan_unpoison_shadow(page_address(page), PAGE_SIZE << order);
>  }
>
>  void kasan_free_pages(struct page *page, unsigned int order)

> As already said before no changes needed in kasan_kmalloc_large. kasan_alloc_pages() alredy did tag_set().

Will fix all in v2, thanks!
diff mbox

Patch

diff --git a/mm/kasan/common.c b/mm/kasan/common.c
index b8e0a8215021..f9f2181164a2 100644
--- a/mm/kasan/common.c
+++ b/mm/kasan/common.c
@@ -207,18 +207,11 @@  void kasan_unpoison_stack_above_sp_to(const void *watermark)
 
 void kasan_alloc_pages(struct page *page, unsigned int order)
 {
-#ifdef CONFIG_KASAN_GENERIC
-	if (likely(!PageHighMem(page)))
-		kasan_unpoison_shadow(page_address(page), PAGE_SIZE << order);
-#else
-	if (!PageSlab(page)) {
-		u8 tag = random_tag();
+	if (unlikely(PageHighMem(page)))
+		return;
 
-		kasan_poison_shadow(page_address(page), PAGE_SIZE << order,
-					tag);
-		page_kasan_tag_set(page, tag);
-	}
-#endif
+	page_kasan_tag_set(page, random_tag());
+	kasan_unpoison_shadow(page_address(page), PAGE_SIZE << order);
 }
 
 void kasan_free_pages(struct page *page, unsigned int order)