aboutsummaryrefslogtreecommitdiffstats
path: root/fs/proc/kcore.c
diff options
context:
space:
mode:
authorKairui Song <kasong@redhat.com>2019-03-07 22:05:08 -0500
committerThomas Gleixner <tglx@linutronix.de>2019-03-23 07:11:49 -0400
commitffc8599aa9763f39f6736a79da4d1575e7006f9a (patch)
tree564374b91fdfced43fbcbf2310cb05e3ca9759a4 /fs/proc/kcore.c
parentf7798711adeebde3c59ddd797a3f2da36c1005be (diff)
x86/gart: Exclude GART aperture from kcore
On machines where the GART aperture is mapped over physical RAM, /proc/kcore contains the GART aperture range. Accessing the GART range via /proc/kcore results in a kernel crash. vmcore used to have the same issue, until it was fixed with commit 2a3e83c6f96c ("x86/gart: Exclude GART aperture from vmcore")', leveraging existing hook infrastructure in vmcore to let /proc/vmcore return zeroes when attempting to read the aperture region, and so it won't read from the actual memory. Apply the same workaround for kcore. First implement the same hook infrastructure for kcore, then reuse the hook functions introduced in the previous vmcore fix. Just with some minor adjustment, rename some functions for more general usage, and simplify the hook infrastructure a bit as there is no module usage yet. Suggested-by: Baoquan He <bhe@redhat.com> Signed-off-by: Kairui Song <kasong@redhat.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Jiri Bohac <jbohac@suse.cz> Acked-by: Baoquan He <bhe@redhat.com> Cc: Borislav Petkov <bp@alien8.de> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Alexey Dobriyan <adobriyan@gmail.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Omar Sandoval <osandov@fb.com> Cc: Dave Young <dyoung@redhat.com> Link: https://lkml.kernel.org/r/20190308030508.13548-1-kasong@redhat.com
Diffstat (limited to 'fs/proc/kcore.c')
-rw-r--r--fs/proc/kcore.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
index bbcc185062bb..d29d869abec1 100644
--- a/fs/proc/kcore.c
+++ b/fs/proc/kcore.c
@@ -54,6 +54,28 @@ static LIST_HEAD(kclist_head);
54static DECLARE_RWSEM(kclist_lock); 54static DECLARE_RWSEM(kclist_lock);
55static int kcore_need_update = 1; 55static int kcore_need_update = 1;
56 56
57/*
58 * Returns > 0 for RAM pages, 0 for non-RAM pages, < 0 on error
59 * Same as oldmem_pfn_is_ram in vmcore
60 */
61static int (*mem_pfn_is_ram)(unsigned long pfn);
62
63int __init register_mem_pfn_is_ram(int (*fn)(unsigned long pfn))
64{
65 if (mem_pfn_is_ram)
66 return -EBUSY;
67 mem_pfn_is_ram = fn;
68 return 0;
69}
70
71static int pfn_is_ram(unsigned long pfn)
72{
73 if (mem_pfn_is_ram)
74 return mem_pfn_is_ram(pfn);
75 else
76 return 1;
77}
78
57/* This doesn't grab kclist_lock, so it should only be used at init time. */ 79/* This doesn't grab kclist_lock, so it should only be used at init time. */
58void __init kclist_add(struct kcore_list *new, void *addr, size_t size, 80void __init kclist_add(struct kcore_list *new, void *addr, size_t size,
59 int type) 81 int type)
@@ -465,6 +487,11 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
465 goto out; 487 goto out;
466 } 488 }
467 m = NULL; /* skip the list anchor */ 489 m = NULL; /* skip the list anchor */
490 } else if (!pfn_is_ram(__pa(start) >> PAGE_SHIFT)) {
491 if (clear_user(buffer, tsz)) {
492 ret = -EFAULT;
493 goto out;
494 }
468 } else if (m->type == KCORE_VMALLOC) { 495 } else if (m->type == KCORE_VMALLOC) {
469 vread(buf, (char *)start, tsz); 496 vread(buf, (char *)start, tsz);
470 /* we have to zero-fill user buffer even if no read */ 497 /* we have to zero-fill user buffer even if no read */