hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/fs/proc/vmcore.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * fs/proc/vmcore.c Interface for accessing the crash
34 * dump from the system's previous life.
....@@ -16,14 +17,16 @@
1617 #include <linux/slab.h>
1718 #include <linux/highmem.h>
1819 #include <linux/printk.h>
19
-#include <linux/bootmem.h>
20
+#include <linux/memblock.h>
2021 #include <linux/init.h>
2122 #include <linux/crash_dump.h>
2223 #include <linux/list.h>
24
+#include <linux/moduleparam.h>
2325 #include <linux/mutex.h>
2426 #include <linux/vmalloc.h>
2527 #include <linux/pagemap.h>
2628 #include <linux/uaccess.h>
29
+#include <linux/mem_encrypt.h>
2730 #include <asm/io.h>
2831 #include "internal.h"
2932
....@@ -51,6 +54,9 @@
5154 /* Device Dump list and mutex to synchronize access to list */
5255 static LIST_HEAD(vmcoredd_list);
5356 static DEFINE_MUTEX(vmcoredd_mutex);
57
+
58
+static bool vmcoredd_disabled;
59
+core_param(novmcoredd, vmcoredd_disabled, bool, 0);
5460 #endif /* CONFIG_PROC_VMCORE_DEVICE_DUMP */
5561
5662 /* Device Dump Size */
....@@ -97,8 +103,9 @@
97103 }
98104
99105 /* Reads a page from the oldmem device from given offset. */
100
-static ssize_t read_from_oldmem(char *buf, size_t count,
101
- u64 *ppos, int userbuf)
106
+ssize_t read_from_oldmem(char *buf, size_t count,
107
+ u64 *ppos, int userbuf,
108
+ bool encrypted)
102109 {
103110 unsigned long pfn, offset;
104111 size_t nr_bytes;
....@@ -124,8 +131,14 @@
124131 else if (clear_user(buf, nr_bytes))
125132 tmp = -EFAULT;
126133 } else {
127
- tmp = copy_oldmem_page(pfn, buf, nr_bytes,
128
- offset, userbuf);
134
+ if (encrypted)
135
+ tmp = copy_oldmem_page_encrypted(pfn, buf,
136
+ nr_bytes,
137
+ offset,
138
+ userbuf);
139
+ else
140
+ tmp = copy_oldmem_page(pfn, buf, nr_bytes,
141
+ offset, userbuf);
129142 }
130143 if (tmp < 0)
131144 return tmp;
....@@ -160,7 +173,7 @@
160173 */
161174 ssize_t __weak elfcorehdr_read(char *buf, size_t count, u64 *ppos)
162175 {
163
- return read_from_oldmem(buf, count, ppos, 0);
176
+ return read_from_oldmem(buf, count, ppos, 0, false);
164177 }
165178
166179 /*
....@@ -168,7 +181,7 @@
168181 */
169182 ssize_t __weak elfcorehdr_read_notes(char *buf, size_t count, u64 *ppos)
170183 {
171
- return read_from_oldmem(buf, count, ppos, 0);
184
+ return read_from_oldmem(buf, count, ppos, 0, mem_encrypt_active());
172185 }
173186
174187 /*
....@@ -178,6 +191,7 @@
178191 unsigned long from, unsigned long pfn,
179192 unsigned long size, pgprot_t prot)
180193 {
194
+ prot = pgprot_encrypted(prot);
181195 return remap_pfn_range(vma, from, pfn, size, prot);
182196 }
183197
....@@ -367,7 +381,8 @@
367381 m->offset + m->size - *fpos,
368382 buflen);
369383 start = m->paddr + *fpos - m->offset;
370
- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
384
+ tmp = read_from_oldmem(buffer, tsz, &start,
385
+ userbuf, mem_encrypt_active());
371386 if (tmp < 0)
372387 return tmp;
373388 buflen -= tsz;
....@@ -417,7 +432,7 @@
417432 if (rc < 0) {
418433 unlock_page(page);
419434 put_page(page);
420
- return (rc == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS;
435
+ return vmf_error(rc);
421436 }
422437 SetPageUptodate(page);
423438 }
....@@ -656,10 +671,10 @@
656671 }
657672 #endif
658673
659
-static const struct file_operations proc_vmcore_operations = {
660
- .read = read_vmcore,
661
- .llseek = default_llseek,
662
- .mmap = mmap_vmcore,
674
+static const struct proc_ops vmcore_proc_ops = {
675
+ .proc_read = read_vmcore,
676
+ .proc_lseek = default_llseek,
677
+ .proc_mmap = mmap_vmcore,
663678 };
664679
665680 static struct vmcore* __init get_new_element(void)
....@@ -1445,6 +1460,11 @@
14451460 size_t data_size;
14461461 int ret;
14471462
1463
+ if (vmcoredd_disabled) {
1464
+ pr_err_once("Device dump is disabled\n");
1465
+ return -EINVAL;
1466
+ }
1467
+
14481468 if (!data || !strlen(data->dump_name) ||
14491469 !data->vmcoredd_callback || !data->size)
14501470 return -EINVAL;
....@@ -1539,7 +1559,7 @@
15391559 elfcorehdr_free(elfcorehdr_addr);
15401560 elfcorehdr_addr = ELFCORE_ADDR_ERR;
15411561
1542
- proc_vmcore = proc_create("vmcore", S_IRUSR, NULL, &proc_vmcore_operations);
1562
+ proc_vmcore = proc_create("vmcore", S_IRUSR, NULL, &vmcore_proc_ops);
15431563 if (proc_vmcore)
15441564 proc_vmcore->size = vmcore_size;
15451565 return 0;