arm64 KASAN_HW_TAGS panic on non-MTE hardware on 5.12-rc1

Andrey Konovalov andreyknvl at google.com
Fri Mar 5 17:27:45 GMT 2021


On Fri, Mar 5, 2021 at 6:11 PM Catalin Marinas <catalin.marinas at arm.com> wrote:
>
> Hi Andrey,

Hi Catalin,

>
> Enabling CONFIG_KASAN_HW_TAGS and running the resulting kernel on
> non-MTE hardware panics with an undefined STG instruction from
> mte_set_mem_tag_range():
>
> ./scripts/faddr2line vmlinux kasan_unpoison_task_stack+0x18/0x40
> kasan_unpoison_task_stack+0x18/0x40:
> mte_set_mem_tag_range at arch/arm64/include/asm/mte-kasan.h:71
> (inlined by) mte_set_mem_tag_range at arch/arm64/include/asm/mte-kasan.h:56
> (inlined by) kasan_unpoison at mm/kasan/kasan.h:363
> (inlined by) kasan_unpoison_task_stack at mm/kasan/common.c:72

This is weird. kasan_unpoison_task_stack() is only defined when
CONFIG_KASAN_STACK is enabled, which shouldn't be enablable for
HW_TAGS.

Are you using the mainline kernel?

Could you share the kernel config that you use?

>
> The full trace:
>
> ------------[ cut here ]------------
> kernel BUG at arch/arm64/kernel/traps.c:406!
> Internal error: Oops - BUG: 0 [#1] PREEMPT SMP
> Modules linked in:
> CPU: 0 PID: 0 Comm: swapper Not tainted 5.12.0-rc1-00002-ge76afd1d69f3-dirty #2
> pstate: 00000085 (nzcv daIf -PAN -UAO -TCO BTYPE=--)
> pc : do_undefinstr+0x2c8/0x2e8
> lr : do_undefinstr+0x2d4/0x2e8
> sp : ffffc07baeaa3cf0
> x29: ffffc07baeaa3cf0 x28: ffffc07baeab3280
> x27: ffffc07baeaa9a00 x26: ffffc07baeaa7000
> x25: ffffc07baeab3964 x24: ffffc07baeaa9c00
> x23: 0000000040000085 x22: ffffc07baed7f0e0
> x21: 00000000d9200800 x20: ffffc07baeab3280
> x19: ffffc07baeaa3d80 x18: 0000000000000200
> x17: 000000000000000b x16: 0000000000007fff
> x15: 00000000ffffffff x14: 0000000000000000
> x13: 0000000000000048 x12: ffffc07baeab3280
> x11: ffff64d0ffc00294 x10: 0000000000000000
> x9 : 0000000000000000 x8 : 00000000389fd980
> x7 : ffff64d0ffbde5b8 x6 : 0000000000000000
> x5 : ffff64d0ffb99880 x4 : ffffc07baeab5710
> x3 : ffffc07baed7f0f0 x2 : 0000000000000000
> x1 : ffffc07baeab3280 x0 : 0000000040000085
> Call trace:
>  do_undefinstr+0x2c8/0x2e8
>  el1_undef+0x30/0x50
>  el1_sync_handler+0x8c/0xc8
>  el1_sync+0x70/0x100
>  kasan_unpoison_task_stack+0x18/0x40
>  sched_init+0x390/0x3f0
>  start_kernel+0x2cc/0x540
>  0x0
> Code: 17ffff8a f9401bf7 17ffffc8 f9001bf7 (d4210000)
> random: get_random_bytes called from print_oops_end_marker+0x2c/0x68 with crng_init=0
> ---[ end trace c881f708bdfe36c8 ]---
>
> If MTE is not available, I thought we should not end up calling the MTE
> backend but it seems that kasan expects the backend to skip the
> undefined instructions.
>
> Does kasan fall back to sw_tags if hw_tags are not available or it just
> disables kasan altogether?

If the hardware doesn't support HW_TAGS, KASAN should get disabled.

If the compiler doesn't support HW_TAGS, I think KASAN will fall back
to GENERIC through oldconfig.

Thanks!



More information about the linux-arm-kernel mailing list