linux/mm/kasan
Lecopzer Chen a11a496ee6 kasan: fix unaligned address is unhandled in kasan_remove_zero_shadow
During testing kasan_populate_early_shadow and kasan_remove_zero_shadow,
if the shadow start and end address in kasan_remove_zero_shadow() is not
aligned to PMD_SIZE, the remain unaligned PTE won't be removed.

In the test case for kasan_remove_zero_shadow():

    shadow_start: 0xffffffb802000000, shadow end: 0xffffffbfbe000000

    3-level page table:
      PUD_SIZE: 0x40000000 PMD_SIZE: 0x200000 PAGE_SIZE: 4K

0xffffffbf80000000 ~ 0xffffffbfbdf80000 will not be removed because in
kasan_remove_pud_table(), kasan_pmd_table(*pud) is true but the next
address is 0xffffffbfbdf80000 which is not aligned to PUD_SIZE.

In the correct condition, this should fallback to the next level
kasan_remove_pmd_table() but the condition flow always continue to skip
the unaligned part.

Fix by correcting the condition when next and addr are neither aligned.

Link: https://lkml.kernel.org/r/20210103135621.83129-1-lecopzer@gmail.com
Fixes: 0207df4fa1 ("kernel/memremap, kasan: make ZONE_DEVICE with work with KASAN")
Signed-off-by: Lecopzer Chen <lecopzer.chen@mediatek.com>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: YJ Chiang <yj.chiang@mediatek.com>
Cc: Andrey Konovalov <andreyknvl@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-01-24 10:34:52 -08:00
..
common.c kasan, mm: allow cache merging with no metadata 2020-12-22 12:55:09 -08:00
generic.c kasan: fix null pointer dereference in kasan_record_aux_stack 2020-12-29 15:36:49 -08:00
hw_tags.c kasan: sanitize objects when metadata doesn't fit 2020-12-22 12:55:09 -08:00
init.c kasan: fix unaligned address is unhandled in kasan_remove_zero_shadow 2021-01-24 10:34:52 -08:00
kasan.h kasan: sanitize objects when metadata doesn't fit 2020-12-22 12:55:09 -08:00
Makefile kasan, arm64: implement HW_TAGS runtime 2020-12-22 12:55:08 -08:00
quarantine.c kasan: sanitize objects when metadata doesn't fit 2020-12-22 12:55:09 -08:00
report_generic.c kasan: separate metadata_fetch_row for each mode 2020-12-22 12:55:07 -08:00
report_hw_tags.c kasan: inline kasan_reset_tag for tag-based modes 2020-12-22 12:55:08 -08:00
report_sw_tags.c kasan: sanitize objects when metadata doesn't fit 2020-12-22 12:55:09 -08:00
report.c kasan: sanitize objects when metadata doesn't fit 2020-12-22 12:55:09 -08:00
shadow.c kasan: don't round_up too much 2020-12-22 12:55:09 -08:00
sw_tags.c kasan: sanitize objects when metadata doesn't fit 2020-12-22 12:55:09 -08:00