Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

vfs/proc/kcore, x86/mm/kcore: Fix SMAP fault when dumping vsyscall user page

Commit:

df04abfd181a ("fs/proc/kcore.c: Add bounce buffer for ktext data")

... introduced a bounce buffer to work around CONFIG_HARDENED_USERCOPY=y.
However, accessing the vsyscall user page will cause an SMAP fault.

Replace memcpy() with copy_from_user() to fix this bug works, but adding
a common way to handle this sort of user page may be useful for future.

Currently, only vsyscall page requires KCORE_USER.

Signed-off-by: Jia Zhang <zhang.jia@linux.alibaba.com>
Reviewed-by: Jiri Olsa <jolsa@kernel.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: jolsa@redhat.com
Link: http://lkml.kernel.org/r/1518446694-21124-2-git-send-email-zhang.jia@linux.alibaba.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Jia Zhang and committed by
Ingo Molnar
595dd46e aec6487e

+6 -2
+1 -2
arch/x86/mm/init_64.c
··· 1193 1193 register_page_bootmem_info(); 1194 1194 1195 1195 /* Register memory areas for /proc/kcore */ 1196 - kclist_add(&kcore_vsyscall, (void *)VSYSCALL_ADDR, 1197 - PAGE_SIZE, KCORE_OTHER); 1196 + kclist_add(&kcore_vsyscall, (void *)VSYSCALL_ADDR, PAGE_SIZE, KCORE_USER); 1198 1197 1199 1198 mem_init_print_info(NULL); 1200 1199 }
+4
fs/proc/kcore.c
··· 510 510 /* we have to zero-fill user buffer even if no read */ 511 511 if (copy_to_user(buffer, buf, tsz)) 512 512 return -EFAULT; 513 + } else if (m->type == KCORE_USER) { 514 + /* User page is handled prior to normal kernel page: */ 515 + if (copy_to_user(buffer, (char *)start, tsz)) 516 + return -EFAULT; 513 517 } else { 514 518 if (kern_addr_valid(start)) { 515 519 /*
+1
include/linux/kcore.h
··· 10 10 KCORE_VMALLOC, 11 11 KCORE_RAM, 12 12 KCORE_VMEMMAP, 13 + KCORE_USER, 13 14 KCORE_OTHER, 14 15 }; 15 16