kasan: vmalloc: Fixes for the percpu allocator and vrealloc
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v5 Latest3 patches 1 replyIn review
- v43 patches 0 repliesSuperseded
- v33 patches 10 repliesSuperseded 2 of 3 applied
Changes in v5 from the cover letter
- Rebased onto 6.19-rc1.
Patches in v5 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | mm/kasan: Fix incorrect unpoisoning in vrealloc for KASANinclude/ mm/ mm/ +1 more | +8 | 0 replies | |
| 2/3 | kasan: Refactor pcpu kasan vmalloc unpoisoninclude/ mm/ mm/ | +33 | 0 replies | |
| 3/3 | kasan: Unpoison vms[area] addresses with a common tagmm/ | +18 | 0 replies |
Reviews trailers per patch
All 3 patches have a Reviewed-by or Acked-by.
| Patch | Andrey Konovalov |
|---|---|
| 1/3 | R-b |
| 2/3 | R-b |
| 3/3 | R-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH v5 0/3] kasan: vmalloc: Fixes for the percpu allocator and vrealloc
Patches fix two issues related to KASAN and vmalloc.
The first one, a KASAN tag mismatch, possibly resulting in a kernel panic, can be observed on systems with a tag-based KASAN enabled and with multiple NUMA nodes. Initially it was only noticed on x86 [1] but later a similar issue was also reported on arm64 [2].
Specifically the problem is related to how vm_structs interact with pcpu_chunks - both when they are allocated, assigned and when pcpu_chunk addresses are derived.
When vm_structs are allocated they are unpoisoned, each with a different random tag, if vmalloc support is enabled along the KASAN mode. Later when first pcpu chunk is allocated it gets its 'base_addr' field set to the first allocated vm_struct. With that it inherits that vm_struct's tag.
When pcpu_chunk addresses are later derived (by pcpu_chunk_addr(), for example in pcpu_alloc_noprof()) the base_addr field is used and offsets are added to it. If the initial conditions are satisfied then some of the offsets will point into memory allocated with a different vm_struct. So while the lower bits will get accurately derived the tag bits in the top of the pointer won't match the shadow memory contents.
The solution (proposed at v2 of the x86 KASAN series [3]) is to unpoison the vm_structs with the same tag when allocating them for the per cpu allocator (in pcpu_get_vm_areas()).
The second one reported by syzkaller [4] is related to vrealloc and happens because of random tag generation when unpoisoning memory without allocating new pages. This breaks shadow memory tracking and needs to reuse the existing tag instead of generating a new one. At the same time an inconsistency in used flags is corrected.
The series is based on 6.19-rc1.
[1] https://lore.kernel.org/all/e7e04692866d02e6d3b32bb43b998e5d17092ba4.1738686764.git.maciej.wieczor-retman@intel.com/
[2] https://lore.kernel.org/all/aMUrW1Znp1GEj7St@MiWiFi-R3L-srv/
[3] https://lore.kernel.org/all/CAPAsAGxDRv_uFeMYu9TwhBVWHCCtkSxoWY4xmFB_vowMbi8raw@mail.gmail.com/
[4] https://syzkaller.appspot.com/bug?extid=997752115a851cb0cf36
Changes v5:
- Rebased onto 6.19-rc1.
Changes v4:
- Added WARN_ON_ONCE() and removed pr_warn() from last patch.
- Added missing cc stable to the first patch.
- Fixed stray 'Changelog v1' in the patch messages.
Changes v3:
- Reworded the 4th and 5th paragraphs after finding the vms[] pointers were untagged.
- Redo the patches by using a flag instead of a new __kasan_vmalloc_unpoison() argument.
- Added Jiayuan's patch to the series.
Changes v2:
- Redid the patches since last version wasn't an actual refactor as the patch promised.
- Also fixed multiple mistakes and retested everything.
Jiayuan Chen (1):
mm/kasan: Fix incorrect unpoisoning in vrealloc for KASAN
Maciej Wieczor-Retman (2):
kasan: Refactor pcpu kasan vmalloc unpoison
kasan: Unpoison vms[area] addresses with a common tag
include/linux/kasan.h | 16 ++++++++++++++++ mm/kasan/common.c | 32 ++++++++++++++++++++++++++++++++ mm/kasan/hw_tags.c | 2 +- mm/kasan/shadow.c | 4 +++- mm/vmalloc.c | 8 ++++---- 5 files changed, 56 insertions(+), 6 deletions(-)
Signature · 1 line
2.52.0