diff mbox series

[v2,1/1] kasan: Add memzero init for unaligned size under SLUB debug

Message ID 20210623133533.2246-2-yee.lee@mediatek.com (mailing list archive)
State New
Headers show
Series [v2,1/1] kasan: Add memzero init for unaligned size under SLUB debug | expand

Commit Message

Yee Lee (李建誼) June 23, 2021, 1:35 p.m. UTC
From: Yee Lee <yee.lee@mediatek.com>

Issue: when SLUB debug is on, hwtag kasan_unpoison() would overwrite the redzone with unaligned object size.

An additional memzero_explicit() path is added to replacing hwtag initialization
at SLUB deubg mode.

Signed-off-by: Yee Lee <yee.lee@mediatek.com>
Suggested-by: Marco Elver <elver@google.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
 mm/kasan/kasan.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Yee Lee (李建誼) June 23, 2021, 1:52 p.m. UTC | #1
Sorry not a completed patch.
Please skip this mail.

BR,
Yee

On Wed, 2021-06-23 at 21:35 +0800, yee.lee@mediatek.com wrote:
> From: Yee Lee <yee.lee@mediatek.com>
> 
> Issue: when SLUB debug is on, hwtag kasan_unpoison() would overwrite
> the redzone with unaligned object size.
> 
> An additional memzero_explicit() path is added to replacing hwtag
> initialization
> at SLUB deubg mode.
> 
> Signed-off-by: Yee Lee <yee.lee@mediatek.com>
> Suggested-by: Marco Elver <elver@google.com>
> Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
> Cc: Alexander Potapenko <glider@google.com>
> Cc: Andrey Konovalov <andreyknvl@gmail.com>
> Cc: Dmitry Vyukov <dvyukov@google.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> ---
>  mm/kasan/kasan.h | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h
> index d8faa64614b7..e984a9ac814d 100644
> --- a/mm/kasan/kasan.h
> +++ b/mm/kasan/kasan.h
> @@ -387,10 +387,12 @@ static inline void kasan_unpoison(const void
> *addr, size_t size, bool init)
>  
>  	if (WARN_ON((unsigned long)addr & KASAN_GRANULE_MASK))
>  		return;
> +	#if IS_ENABLED(CONFIG_SLUB_DEBUG)
>  	if (init && ((unsigned long)size & KASAN_GRANULE_MASK)) {
>  		init = false;
> -		memset((void *)addr, 0, size);
> +		memzero_explicit((void *)addr, size);
>  	}
> +	#endif
>  	size = round_up(size, KASAN_GRANULE_SIZE);
>  	hw_set_mem_tag_range((void *)addr, size, tag, init);
>  }
diff mbox series

Patch

diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h
index d8faa64614b7..e984a9ac814d 100644
--- a/mm/kasan/kasan.h
+++ b/mm/kasan/kasan.h
@@ -387,10 +387,12 @@  static inline void kasan_unpoison(const void *addr, size_t size, bool init)
 
 	if (WARN_ON((unsigned long)addr & KASAN_GRANULE_MASK))
 		return;
+	#if IS_ENABLED(CONFIG_SLUB_DEBUG)
 	if (init && ((unsigned long)size & KASAN_GRANULE_MASK)) {
 		init = false;
-		memset((void *)addr, 0, size);
+		memzero_explicit((void *)addr, size);
 	}
+	#endif
 	size = round_up(size, KASAN_GRANULE_SIZE);
 	hw_set_mem_tag_range((void *)addr, size, tag, init);
 }