Mark Rutland
29083fd84d
kasan: hw_tags: avoid invalid virt_to_page()
...
When booting with 'kasan.vmalloc=off', a kernel configured with support
for KASAN_HW_TAGS will explode at boot time due to bogus use of
virt_to_page() on a vmalloc adddress. With CONFIG_DEBUG_VIRTUAL selected
this will be reported explicitly, and with or without CONFIG_DEBUG_VIRTUAL
the kernel will dereference a bogus address:
| ------------[ cut here ]------------
| virt_to_phys used for non-linear address: (____ptrval____) (0xffff800008000000)
| WARNING: CPU: 0 PID: 0 at arch/arm64/mm/physaddr.c:15 __virt_to_phys+0x78/0x80
| Modules linked in:
| CPU: 0 PID: 0 Comm: swapper/0 Not tainted 6.3.0-rc3-00073-g83865133300d-dirty #4
| Hardware name: linux,dummy-virt (DT)
| pstate: 600000c5 (nZCv daIF -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
| pc : __virt_to_phys+0x78/0x80
| lr : __virt_to_phys+0x78/0x80
| sp : ffffcd076afd3c80
| x29: ffffcd076afd3c80 x28: 0068000000000f07 x27: ffff800008000000
| x26: fffffbfff0000000 x25: fffffbffff000000 x24: ff00000000000000
| x23: ffffcd076ad3c000 x22: fffffc0000000000 x21: ffff800008000000
| x20: ffff800008004000 x19: ffff800008000000 x18: ffff800008004000
| x17: 666678302820295f x16: ffffffffffffffff x15: 0000000000000004
| x14: ffffcd076b009e88 x13: 0000000000000fff x12: 0000000000000003
| x11: 00000000ffffefff x10: c0000000ffffefff x9 : 0000000000000000
| x8 : 0000000000000000 x7 : 205d303030303030 x6 : 302e30202020205b
| x5 : ffffcd076b41d63f x4 : ffffcd076afd3827 x3 : 0000000000000000
| x2 : 0000000000000000 x1 : ffffcd076afd3a30 x0 : 000000000000004f
| Call trace:
| __virt_to_phys+0x78/0x80
| __kasan_unpoison_vmalloc+0xd4/0x478
| __vmalloc_node_range+0x77c/0x7b8
| __vmalloc_node+0x54/0x64
| init_IRQ+0x94/0xc8
| start_kernel+0x194/0x420
| __primary_switched+0xbc/0xc4
| ---[ end trace 0000000000000000 ]---
| Unable to handle kernel paging request at virtual address 03fffacbe27b8000
| Mem abort info:
| ESR = 0x0000000096000004
| EC = 0x25: DABT (current EL), IL = 32 bits
| SET = 0, FnV = 0
| EA = 0, S1PTW = 0
| FSC = 0x04: level 0 translation fault
| Data abort info:
| ISV = 0, ISS = 0x00000004
| CM = 0, WnR = 0
| swapper pgtable: 4k pages, 48-bit VAs, pgdp=0000000041bc5000
| [03fffacbe27b8000] pgd=0000000000000000, p4d=0000000000000000
| Internal error: Oops: 0000000096000004 [#1 ] PREEMPT SMP
| Modules linked in:
| CPU: 0 PID: 0 Comm: swapper/0 Tainted: G W 6.3.0-rc3-00073-g83865133300d-dirty #4
| Hardware name: linux,dummy-virt (DT)
| pstate: 200000c5 (nzCv daIF -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
| pc : __kasan_unpoison_vmalloc+0xe4/0x478
| lr : __kasan_unpoison_vmalloc+0xd4/0x478
| sp : ffffcd076afd3ca0
| x29: ffffcd076afd3ca0 x28: 0068000000000f07 x27: ffff800008000000
| x26: 0000000000000000 x25: 03fffacbe27b8000 x24: ff00000000000000
| x23: ffffcd076ad3c000 x22: fffffc0000000000 x21: ffff800008000000
| x20: ffff800008004000 x19: ffff800008000000 x18: ffff800008004000
| x17: 666678302820295f x16: ffffffffffffffff x15: 0000000000000004
| x14: ffffcd076b009e88 x13: 0000000000000fff x12: 0000000000000001
| x11: 0000800008000000 x10: ffff800008000000 x9 : ffffb2f8dee00000
| x8 : 000ffffb2f8dee00 x7 : 205d303030303030 x6 : 302e30202020205b
| x5 : ffffcd076b41d63f x4 : ffffcd076afd3827 x3 : 0000000000000000
| x2 : 0000000000000000 x1 : ffffcd076afd3a30 x0 : ffffb2f8dee00000
| Call trace:
| __kasan_unpoison_vmalloc+0xe4/0x478
| __vmalloc_node_range+0x77c/0x7b8
| __vmalloc_node+0x54/0x64
| init_IRQ+0x94/0xc8
| start_kernel+0x194/0x420
| __primary_switched+0xbc/0xc4
| Code: d34cfc08 aa1f03fa 8b081b39 d503201f (f9400328)
| ---[ end trace 0000000000000000 ]---
| Kernel panic - not syncing: Attempted to kill the idle task!
This is because init_vmalloc_pages() erroneously calls virt_to_page() on
a vmalloc address, while virt_to_page() is only valid for addresses in
the linear/direct map. Since init_vmalloc_pages() expects virtual
addresses in the vmalloc range, it must use vmalloc_to_page() rather
than virt_to_page().
We call init_vmalloc_pages() from __kasan_unpoison_vmalloc(), where we
check !is_vmalloc_or_module_addr(), suggesting that we might encounter a
non-vmalloc address. Luckily, this never happens. By design, we only
call __kasan_unpoison_vmalloc() on pointers in the vmalloc area, and I
have verified that we don't violate that expectation. Given that,
is_vmalloc_or_module_addr() must always be true for any legitimate
argument to __kasan_unpoison_vmalloc().
Correct init_vmalloc_pages() to use vmalloc_to_page(), and remove the
redundant and misleading use of is_vmalloc_or_module_addr() in
__kasan_unpoison_vmalloc().
Link: https://lkml.kernel.org/r/20230418164212.1775741-1-mark.rutland@arm.com
Fixes: 6c2f761dad7851d8 ("kasan: fix zeroing vmalloc memory with HW_TAGS")
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Konovalov <andreyknvl@google.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Marco Elver <elver@google.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-05-02 17:23:27 -07:00
..
2023-04-05 19:42:59 -07:00
2023-05-02 17:23:27 -07:00
2023-04-27 19:42:02 -07:00
2023-04-18 16:30:11 -07:00
2023-04-27 19:42:02 -07:00
2022-08-02 12:34:03 -04:00
2022-08-28 14:02:45 -07:00
2022-09-11 20:25:50 -07:00
2023-03-28 16:20:06 -07:00
2023-04-05 19:42:52 -07:00
2022-03-22 15:57:09 -07:00
2023-04-27 19:42:02 -07:00
2023-04-05 19:42:46 -07:00
2023-03-28 16:20:09 -07:00
2023-04-05 19:42:38 -07:00
2023-04-05 19:42:41 -07:00
2022-03-22 15:57:11 -07:00
2023-01-18 17:12:57 -08:00
2022-11-22 18:50:44 -08:00
2023-04-05 19:42:42 -07:00
2023-04-27 19:42:02 -07:00
2022-09-26 12:14:34 -07:00
2022-12-15 16:37:48 -08:00
2022-11-08 17:37:15 -08:00
2023-04-28 09:43:49 -07:00
2022-10-12 18:51:51 -07:00
2023-01-18 17:12:39 -08:00
2023-04-21 14:52:03 -07:00
2023-02-13 15:54:27 -08:00
2023-04-18 16:29:54 -07:00
2022-08-08 18:06:43 -07:00
2023-04-27 19:42:02 -07:00
2022-10-03 14:03:05 -07:00
2023-04-05 20:02:57 -07:00
2023-04-21 14:52:02 -07:00
2022-06-27 12:22:31 +01:00
2023-04-27 19:42:02 -07:00
2023-04-27 19:42:02 -07:00
2023-04-27 13:42:16 -07:00
2023-02-16 20:43:49 -08:00
2023-04-21 14:52:03 -07:00
2022-06-16 19:48:31 -07:00
2023-04-12 17:36:23 -07:00
2023-04-28 09:43:49 -07:00
2023-04-27 19:42:02 -07:00
2023-02-02 22:32:54 -08:00
2023-04-18 16:29:42 -07:00
2023-04-18 16:30:09 -07:00
2023-04-18 16:30:11 -07:00
2023-04-18 16:29:42 -07:00
2023-04-27 19:42:02 -07:00
2023-02-09 16:51:40 -08:00
2023-04-21 14:52:04 -07:00
2023-04-16 10:41:25 -07:00
2022-11-30 15:58:41 -08:00
2023-02-09 16:51:46 -08:00
2023-04-05 19:42:55 -07:00
2023-02-20 12:46:17 -08:00
2023-04-28 09:43:49 -07:00
2023-04-05 19:42:42 -07:00
2023-04-18 16:29:53 -07:00
2023-04-18 16:30:09 -07:00
2022-10-03 14:02:43 -07:00
2023-04-27 19:42:02 -07:00
2023-03-28 16:20:16 -07:00
2023-02-02 22:32:54 -08:00
2022-09-26 19:46:09 -07:00
2023-04-18 16:29:53 -07:00
2023-04-05 20:02:58 -07:00
2022-09-26 19:46:25 -07:00
2023-04-05 19:42:57 -07:00
2023-02-02 22:32:54 -08:00
2023-04-18 16:29:54 -07:00
2022-09-11 20:26:01 -07:00
2023-02-02 22:33:22 -08:00
2023-01-18 17:12:52 -08:00
2023-02-23 17:09:35 -08:00
2023-04-05 19:42:46 -07:00
2023-04-05 19:42:46 -07:00
2023-04-05 19:42:46 -07:00
2023-02-02 22:33:11 -08:00
2023-01-18 17:12:39 -08:00
2023-03-28 16:20:14 -07:00
2023-01-18 17:12:39 -08:00
2023-02-16 20:43:55 -08:00
2023-02-16 20:43:56 -08:00
2023-03-28 16:20:12 -07:00
2022-11-25 13:01:55 -05:00
2022-09-03 10:13:13 -07:00
2023-02-02 22:33:21 -08:00
2023-04-27 13:42:16 -07:00
2022-10-03 14:03:05 -07:00
2023-02-23 17:09:35 -08:00
2023-04-27 19:42:02 -07:00
2023-04-21 14:52:03 -07:00
2022-10-03 14:03:07 -07:00
2023-04-05 19:42:46 -07:00
2023-03-29 10:35:41 +02:00
2023-04-18 16:30:10 -07:00
2023-04-27 19:42:02 -07:00
2023-04-27 19:42:02 -07:00
2023-04-18 16:30:09 -07:00
2023-04-21 14:52:05 -07:00
2022-10-03 14:03:36 -07:00
2022-10-03 14:02:46 -07:00
2023-04-05 19:42:42 -07:00
2023-04-16 10:41:24 -07:00
2023-02-02 22:33:33 -08:00
2023-04-16 12:31:58 -07:00
2023-04-05 19:42:42 -07:00
2023-04-12 17:36:23 -07:00
2023-04-21 14:52:02 -07:00
2023-04-08 13:45:37 -07:00
2023-04-18 16:29:48 -07:00
2023-04-27 19:42:02 -07:00
2023-04-05 20:03:01 -07:00
2023-04-18 16:30:11 -07:00
2023-01-18 17:12:57 -08:00
2022-12-11 18:12:10 -08:00
2023-04-13 13:13:54 -07:00
2023-04-21 14:52:04 -07:00
2023-04-27 19:42:02 -07:00