diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2019-09-24 19:10:23 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2019-09-24 19:10:23 -0400 |
commit | 9c9fa97a8edbc3668dfc7a25de516e80c146e86f (patch) | |
tree | 2dc0e90203796a4b346ce190f9521c3294104058 /lib/test_kasan.c | |
parent | 5184d449600f501a8688069f35c138c6b3bf8b94 (diff) | |
parent | 2b38d01b4de8b1bbda7f5f7e91252609557635fc (diff) |
Merge branch 'akpm' (patches from Andrew)
Merge updates from Andrew Morton:
- a few hot fixes
- ocfs2 updates
- almost all of -mm (slab-generic, slab, slub, kmemleak, kasan,
cleanups, debug, pagecache, memcg, gup, pagemap, memory-hotplug,
sparsemem, vmalloc, initialization, z3fold, compaction, mempolicy,
oom-kill, hugetlb, migration, thp, mmap, madvise, shmem, zswap,
zsmalloc)
* emailed patches from Andrew Morton <akpm@linux-foundation.org>: (132 commits)
mm/zsmalloc.c: fix a -Wunused-function warning
zswap: do not map same object twice
zswap: use movable memory if zpool support allocate movable memory
zpool: add malloc_support_movable to zpool_driver
shmem: fix obsolete comment in shmem_getpage_gfp()
mm/madvise: reduce code duplication in error handling paths
mm: mmap: increase sockets maximum memory size pgoff for 32bits
mm/mmap.c: refine find_vma_prev() with rb_last()
riscv: make mmap allocation top-down by default
mips: use generic mmap top-down layout and brk randomization
mips: replace arch specific way to determine 32bit task with generic version
mips: adjust brk randomization offset to fit generic version
mips: use STACK_TOP when computing mmap base address
mips: properly account for stack randomization and stack guard gap
arm: use generic mmap top-down layout and brk randomization
arm: use STACK_TOP when computing mmap base address
arm: properly account for stack randomization and stack guard gap
arm64, mm: make randomization selected by generic topdown mmap layout
arm64, mm: move generic mmap layout functions to mm
arm64: consider stack randomization for mmap base only when necessary
...
Diffstat (limited to 'lib/test_kasan.c')
-rw-r--r-- | lib/test_kasan.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/test_kasan.c b/lib/test_kasan.c index b63b367a94e8..49cc4d570a40 100644 --- a/lib/test_kasan.c +++ b/lib/test_kasan.c | |||
@@ -18,6 +18,9 @@ | |||
18 | #include <linux/slab.h> | 18 | #include <linux/slab.h> |
19 | #include <linux/string.h> | 19 | #include <linux/string.h> |
20 | #include <linux/uaccess.h> | 20 | #include <linux/uaccess.h> |
21 | #include <linux/io.h> | ||
22 | |||
23 | #include <asm/page.h> | ||
21 | 24 | ||
22 | /* | 25 | /* |
23 | * Note: test functions are marked noinline so that their names appear in | 26 | * Note: test functions are marked noinline so that their names appear in |
@@ -337,6 +340,42 @@ static noinline void __init kmalloc_uaf2(void) | |||
337 | kfree(ptr2); | 340 | kfree(ptr2); |
338 | } | 341 | } |
339 | 342 | ||
343 | static noinline void __init kfree_via_page(void) | ||
344 | { | ||
345 | char *ptr; | ||
346 | size_t size = 8; | ||
347 | struct page *page; | ||
348 | unsigned long offset; | ||
349 | |||
350 | pr_info("invalid-free false positive (via page)\n"); | ||
351 | ptr = kmalloc(size, GFP_KERNEL); | ||
352 | if (!ptr) { | ||
353 | pr_err("Allocation failed\n"); | ||
354 | return; | ||
355 | } | ||
356 | |||
357 | page = virt_to_page(ptr); | ||
358 | offset = offset_in_page(ptr); | ||
359 | kfree(page_address(page) + offset); | ||
360 | } | ||
361 | |||
362 | static noinline void __init kfree_via_phys(void) | ||
363 | { | ||
364 | char *ptr; | ||
365 | size_t size = 8; | ||
366 | phys_addr_t phys; | ||
367 | |||
368 | pr_info("invalid-free false positive (via phys)\n"); | ||
369 | ptr = kmalloc(size, GFP_KERNEL); | ||
370 | if (!ptr) { | ||
371 | pr_err("Allocation failed\n"); | ||
372 | return; | ||
373 | } | ||
374 | |||
375 | phys = virt_to_phys(ptr); | ||
376 | kfree(phys_to_virt(phys)); | ||
377 | } | ||
378 | |||
340 | static noinline void __init kmem_cache_oob(void) | 379 | static noinline void __init kmem_cache_oob(void) |
341 | { | 380 | { |
342 | char *p; | 381 | char *p; |
@@ -737,6 +776,8 @@ static int __init kmalloc_tests_init(void) | |||
737 | kmalloc_uaf(); | 776 | kmalloc_uaf(); |
738 | kmalloc_uaf_memset(); | 777 | kmalloc_uaf_memset(); |
739 | kmalloc_uaf2(); | 778 | kmalloc_uaf2(); |
779 | kfree_via_page(); | ||
780 | kfree_via_phys(); | ||
740 | kmem_cache_oob(); | 781 | kmem_cache_oob(); |
741 | memcg_accounted_kmem_cache(); | 782 | memcg_accounted_kmem_cache(); |
742 | kasan_stack_oob(); | 783 | kasan_stack_oob(); |