Kirill A. Shutemov
bfd40eaff5
mm: fix vma_is_anonymous() false-positives
vma_is_anonymous() relies on ->vm_ops being NULL to detect anonymous
VMA. This is unreliable as ->mmap may not set ->vm_ops.
False-positive vma_is_anonymous() may lead to crashes:
next ffff8801ce5e7040 prev ffff8801d20eca50 mm ffff88019c1e13c0
prot 27 anon_vma ffff88019680cdd8 vm_ops 0000000000000000
pgoff 0 file ffff8801b2ec2d00 private_data 0000000000000000
flags: 0xff(read|write|exec|shared|mayread|maywrite|mayexec|mayshare)
------------[ cut here ]------------
kernel BUG at mm/memory.c:1422!
invalid opcode: 0000 [#1] SMP KASAN
CPU: 0 PID: 18486 Comm: syz-executor3 Not tainted 4.18.0-rc3+ #136
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google
01/01/2011
RIP: 0010:zap_pmd_range mm/memory.c:1421 [inline]
RIP: 0010:zap_pud_range mm/memory.c:1466 [inline]
RIP: 0010:zap_p4d_range mm/memory.c:1487 [inline]
RIP: 0010:unmap_page_range+0x1c18/0x2220 mm/memory.c:1508
Call Trace:
unmap_single_vma+0x1a0/0x310 mm/memory.c:1553
zap_page_range_single+0x3cc/0x580 mm/memory.c:1644
unmap_mapping_range_vma mm/memory.c:2792 [inline]
unmap_mapping_range_tree mm/memory.c:2813 [inline]
unmap_mapping_pages+0x3a7/0x5b0 mm/memory.c:2845
unmap_mapping_range+0x48/0x60 mm/memory.c:2880
truncate_pagecache+0x54/0x90 mm/truncate.c:800
truncate_setsize+0x70/0xb0 mm/truncate.c:826
simple_setattr+0xe9/0x110 fs/libfs.c:409
notify_change+0xf13/0x10f0 fs/attr.c:335
do_truncate+0x1ac/0x2b0 fs/open.c:63
do_sys_ftruncate+0x492/0x560 fs/open.c:205
__do_sys_ftruncate fs/open.c:215 [inline]
__se_sys_ftruncate fs/open.c:213 [inline]
__x64_sys_ftruncate+0x59/0x80 fs/open.c:213
do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
entry_SYSCALL_64_after_hwframe+0x49/0xbe
Reproducer:
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <unistd.h>
#include <fcntl.h>
#define KCOV_INIT_TRACE _IOR('c', 1, unsigned long)
#define KCOV_ENABLE _IO('c', 100)
#define KCOV_DISABLE _IO('c', 101)
#define COVER_SIZE (1024<<10)
#define KCOV_TRACE_PC 0
#define KCOV_TRACE_CMP 1
int main(int argc, char **argv)
{
int fd;
unsigned long *cover;
system("mount -t debugfs none /sys/kernel/debug");
fd = open("/sys/kernel/debug/kcov", O_RDWR);
ioctl(fd, KCOV_INIT_TRACE, COVER_SIZE);
cover = mmap(NULL, COVER_SIZE * sizeof(unsigned long),
PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
munmap(cover, COVER_SIZE * sizeof(unsigned long));
cover = mmap(NULL, COVER_SIZE * sizeof(unsigned long),
PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
memset(cover, 0, COVER_SIZE * sizeof(unsigned long));
ftruncate(fd, 3UL << 20);
return 0;
}
This can be fixed by assigning anonymous VMAs own vm_ops and not relying
on it being NULL.
If ->mmap() failed to set ->vm_ops, mmap_region() will set it to
dummy_vm_ops. This way we will have non-NULL ->vm_ops for all VMAs.
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Kirill A. Shutemov <[email protected]>
Reported-by: [email protected]
Acked-by: Linus Torvalds <[email protected]>
Reviewed-by: Andrew Morton <[email protected]>
Cc: Dmitry Vyukov <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: Andrea Arcangeli <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
|
2018-07-26 19:38:03 -07:00 |
| .. |
|
kasan
|
kasan: fix shadow_size calculation error in kasan_module_alloc
|
2018-07-03 17:32:19 -07:00 |
|
backing-dev.c
|
bdi: Fix another oops in wb_workfn()
|
2018-06-22 12:08:07 -06:00 |
|
balloon_compaction.c
|
|
|
|
bootmem.c
|
mm: docs: fix parameter names mismatch
|
2018-02-06 18:32:48 -08:00 |
|
cleancache.c
|
mm: use octal not symbolic permissions
|
2018-06-15 07:55:25 +09:00 |
|
cma.c
|
Revert "mm/cma: manage the memory of the CMA area by using the ZONE_MOVABLE"
|
2018-05-24 10:07:50 -07:00 |
|
cma.h
|
|
|
|
cma_debug.c
|
mm: use octal not symbolic permissions
|
2018-06-15 07:55:25 +09:00 |
|
compaction.c
|
mm: use octal not symbolic permissions
|
2018-06-15 07:55:25 +09:00 |
|
debug.c
|
mm: teach dump_page() to correctly output poisoned struct pages
|
2018-07-03 17:32:19 -07:00 |
|
debug_page_ref.c
|
|
|
|
dmapool.c
|
mm: use octal not symbolic permissions
|
2018-06-15 07:55:25 +09:00 |
|
early_ioremap.c
|
|
|
|
fadvise.c
|
mm: add ksys_fadvise64_64() helper; remove in-kernel call to sys_fadvise64_64()
|
2018-04-02 20:16:10 +02:00 |
|
failslab.c
|
mm: use octal not symbolic permissions
|
2018-06-15 07:55:25 +09:00 |
|
filemap.c
|
mm: use new return type vm_fault_t
|
2018-06-07 17:34:36 -07:00 |
|
frame_vector.c
|
|
|
|
frontswap.c
|
mm: use octal not symbolic permissions
|
2018-06-15 07:55:25 +09:00 |
|
gup.c
|
mm: do not bug_on on incorrect length in __mm_populate()
|
2018-07-14 11:11:10 -07:00 |
|
gup_benchmark.c
|
treewide: kvzalloc() -> kvcalloc()
|
2018-06-12 16:19:22 -07:00 |
|
highmem.c
|
|
|
|
hmm.c
|
mm: introduce MEMORY_DEVICE_FS_DAX and CONFIG_DEV_PAGEMAP_OPS
|
2018-05-22 06:59:39 -07:00 |
|
huge_memory.c
|
mm/huge_memory.c: fix data loss when splitting a file pmd
|
2018-07-21 12:50:46 -07:00 |
|
hugetlb.c
|
mm: hugetlb: yield when prepping struct pages
|
2018-07-03 17:32:19 -07:00 |
|
hugetlb_cgroup.c
|
mm: rename page_counter's count/limit into usage/max
|
2018-06-07 17:34:35 -07:00 |
|
hwpoison-inject.c
|
mm/memory_failure: Remove unused trapno from memory_failure
|
2018-01-23 12:17:42 -06:00 |
|
init-mm.c
|
mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct
|
2018-06-07 17:34:34 -07:00 |
|
internal.h
|
Changes for 4.18:
|
2018-06-05 13:24:20 -07:00 |
|
interval_tree.c
|
mm/interval_tree.c: use vma_pages() helper
|
2018-01-31 17:18:37 -08:00 |
|
Kconfig
|
libnvdimm for 4.18
|
2018-06-08 17:21:52 -07:00 |
|
Kconfig.debug
|
|
|
|
khugepaged.c
|
page cache: use xa_lock
|
2018-04-11 10:28:39 -07:00 |
|
kmemleak-test.c
|
|
|
|
kmemleak.c
|
mm: kernel-doc: add missing parameter descriptions
|
2018-04-05 21:36:27 -07:00 |
|
ksm.c
|
mm/ksm.c: ignore STABLE_FLAG of rmap_item->address in rmap_walk_ksm()
|
2018-06-15 07:55:23 +09:00 |
|
list_lru.c
|
mm: make counting of list_lru_one::nr_items lockless
|
2018-04-05 21:36:27 -07:00 |
|
maccess.c
|
mm: docs: fix parameter names mismatch
|
2018-02-06 18:32:48 -08:00 |
|
madvise.c
|
mm/memory_failure: Remove unused trapno from memory_failure
|
2018-01-23 12:17:42 -06:00 |
|
Makefile
|
mm: restructure memfd code
|
2018-06-07 17:34:35 -07:00 |
|
memblock.c
|
mm/memblock: add missing include <linux/bootmem.h>
|
2018-07-21 12:50:46 -07:00 |
|
memcontrol.c
|
mm: memcg: fix use after free in mem_cgroup_iter()
|
2018-07-21 12:50:46 -07:00 |
|
memfd.c
|
mm: restructure memfd code
|
2018-06-07 17:34:35 -07:00 |
|
memory-failure.c
|
mm, migrate: remove reason argument from new_page_t
|
2018-04-11 10:28:32 -07:00 |
|
memory.c
|
Merge branch 'akpm' (patches from Andrew)
|
2018-06-07 18:39:37 -07:00 |
|
memory_hotplug.c
|
mm: move is_pageblock_removable_nolock() to mm/memory_hotplug.c
|
2018-06-07 17:34:36 -07:00 |
|
mempolicy.c
|
mm: use vma_init() to initialize VMAs on stack and data segments
|
2018-07-26 19:38:03 -07:00 |
|
mempool.c
|
mempool: Add mempool_init()/mempool_exit()
|
2018-05-14 13:14:23 -06:00 |
|
memtest.c
|
|
|
|
migrate.c
|
mm: migrate: fix double call of radix_tree_replace_slot()
|
2018-05-11 17:28:45 -07:00 |
|
mincore.c
|
|
|
|
mlock.c
|
mm, mlock, vmscan: no more skipping pagevecs
|
2018-02-21 15:35:42 -08:00 |
|
mm_init.c
|
|
|
|
mmap.c
|
mm: fix vma_is_anonymous() false-positives
|
2018-07-26 19:38:03 -07:00 |
|
mmu_context.c
|
|
|
|
mmu_notifier.c
|
mm, mmu_notifier: annotate mmu notifiers with blockable invalidate callbacks
|
2018-01-31 17:18:38 -08:00 |
|
mmzone.c
|
|
|
|
mprotect.c
|
sched/numa: avoid trapping faults and attempting migration of file-backed dirty pages
|
2018-04-11 10:28:31 -07:00 |
|
mremap.c
|
mremap: remove LATENCY_LIMIT from mremap to reduce the number of TLB shootdowns
|
2018-06-15 07:55:24 +09:00 |
|
msync.c
|
|
|
|
nobootmem.c
|
|
|
|
nommu.c
|
mm: fix vma_is_anonymous() false-positives
|
2018-07-26 19:38:03 -07:00 |
|
oom_kill.c
|
mm: fix oom_kill event handling
|
2018-06-15 07:55:25 +09:00 |
|
page-writeback.c
|
writeback: safer lock nesting
|
2018-04-20 17:18:35 -07:00 |
|
page_alloc.c
|
mm: don't do zero_resv_unavail if memmap is not allocated
|
2018-07-16 09:41:57 -07:00 |
|
page_counter.c
|
memcg: introduce memory.min
|
2018-06-07 17:34:36 -07:00 |
|
page_ext.c
|
mm/page_ext.c: make page_ext_init a noop when CONFIG_PAGE_EXTENSION but nothing uses it
|
2018-01-31 17:18:39 -08:00 |
|
page_idle.c
|
mm: use octal not symbolic permissions
|
2018-06-15 07:55:25 +09:00 |
|
page_io.c
|
|
|
|
page_isolation.c
|
mm, migrate: remove reason argument from new_page_t
|
2018-04-11 10:28:32 -07:00 |
|
page_owner.c
|
mm: use octal not symbolic permissions
|
2018-06-15 07:55:25 +09:00 |
|
page_poison.c
|
mm/page_poison.c: make early_page_poison_param() __init
|
2018-04-05 21:36:26 -07:00 |
|
page_vma_mapped.c
|
|
|
|
pagewalk.c
|
mm: kernel-doc: add missing parameter descriptions
|
2018-04-05 21:36:27 -07:00 |
|
percpu-internal.h
|
|
|
|
percpu-km.c
|
percpu: allow select gfp to be passed to underlying allocators
|
2018-02-18 05:33:01 -08:00 |
|
percpu-stats.c
|
treewide: Use array_size() in vmalloc()
|
2018-06-12 16:19:22 -07:00 |
|
percpu-vm.c
|
percpu: allow select gfp to be passed to underlying allocators
|
2018-02-18 05:33:01 -08:00 |
|
percpu.c
|
arch: remove obsolete architecture ports
|
2018-04-02 20:20:12 -07:00 |
|
pgtable-generic.c
|
mm: do not lose dirty and accessed bits in pmdp_invalidate()
|
2018-01-31 17:18:38 -08:00 |
|
process_vm_access.c
|
mm: docs: add blank lines to silence sphinx "Unexpected indentation" errors
|
2018-02-06 18:32:48 -08:00 |
|
quicklist.c
|
|
|
|
readahead.c
|
mm: split ->readpages calls to avoid non-contiguous pages lists
|
2018-06-01 18:37:32 -07:00 |
|
rmap.c
|
mm: do not drop unused pages when userfaultd is running
|
2018-07-14 11:11:09 -07:00 |
|
rodata_test.c
|
|
|
|
shmem.c
|
mm: use vma_init() to initialize VMAs on stack and data segments
|
2018-07-26 19:38:03 -07:00 |
|
slab.c
|
treewide: kzalloc() -> kcalloc()
|
2018-06-12 16:19:22 -07:00 |
|
slab.h
|
slab, slub: skip unnecessary kasan_cache_shutdown()
|
2018-04-05 21:36:24 -07:00 |
|
slab_common.c
|
slub: fix failure when we delete and create a slab cache
|
2018-06-28 11:16:44 -07:00 |
|
slob.c
|
slab: __GFP_ZERO is incompatible with a constructor
|
2018-06-07 17:34:34 -07:00 |
|
slub.c
|
slub: fix failure when we delete and create a slab cache
|
2018-06-28 11:16:44 -07:00 |
|
sparse-vmemmap.c
|
|
|
|
sparse.c
|
mm/sparse.c: pass the __highest_present_section_nr + 1 to alloc_func()
|
2018-06-07 17:34:35 -07:00 |
|
swap.c
|
mm: introduce MEMORY_DEVICE_FS_DAX and CONFIG_DEV_PAGEMAP_OPS
|
2018-05-22 06:59:39 -07:00 |
|
swap_cgroup.c
|
|
|
|
swap_slots.c
|
treewide: kvzalloc() -> kvcalloc()
|
2018-06-12 16:19:22 -07:00 |
|
swap_state.c
|
treewide: kvzalloc() -> kvcalloc()
|
2018-06-12 16:19:22 -07:00 |
|
swapfile.c
|
mm/swapfile.c: fix swap_count comment about nonexistent SWAP_HAS_CONT
|
2018-06-15 07:55:23 +09:00 |
|
truncate.c
|
page cache: use xa_lock
|
2018-04-11 10:28:39 -07:00 |
|
usercopy.c
|
|
|
|
userfaultfd.c
|
userfaultfd: prevent non-cooperative events vs mcopy_atomic races
|
2018-06-07 17:34:38 -07:00 |
|
util.c
|
mm: kvmalloc does not fallback to vmalloc for incompatible gfp flags
|
2018-06-07 17:34:38 -07:00 |
|
vmacache.c
|
|
|
|
vmalloc.c
|
mm: use octal not symbolic permissions
|
2018-06-15 07:55:25 +09:00 |
|
vmpressure.c
|
mm/vmpressure.c: convert to use match_string() helper
|
2018-06-07 17:34:36 -07:00 |
|
vmscan.c
|
memcg: introduce memory.min
|
2018-06-07 17:34:36 -07:00 |
|
vmstat.c
|
Revert mm/vmstat.c: fix vmstat_update() preemption BUG
|
2018-06-28 11:16:44 -07:00 |
|
workingset.c
|
page cache: use xa_lock
|
2018-04-11 10:28:39 -07:00 |
|
z3fold.c
|
z3fold: fix reclaim lock-ups
|
2018-05-11 17:28:45 -07:00 |
|
zbud.c
|
mm: docs: fix parameter names mismatch
|
2018-02-06 18:32:48 -08:00 |
|
zpool.c
|
mm/zpool.c: zpool_evictable: fix mismatch in parameter name and kernel-doc
|
2018-02-21 15:35:43 -08:00 |
|
zsmalloc.c
|
mm: use octal not symbolic permissions
|
2018-06-15 07:55:25 +09:00 |
|
zswap.c
|
mm: use octal not symbolic permissions
|
2018-06-15 07:55:25 +09:00 |