kasan: fixes for 5.11-rc
Subsystems (3)
v2 cover kasan: fixes for 5.11-rc
Changes v1->v2:
- Update changelog of patch #1.
Andrey Konovalov (2):
kasan, mm: fix conflicts with init_on_alloc/free kasan, arm64: fix pointer tags in KASAN reports
arch/arm64/mm/fault.c | 2 ++ mm/slub.c | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-)
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7-goog
PATCH v2 1/2 kasan, mm: fix conflicts with init_on_alloc/free
A few places where SLUB accesses object's data or metadata were missed in a previous patch. This leads to false positives with hardware tag-based KASAN when bulk allocations are used with init_on_alloc/free.
Fix the false-positives by resetting pointer tags during these accesses.
(The kasan_reset_tag call is removed from slab_alloc_node, as it's added
into maybe_wipe_obj_freeptr.)
--- mm/slub.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
mm/slub.c +4 -3
@@ -2791,7 +2791,8 @@ static __always_inline void maybe_wipe_obj_freeptr(struct kmem_cache *s, void *obj) {if (unlikely (slab_want_init_on_free (s)) && obj) -memset ((void *)((char *)obj + s->offset),0 ,sizeof (void *)); +memset ((void *)((char *)kasan_reset_tag (obj) + s->offset), +0 ,sizeof (void *)); }/*
@@ -2883,7 +2884,7 @@ static __always_inline void *slab_alloc_node(struct kmem_cache *s,stat (s,ALLOC_FASTPATH ); } -maybe_wipe_obj_freeptr (s,kasan_reset_tag (object)); +maybe_wipe_obj_freeptr (s, object);if (unlikely (slab_want_init_on_alloc (gfpflags, s)) && object)memset (kasan_reset_tag (object),0 , s->object_size);
@@ -3329,7 +3330,7 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,int j;for (j =0 ; j < i; j++) -memset (p[j],0 , s->object_size); +memset (kasan_reset_tag (p[j]),0 , s->object_size); }/* memcg and kmem_cache debug support */
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7-goog
PATCH v2 2/2 kasan, arm64: fix pointer tags in KASAN reports
In reply to Andrey KonovalovAs of the "arm64: expose FAR_EL1 tag bits in siginfo" patch, the address that is passed to report_tag_fault has pointer tags in the format of 0x0X, while KASAN uses 0xFX format (note the difference in the top 4 bits).
Fix up the pointer tag before calling kasan_report.
--- arch/arm64/mm/fault.c | 2 ++ 1 file changed, 2 insertions(+)
arch/arm64/mm/fault.c +2 -0
@@ -304,6 +304,8 @@ static void report_tag_fault(unsigned long addr, unsigned int esr, {bool is_write = ((esr & ESR_ELx_WNR) >> ESR_ELx_WNR_SHIFT) !=0 ; +/* The format of KASAN tags is 0xF<x>. */ + addr |= (0xF0UL <<MTE_TAG_SHIFT );/* * SAS bits aren't set for all faults reported in EL1, so we can't * find out access size.
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7-goog
Catalin Marinas
maintainerRe: [PATCH v2 2/2] kasan, arm64: fix pointer tags in KASAN reports
Quoted 19 lines · Andrey Konovalov
As of the "arm64: expose
FAR_EL1tag bits in siginfo" patch, the address that is passed toreport_tag_faulthas pointer tags in the format of 0x0X, while KASAN uses 0xFX format (note the difference in the top 4 bits).Fix up the pointer tag before calling
kasan_report.Fixes dceec3ff7807 ("arm64: expose FAR_EL1 tag bits in siginfo")Fixes 4291e9ee6189 ("kasan, arm64: print report from tag fault handler")Signed-off-by Andrey Konovalov <[email protected]>--- arch/arm64/mm/fault.c | 2 ++ 1 file changed, 2 insertions(+)arch/arm64/mm/fault.c +0
-0
arch/arm64/mm/fault.c static void report_tag_fault(unsigned long addr, unsigned int esr, · line 311
Quoted 8 lines
arch/arm64/mm/fault.c +2
-0@@ -304,6 +304,8 @@ static void report_tag_fault(unsigned long addr, unsigned int esr, {bool is_write = ((esr & ESR_ELx_WNR) >> ESR_ELx_WNR_SHIFT) !=0 ; +/* The format of KASAN tags is 0xF<x>. */ + addr |= (0xF0UL <<MTE_TAG_SHIFT );/* * SAS bits aren't set for all faults reported in EL1, so we can't * find out access size.
I already replied here but I don't see any change in v2:
https://lore.kernel.org/linux-arm-kernel/20210113165441.GC27045@gaia/
Signature · 1 line
Catalin
Re: [PATCH v2 2/2] kasan, arm64: fix pointer tags in KASAN reports
Quoted 32 lines · Catalin Marinas
Quoted 19 lines · Andrey Konovalov
As of the "arm64: expose
FAR_EL1tag bits in siginfo" patch, the address that is passed toreport_tag_faulthas pointer tags in the format of 0x0X, while KASAN uses 0xFX format (note the difference in the top 4 bits).Fix up the pointer tag before calling
kasan_report.Fixes dceec3ff7807 ("arm64: expose FAR_EL1 tag bits in siginfo")Fixes 4291e9ee6189 ("kasan, arm64: print report from tag fault handler")Signed-off-by Andrey Konovalov <[email protected]>--- arch/arm64/mm/fault.c | 2 ++ 1 file changed, 2 insertions(+)arch/arm64/mm/fault.c +0
-0arch/arm64/mm/fault.c static void report_tag_fault(unsigned long addr, unsigned int esr, · line 311
Quoted 8 lines
arch/arm64/mm/fault.c +2
-0@@ -304,6 +304,8 @@ static void report_tag_fault(unsigned long addr, unsigned int esr, {bool is_write = ((esr & ESR_ELx_WNR) >> ESR_ELx_WNR_SHIFT) !=0 ; +/* The format of KASAN tags is 0xF<x>. */ + addr |= (0xF0UL <<MTE_TAG_SHIFT );/* * SAS bits aren't set for all faults reported in EL1, so we can't * find out access size. I already replied here but I don't see any change in v2:
Hi Catalin,
Sorry, Gmail decided to mark all your emails as spam for some reason, so I didn't see any of them :(
I'll fix this in v3.
Thanks!