Files
Linux/include/linux
Vincenzo Frascino 49c6631d3b kasan: add explicit preconditions to kasan_report()
Patch series "kasan: Fix metadata detection for KASAN_HW_TAGS", v5.

With the introduction of KASAN_HW_TAGS, kasan_report() currently assumes
that every location in memory has valid metadata associated.  This is
due to the fact that addr_has_metadata() returns always true.

As a consequence of this, an invalid address (e.g.  NULL pointer
address) passed to kasan_report() when KASAN_HW_TAGS is enabled, leads
to a kernel panic.

Example below, based on arm64:

   BUG: KASAN: invalid-access in 0x0
   Read at addr 0000000000000000 by task swapper/0/1
   Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
   Mem abort info:
     ESR = 0x96000004
     EC = 0x25: DABT (current EL), IL = 32 bits
     SET = 0, FnV = 0
     EA = 0, S1PTW = 0
   Data abort info:
     ISV = 0, ISS = 0x00000004
     CM = 0, WnR = 0

  ...

   Call trace:
    mte_get_mem_tag+0x24/0x40
    kasan_report+0x1a4/0x410
    alsa_sound_last_init+0x8c/0xa4
    do_one_initcall+0x50/0x1b0
    kernel_init_freeable+0x1d4/0x23c
    kernel_init+0x14/0x118
    ret_from_fork+0x10/0x34
   Code: d65f03c0 9000f021 f9428021 b6cfff61 (d9600000)
   ---[ end trace 377c8bb45bdd3a1a ]---
   hrtimer: interrupt took 48694256 ns
   note: swapper/0[1] exited with preempt_count 1
   Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
   SMP: stopping secondary CPUs
   Kernel Offset: 0x35abaf140000 from 0xffff800010000000
   PHYS_OFFSET: 0x40000000
   CPU features: 0x0a7e0152,61c0a030
   Memory Limit: none
   ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b ]---

This series fixes the behavior of addr_has_metadata() that now returns
true only when the address is valid.

This patch (of 2):

With the introduction of KASAN_HW_TAGS, kasan_report() accesses the
metadata only when addr_has_metadata() succeeds.

Add a comment to make sure that the preconditions to the function are
explicitly clarified.

Link: https://lkml.kernel.org/r/[email protected]
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Vincenzo Frascino <[email protected]>
Reviewed-by: Andrey Konovalov <[email protected]>
Cc: Andrey Ryabinin <[email protected]>
Cc: Alexander Potapenko <[email protected]>
Cc: Dmitry Vyukov <[email protected]>
Cc: Leon Romanovsky <[email protected]>
Cc: Andrey Konovalov <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: "Paul E . McKenney" <[email protected]>
Cc: Naresh Kamboju <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
2021-02-05 11:03:47 -08:00
..
…
…
…
…
…
…
…
2020-12-09 19:26:02 -06:00
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
2020-12-02 09:46:55 -07:00
…
…
…
…
…
2020-11-06 08:08:37 -08:00
…
…
…
…
…
…
…
…
2020-12-02 09:46:55 -07:00
…
…
…
…
…
…
…
…
…
2020-12-19 11:18:38 -08:00
…
…
…
…
…
…
2020-10-16 17:21:51 +02:00
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
2020-12-14 16:24:19 +01:00
…
…
2020-12-11 14:02:14 -08:00
…
…
…
…
…
…
…
…
…
2020-12-02 22:00:22 -08:00
…
…
…
…
…
…
2020-12-10 12:42:59 -06:00
…
…
…
…
…
2020-11-16 16:31:41 +01:00
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
2020-11-16 15:20:01 +01:00
…
…
…
…
…
…
…
…
…
2020-11-16 08:14:30 -07:00
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
2020-12-02 22:10:35 -08:00
…
2020-11-23 14:16:55 +00:00
…
…
2020-12-08 14:14:48 +00:00
…
…
…
…
…
…
2020-11-24 16:47:48 +01:00
…
2020-12-15 16:19:31 +01:00
…
…
…
…
…
…
…
…
…
…
…
2020-12-15 16:19:31 +01:00
…
…
…
…
…
…
…
…
…
…
…
…
2021-01-22 15:09:42 +01:00
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
2020-12-07 10:29:57 +01:00
…
…
…
…
…
…
…
2020-12-04 12:23:25 +01:00
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
2020-12-15 15:11:08 -06:00
…
…
…
…
…
2020-12-16 13:08:18 -08:00
…
2020-10-18 09:27:10 -07:00
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
2020-12-03 11:20:52 +01:00
…
…
…
2020-12-15 12:13:39 -08:00
…
…
…
…
…
2020-12-07 17:12:49 -07:00
…
…
…
…
…
2020-11-06 10:05:18 -08:00
…
…
…
…
…
…
…
…
…
…
2020-12-10 16:17:15 +01:00
…
…
2020-12-15 12:13:37 -08:00
…
…
…
…
2020-11-24 16:47:49 +01:00
…
…
…
…
…
…
…
2020-12-10 10:45:36 +01:00
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
2020-10-30 21:57:04 +01:00
2020-11-16 15:20:01 +01:00
…
…
…
…
…
…
…
…
2020-12-04 16:54:35 +01:00
…
…
…
…
…
2020-11-09 18:39:36 +01:00
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…