Andrey Konovalov
4b6f018168
ANDROID: kasan: sync vmalloc support with linux-next/akpm
...
The FROMLIST patches merged in aosp/1974918 that add vmalloc support to
KASAN now have a few fixes staged in linux-next/akpm. Sync the changes.
Bug: 217222520
Bug: 222221793
Change-Id: I33dd30e3834a4d1bb8eac611b350004afdb08a74
Signed-off-by: Andrey Konovalov <andreyknvl@google.com >
2022-03-21 15:31:03 +00:00
Andrey Konovalov
d51f0bf565
FROMGIT: kasan, vmalloc: only tag normal vmalloc allocations
...
The kernel can use to allocate executable memory. The only supported way
to do that is via __vmalloc_node_range() with the executable bit set in
the prot argument. (vmap() resets the bit via pgprot_nx()).
Once tag-based KASAN modes start tagging vmalloc allocations, executing
code from such allocations will lead to the PC register getting a tag,
which is not tolerated by the kernel.
Only tag the allocations for normal kernel pages.
Link: https://lkml.kernel.org/r/fbfd9939a4dc375923c9a5c6b9e7ab05c26b8c6b.1643047180.git.andreyknvl@google.com
Signed-off-by: Andrey Konovalov <andreyknvl@google.com >
Acked-by: Marco Elver <elver@google.com >
Cc: Alexander Potapenko <glider@google.com >
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com >
Cc: Catalin Marinas <catalin.marinas@arm.com >
Cc: Dmitry Vyukov <dvyukov@google.com >
Cc: Evgenii Stepanov <eugenis@google.com >
Cc: Mark Rutland <mark.rutland@arm.com >
Cc: Peter Collingbourne <pcc@google.com >
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com >
Cc: Will Deacon <will@kernel.org >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au >
(cherry picked from commit 831af5e7f050e2c4cc0aa1989753d14e6361cae7
git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git akpm)
Bug: 217222520
Change-Id: I77c52e16d63f23ed84a6eb488996b1822eeb09e9
Signed-off-by: Andrey Konovalov <andreyknvl@google.com >
2022-02-15 17:59:15 +01:00
Andrey Konovalov
261a7a2ac9
BACKPORT: FROMGIT: kasan, vmalloc: add vmalloc tagging for HW_TAGS
...
(Backport: workaround kasan_populate_early_vm_area_shadow missing
due to 3252b1d8309e not backported.)
Add vmalloc tagging support to HW_TAGS KASAN.
The key difference between HW_TAGS and the other two KASAN modes when it
comes to vmalloc: HW_TAGS KASAN can only assign tags to physical memory.
The other two modes have shadow memory covering every mapped virtual
memory region.
Make __kasan_unpoison_vmalloc() for HW_TAGS KASAN:
- Skip non-VM_ALLOC mappings as HW_TAGS KASAN can only tag a single
mapping of normal physical memory; see the comment in the function.
- Generate a random tag, tag the returned pointer and the allocation,
and initialize the allocation at the same time.
- Propagate the tag into the page stucts to allow accesses through
page_address(vmalloc_to_page()).
The rest of vmalloc-related KASAN hooks are not needed:
- The shadow-related ones are fully skipped.
- __kasan_poison_vmalloc() is kept as a no-op with a comment.
Poisoning and zeroing of physical pages that are backing vmalloc()
allocations are skipped via __GFP_SKIP_KASAN_UNPOISON and __GFP_SKIP_ZERO:
__kasan_unpoison_vmalloc() does that instead.
Enabling CONFIG_KASAN_VMALLOC with HW_TAGS is not yet allowed.
Link: https://lkml.kernel.org/r/d19b2e9e59a9abc59d05b72dea8429dcaea739c6.1643047180.git.andreyknvl@google.com
Signed-off-by: Andrey Konovalov <andreyknvl@google.com >
Co-developed-by: Vincenzo Frascino <vincenzo.frascino@arm.com >
Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com >
Acked-by: Marco Elver <elver@google.com >
Cc: Alexander Potapenko <glider@google.com >
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com >
Cc: Catalin Marinas <catalin.marinas@arm.com >
Cc: Dmitry Vyukov <dvyukov@google.com >
Cc: Evgenii Stepanov <eugenis@google.com >
Cc: Mark Rutland <mark.rutland@arm.com >
Cc: Peter Collingbourne <pcc@google.com >
Cc: Will Deacon <will@kernel.org >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au >
(cherry picked from commit c9a950bcf1d67298187050bc3179096e4ef248c1
git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git akpm)
Bug: 217222520
Change-Id: I446b0ae074938389ade70bf503784d4d32b5d09b
Signed-off-by: Andrey Konovalov <andreyknvl@google.com >
2022-02-15 17:59:15 +01:00
Andrey Konovalov
ecf1dc6838
FROMGIT: kasan, vmalloc: add vmalloc tagging for SW_TAGS
...
Add vmalloc tagging support to SW_TAGS KASAN.
- __kasan_unpoison_vmalloc() now assigns a random pointer tag, poisons
the virtual mapping accordingly, and embeds the tag into the returned
pointer.
- __get_vm_area_node() (used by vmalloc() and vmap()) and
pcpu_get_vm_areas() save the tagged pointer into vm_struct->addr
(note: not into vmap_area->addr). This requires putting
kasan_unpoison_vmalloc() after setup_vmalloc_vm[_locked]();
otherwise the latter will overwrite the tagged pointer.
The tagged pointer then is naturally propagateed to vmalloc()
and vmap().
- vm_map_ram() returns the tagged pointer directly.
As a result of this change, vm_struct->addr is now tagged.
Enabling KASAN_VMALLOC with SW_TAGS is not yet allowed.
Link: https://lkml.kernel.org/r/4a78f3c064ce905e9070c29733aca1dd254a74f1.1643047180.git.andreyknvl@google.com
Signed-off-by: Andrey Konovalov <andreyknvl@google.com >
Acked-by: Marco Elver <elver@google.com >
Cc: Alexander Potapenko <glider@google.com >
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com >
Cc: Catalin Marinas <catalin.marinas@arm.com >
Cc: Dmitry Vyukov <dvyukov@google.com >
Cc: Evgenii Stepanov <eugenis@google.com >
Cc: Mark Rutland <mark.rutland@arm.com >
Cc: Peter Collingbourne <pcc@google.com >
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com >
Cc: Will Deacon <will@kernel.org >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au >
(cherry picked from commit 93555972485ebcac55b3855205bf154f1ba8478f
git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git akpm)
Bug: 217222520
Change-Id: I1e156582d91c39a3bf3351405ffd82624072b653
Signed-off-by: Andrey Konovalov <andreyknvl@google.com >
2022-02-15 17:59:15 +01:00
Andrey Konovalov
be087c0e14
FROMGIT: kasan: add wrappers for vmalloc hooks
...
Add wrappers around functions that [un]poison memory for vmalloc
allocations. These functions will be used by HW_TAGS KASAN and therefore
need to be disabled when kasan=off command line argument is provided.
This patch does no functional changes for software KASAN modes.
Link: https://lkml.kernel.org/r/3b8728eac438c55389fb0f9a8a2145d71dd77487.1643047180.git.andreyknvl@google.com
Signed-off-by: Andrey Konovalov <andreyknvl@google.com >
Reviewed-by: Alexander Potapenko <glider@google.com >
Acked-by: Marco Elver <elver@google.com >
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com >
Cc: Catalin Marinas <catalin.marinas@arm.com >
Cc: Dmitry Vyukov <dvyukov@google.com >
Cc: Evgenii Stepanov <eugenis@google.com >
Cc: Mark Rutland <mark.rutland@arm.com >
Cc: Peter Collingbourne <pcc@google.com >
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com >
Cc: Will Deacon <will@kernel.org >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au >
(cherry picked from commit 229f54a9a70a62e5e1cc4c52fae578113519a547
git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git akpm)
Bug: 217222520
Change-Id: I78cd783997a59a255120b47de4851d16968ed77c
Signed-off-by: Andrey Konovalov <andreyknvl@google.com >
2022-02-14 15:50:56 +01:00
Andrey Konovalov
e8c3e6f87a
BACKPORT: FROMGIT: kasan: reorder vmalloc hooks
...
(Backport: drop kasan_populate_early_vm_area_shadow changes, as
3252b1d8309e is not backported.)
Group functions that [de]populate shadow memory for vmalloc. Group
functions that [un]poison memory for vmalloc.
This patch does no functional changes but prepares KASAN code for adding
vmalloc support to HW_TAGS KASAN.
Link: https://lkml.kernel.org/r/aeef49eb249c206c4c9acce2437728068da74c28.1643047180.git.andreyknvl@google.com
Signed-off-by: Andrey Konovalov <andreyknvl@google.com >
Reviewed-by: Alexander Potapenko <glider@google.com >
Acked-by: Marco Elver <elver@google.com >
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com >
Cc: Catalin Marinas <catalin.marinas@arm.com >
Cc: Dmitry Vyukov <dvyukov@google.com >
Cc: Evgenii Stepanov <eugenis@google.com >
Cc: Mark Rutland <mark.rutland@arm.com >
Cc: Peter Collingbourne <pcc@google.com >
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com >
Cc: Will Deacon <will@kernel.org >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au >
(cherry picked from commit 6f933f941311711352b2925d61cd7d2c714cb716
git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git akpm)
Bug: 217222520
Change-Id: Ibafa7a38ebadd066b0371c1981ffd9016115fdef
Signed-off-by: Andrey Konovalov <andreyknvl@google.com >
2022-02-14 15:50:56 +01:00
Andrey Konovalov
deb5ba5311
FROMGIT: kasan, x86, arm64, s390: rename functions for modules shadow
...
Rename kasan_free_shadow to kasan_free_module_shadow and
kasan_module_alloc to kasan_alloc_module_shadow.
These functions are used to allocate/free shadow memory for kernel modules
when KASAN_VMALLOC is not enabled. The new names better reflect their
purpose.
Also reword the comment next to their declaration to improve clarity.
Link: https://lkml.kernel.org/r/36db32bde765d5d0b856f77d2d806e838513fe84.1643047180.git.andreyknvl@google.com
Signed-off-by: Andrey Konovalov <andreyknvl@google.com >
Acked-by: Catalin Marinas <catalin.marinas@arm.com >
Acked-by: Marco Elver <elver@google.com >
Cc: Alexander Potapenko <glider@google.com >
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com >
Cc: Dmitry Vyukov <dvyukov@google.com >
Cc: Evgenii Stepanov <eugenis@google.com >
Cc: Mark Rutland <mark.rutland@arm.com >
Cc: Peter Collingbourne <pcc@google.com >
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com >
Cc: Will Deacon <will@kernel.org >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au >
(cherry picked from commit c7073f59d25ed0f9eca0a15e7a232b92d720bfbf
git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git akpm)
Bug: 217222520
Change-Id: I42a719cf9b65ab032987f5bcc4aabd15dad26888
Signed-off-by: Andrey Konovalov <andreyknvl@google.com >
2022-02-14 15:50:56 +01:00
Kefeng Wang
68b8082163
UPSTREAM: mm: defer kmemleak object creation of module_alloc()
...
Yongqiang reports a kmemleak panic when module insmod/rmmod with KASAN
enabled(without KASAN_VMALLOC) on x86[1].
When the module area allocates memory, it's kmemleak_object is created
successfully, but the KASAN shadow memory of module allocation is not
ready, so when kmemleak scan the module's pointer, it will panic due to
no shadow memory with KASAN check.
module_alloc
__vmalloc_node_range
kmemleak_vmalloc
kmemleak_scan
update_checksum
kasan_module_alloc
kmemleak_ignore
Note, there is no problem if KASAN_VMALLOC enabled, the modules area
entire shadow memory is preallocated. Thus, the bug only exits on ARCH
which supports dynamic allocation of module area per module load, for
now, only x86/arm64/s390 are involved.
Add a VM_DEFER_KMEMLEAK flags, defer vmalloc'ed object register of
kmemleak in module_alloc() to fix this issue.
[1] https://lore.kernel.org/all/6d41e2b9-4692-5ec4-b1cd-cbe29ae89739@huawei.com/
[wangkefeng.wang@huawei.com: fix build]
Link: https://lkml.kernel.org/r/20211125080307.27225-1-wangkefeng.wang@huawei.com
[akpm@linux-foundation.org: simplify ifdefs, per Andrey]
Link: https://lkml.kernel.org/r/CA+fCnZcnwJHUQq34VuRxpdoY6_XbJCDJ-jopksS5Eia4PijPzw@mail.gmail.com
Link: https://lkml.kernel.org/r/20211124142034.192078-1-wangkefeng.wang@huawei.com
Fixes: 793213a82d ("s390/kasan: dynamic shadow mem allocation for modules")
Fixes: 39d114ddc6 ("arm64: add KASAN support")
Fixes: bebf56a1b1 ("kasan: enable instrumentation of global variables")
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com >
Reported-by: Yongqiang Liu <liuyongqiang13@huawei.com >
Cc: Andrey Konovalov <andreyknvl@gmail.com >
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com >
Cc: Dmitry Vyukov <dvyukov@google.com >
Cc: Catalin Marinas <catalin.marinas@arm.com >
Cc: Will Deacon <will@kernel.org >
Cc: Heiko Carstens <hca@linux.ibm.com >
Cc: Vasily Gorbik <gor@linux.ibm.com >
Cc: Christian Borntraeger <borntraeger@linux.ibm.com >
Cc: Alexander Gordeev <agordeev@linux.ibm.com >
Cc: Thomas Gleixner <tglx@linutronix.de >
Cc: Ingo Molnar <mingo@redhat.com >
Cc: Borislav Petkov <bp@alien8.de >
Cc: Dave Hansen <dave.hansen@linux.intel.com >
Cc: Alexander Potapenko <glider@google.com >
Cc: Kefeng Wang <wangkefeng.wang@huawei.com >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
(cherry picked from commit 60115fa54ad7b913b7cb5844e6b7ffeb842d55f2)
Bug: 217222520
Change-Id: Ia20d932a0d56f37ed490a35ed9187ae8026f97fe
Signed-off-by: Andrey Konovalov <andreyknvl@google.com >
2022-02-14 15:50:54 +01:00
Daniel Axtens
af3751f3c2
kasan: allow architectures to provide an outline readiness check
...
Allow architectures to define a kasan_arch_is_ready() hook that bails out
of any function that's about to touch the shadow unless the arch says that
it is ready for the memory to be accessed. This is fairly uninvasive and
should have a negligible performance penalty.
This will only work in outline mode, so an arch must specify
ARCH_DISABLE_KASAN_INLINE if it requires this.
Link: https://lkml.kernel.org/r/20210624034050.511391-3-dja@axtens.net
Signed-off-by: Daniel Axtens <dja@axtens.net >
Reviewed-by: Marco Elver <elver@google.com >
Suggested-by: Christophe Leroy <christophe.leroy@csgroup.eu >
Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com >
Cc: Balbir Singh <bsingharora@gmail.com >
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com >
Cc: Alexander Potapenko <glider@google.com >
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com >
Cc: Dmitry Vyukov <dvyukov@google.com >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2021-06-29 10:53:53 -07:00
Ingo Molnar
f0953a1bba
mm: fix typos in comments
...
Fix ~94 single-word typos in locking code comments, plus a few
very obvious grammar mistakes.
Link: https://lkml.kernel.org/r/20210322212624.GA1963421@gmail.com
Link: https://lore.kernel.org/r/20210322205203.GB1959563@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org >
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org >
Reviewed-by: Randy Dunlap <rdunlap@infradead.org >
Cc: Bhaskar Chowdhury <unixbhaskar@gmail.com >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2021-05-07 00:26:35 -07:00
Andrey Konovalov
aa5c219c60
kasan: init memory in kasan_(un)poison for HW_TAGS
...
This change adds an argument to kasan_poison() and kasan_unpoison() that
allows initializing memory along with setting the tags for HW_TAGS.
Combining setting allocation tags with memory initialization will improve
HW_TAGS KASAN performance when init_on_alloc/free is enabled.
This change doesn't integrate memory initialization with KASAN, this is
done is subsequent patches in this series.
Link: https://lkml.kernel.org/r/3054314039fa64510947e674180d675cab1b4c41.1615296150.git.andreyknvl@google.com
Signed-off-by: Andrey Konovalov <andreyknvl@google.com >
Reviewed-by: Marco Elver <elver@google.com >
Cc: Alexander Potapenko <glider@google.com >
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com >
Cc: Branislav Rankov <Branislav.Rankov@arm.com >
Cc: Catalin Marinas <catalin.marinas@arm.com >
Cc: Christoph Lameter <cl@linux.com >
Cc: David Rientjes <rientjes@google.com >
Cc: Dmitry Vyukov <dvyukov@google.com >
Cc: Evgenii Stepanov <eugenis@google.com >
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com >
Cc: Kevin Brodsky <kevin.brodsky@arm.com >
Cc: Pekka Enberg <penberg@kernel.org >
Cc: Peter Collingbourne <pcc@google.com >
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com >
Cc: Vlastimil Babka <vbabka@suse.cz >
Cc: Will Deacon <will.deacon@arm.com >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2021-04-30 11:20:41 -07:00
Andrey Konovalov
cde8a7eb77
kasan: ensure poisoning size alignment
...
A previous changes d99f6a10c1 ("kasan: don't round_up too much")
attempted to simplify the code by adding a round_up(size) call into
kasan_poison(). While this allows to have less round_up() calls around
the code, this results in round_up() being called multiple times.
This patch removes round_up() of size from kasan_poison() and ensures that
all callers round_up() the size explicitly. This patch also adds
WARN_ON() alignment checks for address and size to kasan_poison() and
kasan_unpoison().
Link: https://lkml.kernel.org/r/3ffe8d4a246ae67a8b5e91f65bf98cd7cba9d7b9.1612546384.git.andreyknvl@google.com
Signed-off-by: Andrey Konovalov <andreyknvl@google.com >
Reviewed-by: Marco Elver <elver@google.com >
Cc: Alexander Potapenko <glider@google.com >
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com >
Cc: Branislav Rankov <Branislav.Rankov@arm.com >
Cc: Catalin Marinas <catalin.marinas@arm.com >
Cc: Dmitry Vyukov <dvyukov@google.com >
Cc: Evgenii Stepanov <eugenis@google.com >
Cc: Kevin Brodsky <kevin.brodsky@arm.com >
Cc: Peter Collingbourne <pcc@google.com >
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com >
Cc: Will Deacon <will.deacon@arm.com >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2021-02-26 09:41:03 -08:00
Andrey Konovalov
e2db1a9aa3
kasan, mm: optimize kmalloc poisoning
...
For allocations from kmalloc caches, kasan_kmalloc() always follows
kasan_slab_alloc(). Currenly, both of them unpoison the whole object,
which is unnecessary.
This patch provides separate implementations for both annotations:
kasan_slab_alloc() unpoisons the whole object, and kasan_kmalloc() only
poisons the redzone.
For generic KASAN, the redzone start might not be aligned to
KASAN_GRANULE_SIZE. Therefore, the poisoning is split in two parts:
kasan_poison_last_granule() poisons the unaligned part, and then
kasan_poison() poisons the rest.
This patch also clarifies alignment guarantees of each of the poisoning
functions and drops the unnecessary round_up() call for redzone_end.
With this change, the early SLUB cache annotation needs to be changed to
kasan_slab_alloc(), as kasan_kmalloc() doesn't unpoison objects now. The
number of poisoned bytes for objects in this cache stays the same, as
kmem_cache_node->object_size is equal to sizeof(struct kmem_cache_node).
Link: https://lkml.kernel.org/r/7e3961cb52be380bc412860332063f5f7ce10d13.1612546384.git.andreyknvl@google.com
Signed-off-by: Andrey Konovalov <andreyknvl@google.com >
Reviewed-by: Marco Elver <elver@google.com >
Cc: Alexander Potapenko <glider@google.com >
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com >
Cc: Branislav Rankov <Branislav.Rankov@arm.com >
Cc: Catalin Marinas <catalin.marinas@arm.com >
Cc: Dmitry Vyukov <dvyukov@google.com >
Cc: Evgenii Stepanov <eugenis@google.com >
Cc: Kevin Brodsky <kevin.brodsky@arm.com >
Cc: Peter Collingbourne <pcc@google.com >
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com >
Cc: Will Deacon <will.deacon@arm.com >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2021-02-26 09:41:02 -08:00
Alexander Potapenko
2b8305260f
kfence, kasan: make KFENCE compatible with KASAN
...
Make KFENCE compatible with KASAN. Currently this helps test KFENCE
itself, where KASAN can catch potential corruptions to KFENCE state, or
other corruptions that may be a result of freepointer corruptions in the
main allocators.
[akpm@linux-foundation.org: merge fixup]
[andreyknvl@google.com: untag addresses for KFENCE]
Link: https://lkml.kernel.org/r/9dc196006921b191d25d10f6e611316db7da2efc.1611946152.git.andreyknvl@google.com
Link: https://lkml.kernel.org/r/20201103175841.3495947-7-elver@google.com
Signed-off-by: Marco Elver <elver@google.com >
Signed-off-by: Alexander Potapenko <glider@google.com >
Signed-off-by: Andrey Konovalov <andreyknvl@google.com >
Reviewed-by: Dmitry Vyukov <dvyukov@google.com >
Reviewed-by: Jann Horn <jannh@google.com >
Co-developed-by: Marco Elver <elver@google.com >
Cc: Andrey Konovalov <andreyknvl@google.com >
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com >
Cc: Andy Lutomirski <luto@kernel.org >
Cc: Borislav Petkov <bp@alien8.de >
Cc: Catalin Marinas <catalin.marinas@arm.com >
Cc: Christopher Lameter <cl@linux.com >
Cc: Dave Hansen <dave.hansen@linux.intel.com >
Cc: David Rientjes <rientjes@google.com >
Cc: Eric Dumazet <edumazet@google.com >
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org >
Cc: Hillf Danton <hdanton@sina.com >
Cc: "H. Peter Anvin" <hpa@zytor.com >
Cc: Ingo Molnar <mingo@redhat.com >
Cc: Joern Engel <joern@purestorage.com >
Cc: Jonathan Corbet <corbet@lwn.net >
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com >
Cc: Kees Cook <keescook@chromium.org >
Cc: Mark Rutland <mark.rutland@arm.com >
Cc: Paul E. McKenney <paulmck@kernel.org >
Cc: Pekka Enberg <penberg@kernel.org >
Cc: Peter Zijlstra <peterz@infradead.org >
Cc: SeongJae Park <sjpark@amazon.de >
Cc: Thomas Gleixner <tglx@linutronix.de >
Cc: Vlastimil Babka <vbabka@suse.cz >
Cc: Will Deacon <will@kernel.org >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2021-02-26 09:41:02 -08:00
Andrey Konovalov
573a480923
kasan: add match-all tag tests
...
Add 3 new tests for tag-based KASAN modes:
1. Check that match-all pointer tag is not assigned randomly.
2. Check that 0xff works as a match-all pointer tag.
3. Check that there are no match-all memory tags.
Note, that test #3 causes a significant number (255) of KASAN reports
to be printed during execution for the SW_TAGS mode.
[arnd@arndb.de: export kasan_poison]
Link: https://lkml.kernel.org/r/20210125112831.2156212-1-arnd@kernel.org
[akpm@linux-foundation.org: s/EXPORT_SYMBOL_GPL/EXPORT_SYMBOL/, per Andrey]
Link: https://linux-review.googlesource.com/id/I78f1375efafa162b37f3abcb2c5bc2f3955dfd8e
Link: https://lkml.kernel.org/r/da841a5408e2204bf25f3b23f70540a65844e8a4.1610733117.git.andreyknvl@google.com
Signed-off-by: Andrey Konovalov <andreyknvl@google.com >
Signed-off-by: Arnd Bergmann <arnd@arndb.de >
Reviewed-by: Marco Elver <elver@google.com >
Reviewed-by: Alexander Potapenko <glider@google.com >
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com >
Cc: Branislav Rankov <Branislav.Rankov@arm.com >
Cc: Catalin Marinas <catalin.marinas@arm.com >
Cc: Dmitry Vyukov <dvyukov@google.com >
Cc: Evgenii Stepanov <eugenis@google.com >
Cc: Kevin Brodsky <kevin.brodsky@arm.com >
Cc: Peter Collingbourne <pcc@google.com >
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com >
Cc: Will Deacon <will.deacon@arm.com >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2021-02-24 13:38:31 -08:00
Andrey Konovalov
f00748bfa0
kasan: prefix global functions with kasan_
...
Patch series "kasan: HW_TAGS tests support and fixes", v4.
This patchset adds support for running KASAN-KUnit tests with the
hardware tag-based mode and also contains a few fixes.
This patch (of 15):
There's a number of internal KASAN functions that are used across multiple
source code files and therefore aren't marked as static inline. To avoid
littering the kernel function names list with generic function names,
prefix all such KASAN functions with kasan_.
As a part of this change:
- Rename internal (un)poison_range() to kasan_(un)poison() (no _range)
to avoid name collision with a public kasan_unpoison_range().
- Rename check_memory_region() to kasan_check_range(), as it's a more
fitting name.
Link: https://lkml.kernel.org/r/cover.1610733117.git.andreyknvl@google.com
Link: https://linux-review.googlesource.com/id/I719cc93483d4ba288a634dba80ee6b7f2809cd26
Link: https://lkml.kernel.org/r/13777aedf8d3ebbf35891136e1f2287e2f34aaba.1610733117.git.andreyknvl@google.com
Signed-off-by: Andrey Konovalov <andreyknvl@google.com >
Suggested-by: Marco Elver <elver@google.com >
Reviewed-by: Marco Elver <elver@google.com >
Reviewed-by: Alexander Potapenko <glider@google.com >
Cc: Catalin Marinas <catalin.marinas@arm.com >
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com >
Cc: Dmitry Vyukov <dvyukov@google.com >
Cc: Will Deacon <will.deacon@arm.com >
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com >
Cc: Peter Collingbourne <pcc@google.com >
Cc: Evgenii Stepanov <eugenis@google.com >
Cc: Branislav Rankov <Branislav.Rankov@arm.com >
Cc: Kevin Brodsky <kevin.brodsky@arm.com >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2021-02-24 13:38:30 -08:00
Andrey Konovalov
d99f6a10c1
kasan: don't round_up too much
...
For hardware tag-based mode kasan_poison_memory() already rounds up the
size. Do the same for software modes and remove round_up() from the common
code.
Link: https://lkml.kernel.org/r/47b232474f1f89dc072aeda0fa58daa6efade377.1606162397.git.andreyknvl@google.com
Link: https://linux-review.googlesource.com/id/Ib397128fac6eba874008662b4964d65352db4aa4
Signed-off-by: Andrey Konovalov <andreyknvl@google.com >
Reviewed-by: Dmitry Vyukov <dvyukov@google.com >
Reviewed-by: Marco Elver <elver@google.com >
Tested-by: Vincenzo Frascino <vincenzo.frascino@arm.com >
Cc: Alexander Potapenko <glider@google.com >
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com >
Cc: Branislav Rankov <Branislav.Rankov@arm.com >
Cc: Catalin Marinas <catalin.marinas@arm.com >
Cc: Evgenii Stepanov <eugenis@google.com >
Cc: Kevin Brodsky <kevin.brodsky@arm.com >
Cc: Vasily Gorbik <gor@linux.ibm.com >
Cc: Will Deacon <will.deacon@arm.com >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2020-12-22 12:55:09 -08:00
Andrey Konovalov
c0054c565a
kasan: inline kasan_reset_tag for tag-based modes
...
Using kasan_reset_tag() currently results in a function call. As it's
called quite often from the allocator code, this leads to a noticeable
slowdown. Move it to include/linux/kasan.h and turn it into a static
inline function. Also remove the now unneeded reset_tag() internal KASAN
macro and use kasan_reset_tag() instead.
Link: https://lkml.kernel.org/r/6940383a3a9dfb416134d338d8fac97a9ebb8686.1606162397.git.andreyknvl@google.com
Link: https://linux-review.googlesource.com/id/I4d2061acfe91d480a75df00b07c22d8494ef14b5
Signed-off-by: Andrey Konovalov <andreyknvl@google.com >
Reviewed-by: Marco Elver <elver@google.com >
Reviewed-by: Dmitry Vyukov <dvyukov@google.com >
Tested-by: Vincenzo Frascino <vincenzo.frascino@arm.com >
Cc: Alexander Potapenko <glider@google.com >
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com >
Cc: Branislav Rankov <Branislav.Rankov@arm.com >
Cc: Catalin Marinas <catalin.marinas@arm.com >
Cc: Evgenii Stepanov <eugenis@google.com >
Cc: Kevin Brodsky <kevin.brodsky@arm.com >
Cc: Vasily Gorbik <gor@linux.ibm.com >
Cc: Will Deacon <will.deacon@arm.com >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2020-12-22 12:55:08 -08:00
Andrey Konovalov
2e903b9147
kasan, arm64: implement HW_TAGS runtime
...
Provide implementation of KASAN functions required for the hardware
tag-based mode. Those include core functions for memory and pointer
tagging (tags_hw.c) and bug reporting (report_tags_hw.c). Also adapt
common KASAN code to support the new mode.
Link: https://lkml.kernel.org/r/cfd0fbede579a6b66755c98c88c108e54f9c56bf.1606161801.git.andreyknvl@google.com
Signed-off-by: Andrey Konovalov <andreyknvl@google.com >
Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com >
Acked-by: Catalin Marinas <catalin.marinas@arm.com >
Reviewed-by: Alexander Potapenko <glider@google.com >
Tested-by: Vincenzo Frascino <vincenzo.frascino@arm.com >
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com >
Cc: Branislav Rankov <Branislav.Rankov@arm.com >
Cc: Dmitry Vyukov <dvyukov@google.com >
Cc: Evgenii Stepanov <eugenis@google.com >
Cc: Kevin Brodsky <kevin.brodsky@arm.com >
Cc: Marco Elver <elver@google.com >
Cc: Vasily Gorbik <gor@linux.ibm.com >
Cc: Will Deacon <will.deacon@arm.com >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2020-12-22 12:55:08 -08:00
Andrey Konovalov
affc3f0775
kasan: define KASAN_MEMORY_PER_SHADOW_PAGE
...
Define KASAN_MEMORY_PER_SHADOW_PAGE as (KASAN_GRANULE_SIZE << PAGE_SHIFT),
which is the same as (KASAN_GRANULE_SIZE * PAGE_SIZE) for software modes
that use shadow memory, and use it across KASAN code to simplify it.
Link: https://lkml.kernel.org/r/8329391cfe14b5cffd3decf3b5c535b6ce21eef6.1606161801.git.andreyknvl@google.com
Signed-off-by: Andrey Konovalov <andreyknvl@google.com >
Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com >
Reviewed-by: Marco Elver <elver@google.com >
Reviewed-by: Alexander Potapenko <glider@google.com >
Tested-by: Vincenzo Frascino <vincenzo.frascino@arm.com >
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com >
Cc: Branislav Rankov <Branislav.Rankov@arm.com >
Cc: Catalin Marinas <catalin.marinas@arm.com >
Cc: Dmitry Vyukov <dvyukov@google.com >
Cc: Evgenii Stepanov <eugenis@google.com >
Cc: Kevin Brodsky <kevin.brodsky@arm.com >
Cc: Vasily Gorbik <gor@linux.ibm.com >
Cc: Will Deacon <will.deacon@arm.com >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2020-12-22 12:55:06 -08:00
Andrey Konovalov
bb359dbcb7
kasan: split out shadow.c from common.c
...
This is a preparatory commit for the upcoming addition of a new hardware
tag-based (MTE-based) KASAN mode.
The new mode won't be using shadow memory. Move all shadow-related code
to shadow.c, which is only enabled for software KASAN modes that use
shadow memory.
No functional changes for software modes.
Link: https://lkml.kernel.org/r/17d95cfa7d5cf9c4fcd9bf415f2a8dea911668df.1606161801.git.andreyknvl@google.com
Signed-off-by: Andrey Konovalov <andreyknvl@google.com >
Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com >
Reviewed-by: Marco Elver <elver@google.com >
Reviewed-by: Alexander Potapenko <glider@google.com >
Tested-by: Vincenzo Frascino <vincenzo.frascino@arm.com >
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com >
Cc: Branislav Rankov <Branislav.Rankov@arm.com >
Cc: Catalin Marinas <catalin.marinas@arm.com >
Cc: Dmitry Vyukov <dvyukov@google.com >
Cc: Evgenii Stepanov <eugenis@google.com >
Cc: Kevin Brodsky <kevin.brodsky@arm.com >
Cc: Vasily Gorbik <gor@linux.ibm.com >
Cc: Will Deacon <will.deacon@arm.com >
Signed-off-by: Andrew Morton <akpm@linux-foundation.org >
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org >
2020-12-22 12:55:06 -08:00