hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/fs/proc/kcore.c
....@@ -22,7 +22,7 @@
2222 #include <linux/vmalloc.h>
2323 #include <linux/highmem.h>
2424 #include <linux/printk.h>
25
-#include <linux/bootmem.h>
25
+#include <linux/memblock.h>
2626 #include <linux/init.h>
2727 #include <linux/slab.h>
2828 #include <linux/uaccess.h>
....@@ -31,6 +31,7 @@
3131 #include <linux/ioport.h>
3232 #include <linux/memory.h>
3333 #include <linux/sched/task.h>
34
+#include <linux/security.h>
3435 #include <asm/sections.h>
3536 #include "internal.h"
3637
....@@ -192,8 +193,6 @@
192193 return 1;
193194
194195 p = pfn_to_page(pfn);
195
- if (!memmap_valid_within(pfn, p, page_zone(p)))
196
- return 1;
197196
198197 ent = kmalloc(sizeof(*ent), GFP_KERNEL);
199198 if (!ent)
....@@ -511,7 +510,8 @@
511510 * Using bounce buffer to bypass the
512511 * hardened user copy kernel text checks.
513512 */
514
- if (probe_kernel_read(buf, (void *) start, tsz)) {
513
+ if (copy_from_kernel_nofault(buf, (void *)start,
514
+ tsz)) {
515515 if (clear_user(buffer, tsz)) {
516516 ret = -EFAULT;
517517 goto out;
....@@ -545,8 +545,13 @@
545545
546546 static int open_kcore(struct inode *inode, struct file *filp)
547547 {
548
+ int ret = security_locked_down(LOCKDOWN_KCORE);
549
+
548550 if (!capable(CAP_SYS_RAWIO))
549551 return -EPERM;
552
+
553
+ if (ret)
554
+ return ret;
550555
551556 filp->private_data = kmalloc(PAGE_SIZE, GFP_KERNEL);
552557 if (!filp->private_data)
....@@ -568,11 +573,11 @@
568573 return 0;
569574 }
570575
571
-static const struct file_operations proc_kcore_operations = {
572
- .read = read_kcore,
573
- .open = open_kcore,
574
- .release = release_kcore,
575
- .llseek = default_llseek,
576
+static const struct proc_ops kcore_proc_ops = {
577
+ .proc_read = read_kcore,
578
+ .proc_open = open_kcore,
579
+ .proc_release = release_kcore,
580
+ .proc_lseek = default_llseek,
576581 };
577582
578583 /* just remember that we have to update kcore */
....@@ -615,7 +620,7 @@
615620 /*
616621 * MODULES_VADDR has no intersection with VMALLOC_ADDR.
617622 */
618
-struct kcore_list kcore_modules;
623
+static struct kcore_list kcore_modules;
619624 static void __init add_modules_range(void)
620625 {
621626 if (MODULES_VADDR != VMALLOC_START && MODULES_END != VMALLOC_END) {
....@@ -631,8 +636,7 @@
631636
632637 static int __init proc_kcore_init(void)
633638 {
634
- proc_root_kcore = proc_create("kcore", S_IRUSR, NULL,
635
- &proc_kcore_operations);
639
+ proc_root_kcore = proc_create("kcore", S_IRUSR, NULL, &kcore_proc_ops);
636640 if (!proc_root_kcore) {
637641 pr_err("couldn't create /proc/kcore\n");
638642 return 0; /* Always returns 0. */