Skip to contentSkip to conversation

kasan: fix redzone overwritten issue under SLUB debug

PATCH Superseded [email protected] 1 participant 4 messages Jun 23, 2021

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#1 lore raw

PATCH v2 1/1 kasan: Add memzero init for unaligned size under SLUB debug

In reply to [email protected]

From: Yee Lee <[email protected]>

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.

Cc Andrey Ryabinin <[email protected]>
Cc Alexander Potapenko <[email protected]>
Cc Andrey Konovalov <[email protected]>
Cc Dmitry Vyukov <[email protected]>
Cc Andrew Morton <[email protected]>
---
 mm/kasan/kasan.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
mm/kasan/kasan.h +3 -1
index d8faa64614b7..e984a9ac814d 100644
@@ -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);
 }
Signature · 1 line
2.18.0
#0 lore raw

v2 cover kasan: fix redzone overwritten issue under SLUB debug

From: Yee Lee <[email protected]>

Issue: hwtag kasan_unpoison() would overwrite the redzone in those object with unaligned object size. This patch Adds memzero_explict() to separate the initialization for such condition. The new code path is executed about 1.1% during nromal booting process.

=============
Exp: QEMUv5.2(+mte)/SLUB_debug
code path exec : 941/80854 (1.1%)

---
Changed since v1:
- Apply IS_ENABLED to wrap codes under SLUB debug mode.
- Replace memset() by memzero_explict().

---
Yee Lee (1):
kasan: Add memzero init for unaligned size under SLUB debug

 mm/kasan/kasan.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Signature · 5 lines
2.18.0
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
author
#3 lore raw

Sorry not a completed patch.
please skip this mail.

BR,
Yee

Quoted 16 lines · On Wed, 2021-06-23 at 21:35 +0800, [email protected] wrote:

From: Yee Lee <[email protected]>

Issue: hwtag kasan_unpoison() would overwrite the redzone in those object with unaligned object size. This patch Adds memzero_explict() to separate the initialization for such condition. The new code path is executed about 1.1% during nromal booting process.

=============
Exp: QEMUv5.2(+mte)/SLUB_debug
code path exec : 941/80854 (1.1%)

---
Changed since v1:
- Apply IS_ENABLED to wrap codes under SLUB debug mode.
- Replace memset() by memzero_explict().

Quoted 7 lines

---
Yee Lee (1):
kasan: Add memzero init for unaligned size under SLUB debug

 mm/kasan/kasan.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek

author
#2 lore raw

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

In reply to [email protected]

Sorry not a completed patch.
Please skip this mail.

BR,
Yee

Quoted 39 lines · On Wed, 2021-06-23 at 21:35 +0800, [email protected] wrote:

From: Yee Lee <[email protected]>

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.

Cc Andrey Ryabinin <[email protected]>
Cc Alexander Potapenko <[email protected]>
Cc Andrey Konovalov <[email protected]>
Cc Dmitry Vyukov <[email protected]>
Cc Andrew Morton <[email protected]>
---
 mm/kasan/kasan.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
mm/kasan/kasan.h +3 -1
index d8faa64614b7..e984a9ac814d 100644
@@ -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);

}