License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 14:07:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* fs/proc/kcore.c kernel ELF core dumper
|
|
|
|
*
|
|
|
|
* Modelled on fs/exec.c:aout_core_dump()
|
|
|
|
* Jeremy Fitzhardinge <jeremy@sw.oz.au>
|
|
|
|
* ELF version written by David Howells <David.Howells@nexor.co.uk>
|
|
|
|
* Modified and incorporated into 2.3.x by Tigran Aivazian <tigran@veritas.com>
|
|
|
|
* Support to dump vmalloc'd areas (ELF only), Tigran Aivazian <tigran@veritas.com>
|
|
|
|
* Safe accesses to vmalloc/direct-mapped discontiguous areas, Kanoj Sarcar <kanoj@sgi.com>
|
|
|
|
*/
|
|
|
|
|
2018-08-22 04:55:20 +00:00
|
|
|
#include <linux/crash_core.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/proc_fs.h>
|
2013-04-11 23:10:25 +00:00
|
|
|
#include <linux/kcore.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/user.h>
|
2006-01-11 20:17:46 +00:00
|
|
|
#include <linux/capability.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/elf.h>
|
|
|
|
#include <linux/elfcore.h>
|
2013-04-29 22:08:08 +00:00
|
|
|
#include <linux/notifier.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/vmalloc.h>
|
|
|
|
#include <linux/highmem.h>
|
2013-02-28 01:03:16 +00:00
|
|
|
#include <linux/printk.h>
|
2018-10-30 22:09:49 +00:00
|
|
|
#include <linux/memblock.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/init.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2016-12-24 19:46:01 +00:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <asm/io.h>
|
2009-09-22 23:45:41 +00:00
|
|
|
#include <linux/list.h>
|
2009-09-22 23:45:48 +00:00
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/memory.h>
|
2017-02-08 17:51:36 +00:00
|
|
|
#include <linux/sched/task.h>
|
2019-08-20 00:17:57 +00:00
|
|
|
#include <linux/security.h>
|
2009-09-22 23:45:45 +00:00
|
|
|
#include <asm/sections.h>
|
2013-04-11 12:34:43 +00:00
|
|
|
#include "internal.h"
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-12-07 04:38:00 +00:00
|
|
|
#define CORE_STR "CORE"
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-07-25 08:48:10 +00:00
|
|
|
#ifndef ELF_CORE_EFLAGS
|
|
|
|
#define ELF_CORE_EFLAGS 0
|
|
|
|
#endif
|
|
|
|
|
2008-10-06 10:14:19 +00:00
|
|
|
static struct proc_dir_entry *proc_root_kcore;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#ifndef kc_vaddr_to_offset
|
|
|
|
#define kc_vaddr_to_offset(v) ((v) - PAGE_OFFSET)
|
|
|
|
#endif
|
|
|
|
#ifndef kc_offset_to_vaddr
|
|
|
|
#define kc_offset_to_vaddr(o) ((o) + PAGE_OFFSET)
|
|
|
|
#endif
|
|
|
|
|
2009-09-22 23:45:41 +00:00
|
|
|
static LIST_HEAD(kclist_head);
|
2018-08-22 04:54:59 +00:00
|
|
|
static DECLARE_RWSEM(kclist_lock);
|
2009-09-22 23:45:48 +00:00
|
|
|
static int kcore_need_update = 1;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2019-03-08 03:05:08 +00:00
|
|
|
/*
|
|
|
|
* Returns > 0 for RAM pages, 0 for non-RAM pages, < 0 on error
|
|
|
|
* Same as oldmem_pfn_is_ram in vmcore
|
|
|
|
*/
|
|
|
|
static int (*mem_pfn_is_ram)(unsigned long pfn);
|
|
|
|
|
|
|
|
int __init register_mem_pfn_is_ram(int (*fn)(unsigned long pfn))
|
|
|
|
{
|
|
|
|
if (mem_pfn_is_ram)
|
|
|
|
return -EBUSY;
|
|
|
|
mem_pfn_is_ram = fn;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pfn_is_ram(unsigned long pfn)
|
|
|
|
{
|
|
|
|
if (mem_pfn_is_ram)
|
|
|
|
return mem_pfn_is_ram(pfn);
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-08-22 04:54:51 +00:00
|
|
|
/* This doesn't grab kclist_lock, so it should only be used at init time. */
|
|
|
|
void __init kclist_add(struct kcore_list *new, void *addr, size_t size,
|
|
|
|
int type)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
new->addr = (unsigned long)addr;
|
|
|
|
new->size = size;
|
2009-09-22 23:45:43 +00:00
|
|
|
new->type = type;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-09-22 23:45:41 +00:00
|
|
|
list_add_tail(&new->list, &kclist_head);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2018-08-22 04:55:09 +00:00
|
|
|
static size_t get_kcore_size(int *nphdr, size_t *phdrs_len, size_t *notes_len,
|
|
|
|
size_t *data_offset)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
size_t try, size;
|
|
|
|
struct kcore_list *m;
|
|
|
|
|
|
|
|
*nphdr = 1; /* PT_NOTE */
|
|
|
|
size = 0;
|
|
|
|
|
2009-09-22 23:45:41 +00:00
|
|
|
list_for_each_entry(m, &kclist_head, list) {
|
2005-04-16 22:20:36 +00:00
|
|
|
try = kc_vaddr_to_offset((size_t)m->addr + m->size);
|
|
|
|
if (try > size)
|
|
|
|
size = try;
|
|
|
|
*nphdr = *nphdr + 1;
|
|
|
|
}
|
2018-08-22 04:55:09 +00:00
|
|
|
|
|
|
|
*phdrs_len = *nphdr * sizeof(struct elf_phdr);
|
2018-08-22 04:55:20 +00:00
|
|
|
*notes_len = (4 * sizeof(struct elf_note) +
|
|
|
|
3 * ALIGN(sizeof(CORE_STR), 4) +
|
|
|
|
VMCOREINFO_NOTE_NAME_BYTES +
|
2018-08-22 04:55:09 +00:00
|
|
|
ALIGN(sizeof(struct elf_prstatus), 4) +
|
|
|
|
ALIGN(sizeof(struct elf_prpsinfo), 4) +
|
2018-08-22 04:55:20 +00:00
|
|
|
ALIGN(arch_task_struct_size, 4) +
|
|
|
|
ALIGN(vmcoreinfo_size, 4));
|
2018-08-22 04:55:09 +00:00
|
|
|
*data_offset = PAGE_ALIGN(sizeof(struct elfhdr) + *phdrs_len +
|
|
|
|
*notes_len);
|
|
|
|
return *data_offset + size;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2009-09-22 23:45:48 +00:00
|
|
|
#ifdef CONFIG_HIGHMEM
|
|
|
|
/*
|
|
|
|
* If no highmem, we can assume [0...max_low_pfn) continuous range of memory
|
|
|
|
* because memory hole is not as big as !HIGHMEM case.
|
|
|
|
* (HIGHMEM is special because part of memory is _invisible_ from the kernel.)
|
|
|
|
*/
|
2018-08-22 04:55:02 +00:00
|
|
|
static int kcore_ram_list(struct list_head *head)
|
2009-09-22 23:45:48 +00:00
|
|
|
{
|
|
|
|
struct kcore_list *ent;
|
|
|
|
|
|
|
|
ent = kmalloc(sizeof(*ent), GFP_KERNEL);
|
|
|
|
if (!ent)
|
|
|
|
return -ENOMEM;
|
|
|
|
ent->addr = (unsigned long)__va(0);
|
|
|
|
ent->size = max_low_pfn << PAGE_SHIFT;
|
|
|
|
ent->type = KCORE_RAM;
|
2018-08-22 04:55:02 +00:00
|
|
|
list_add(&ent->list, head);
|
|
|
|
return 0;
|
2009-09-22 23:45:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#else /* !CONFIG_HIGHMEM */
|
|
|
|
|
2009-09-22 23:45:49 +00:00
|
|
|
#ifdef CONFIG_SPARSEMEM_VMEMMAP
|
|
|
|
/* calculate vmemmap's address from given system ram pfn and register it */
|
2012-03-23 22:02:52 +00:00
|
|
|
static int
|
|
|
|
get_sparsemem_vmemmap_info(struct kcore_list *ent, struct list_head *head)
|
2009-09-22 23:45:49 +00:00
|
|
|
{
|
|
|
|
unsigned long pfn = __pa(ent->addr) >> PAGE_SHIFT;
|
|
|
|
unsigned long nr_pages = ent->size >> PAGE_SHIFT;
|
|
|
|
unsigned long start, end;
|
|
|
|
struct kcore_list *vmm, *tmp;
|
|
|
|
|
|
|
|
|
|
|
|
start = ((unsigned long)pfn_to_page(pfn)) & PAGE_MASK;
|
|
|
|
end = ((unsigned long)pfn_to_page(pfn + nr_pages)) - 1;
|
2014-08-08 21:21:20 +00:00
|
|
|
end = PAGE_ALIGN(end);
|
2009-09-22 23:45:49 +00:00
|
|
|
/* overlap check (because we have to align page */
|
|
|
|
list_for_each_entry(tmp, head, list) {
|
|
|
|
if (tmp->type != KCORE_VMEMMAP)
|
|
|
|
continue;
|
|
|
|
if (start < tmp->addr + tmp->size)
|
|
|
|
if (end > tmp->addr)
|
|
|
|
end = tmp->addr;
|
|
|
|
}
|
|
|
|
if (start < end) {
|
|
|
|
vmm = kmalloc(sizeof(*vmm), GFP_KERNEL);
|
|
|
|
if (!vmm)
|
|
|
|
return 0;
|
|
|
|
vmm->addr = start;
|
|
|
|
vmm->size = end - start;
|
|
|
|
vmm->type = KCORE_VMEMMAP;
|
|
|
|
list_add_tail(&vmm->list, head);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
#else
|
2012-03-23 22:02:52 +00:00
|
|
|
static int
|
|
|
|
get_sparsemem_vmemmap_info(struct kcore_list *ent, struct list_head *head)
|
2009-09-22 23:45:49 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2009-09-22 23:45:48 +00:00
|
|
|
static int
|
|
|
|
kclist_add_private(unsigned long pfn, unsigned long nr_pages, void *arg)
|
|
|
|
{
|
|
|
|
struct list_head *head = (struct list_head *)arg;
|
|
|
|
struct kcore_list *ent;
|
2018-05-11 23:01:57 +00:00
|
|
|
struct page *p;
|
|
|
|
|
|
|
|
if (!pfn_valid(pfn))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
p = pfn_to_page(pfn);
|
2009-09-22 23:45:48 +00:00
|
|
|
|
|
|
|
ent = kmalloc(sizeof(*ent), GFP_KERNEL);
|
|
|
|
if (!ent)
|
|
|
|
return -ENOMEM;
|
2018-05-11 23:01:57 +00:00
|
|
|
ent->addr = (unsigned long)page_to_virt(p);
|
2009-09-22 23:45:48 +00:00
|
|
|
ent->size = nr_pages << PAGE_SHIFT;
|
|
|
|
|
2018-05-11 23:01:57 +00:00
|
|
|
if (!virt_addr_valid(ent->addr))
|
2009-09-22 23:45:48 +00:00
|
|
|
goto free_out;
|
|
|
|
|
|
|
|
/* cut not-mapped area. ....from ppc-32 code. */
|
|
|
|
if (ULONG_MAX - ent->addr < ent->size)
|
|
|
|
ent->size = ULONG_MAX - ent->addr;
|
|
|
|
|
2018-05-11 23:01:57 +00:00
|
|
|
/*
|
|
|
|
* We've already checked virt_addr_valid so we know this address
|
|
|
|
* is a valid pointer, therefore we can check against it to determine
|
|
|
|
* if we need to trim
|
|
|
|
*/
|
|
|
|
if (VMALLOC_START > ent->addr) {
|
2009-09-22 23:45:48 +00:00
|
|
|
if (VMALLOC_START - ent->addr < ent->size)
|
|
|
|
ent->size = VMALLOC_START - ent->addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
ent->type = KCORE_RAM;
|
|
|
|
list_add_tail(&ent->list, head);
|
2009-09-22 23:45:49 +00:00
|
|
|
|
|
|
|
if (!get_sparsemem_vmemmap_info(ent, head)) {
|
|
|
|
list_del(&ent->list);
|
|
|
|
goto free_out;
|
|
|
|
}
|
|
|
|
|
2009-09-22 23:45:48 +00:00
|
|
|
return 0;
|
|
|
|
free_out:
|
|
|
|
kfree(ent);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-08-22 04:55:02 +00:00
|
|
|
static int kcore_ram_list(struct list_head *list)
|
2009-09-22 23:45:48 +00:00
|
|
|
{
|
|
|
|
int nid, ret;
|
|
|
|
unsigned long end_pfn;
|
|
|
|
|
|
|
|
/* Not inialized....update now */
|
|
|
|
/* find out "max pfn" */
|
|
|
|
end_pfn = 0;
|
2012-12-12 21:51:25 +00:00
|
|
|
for_each_node_state(nid, N_MEMORY) {
|
2009-09-22 23:45:48 +00:00
|
|
|
unsigned long node_end;
|
2013-11-12 23:07:19 +00:00
|
|
|
node_end = node_end_pfn(nid);
|
2009-09-22 23:45:48 +00:00
|
|
|
if (end_pfn < node_end)
|
|
|
|
end_pfn = node_end;
|
|
|
|
}
|
|
|
|
/* scan 0 to max_pfn */
|
2018-08-22 04:55:02 +00:00
|
|
|
ret = walk_system_ram_range(0, end_pfn, list, kclist_add_private);
|
|
|
|
if (ret)
|
2009-09-22 23:45:48 +00:00
|
|
|
return -ENOMEM;
|
2018-08-22 04:55:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_HIGHMEM */
|
|
|
|
|
|
|
|
static int kcore_update_ram(void)
|
|
|
|
{
|
|
|
|
LIST_HEAD(list);
|
|
|
|
LIST_HEAD(garbage);
|
|
|
|
int nphdr;
|
2018-08-22 04:55:09 +00:00
|
|
|
size_t phdrs_len, notes_len, data_offset;
|
2018-08-22 04:55:02 +00:00
|
|
|
struct kcore_list *tmp, *pos;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
down_write(&kclist_lock);
|
|
|
|
if (!xchg(&kcore_need_update, 0))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = kcore_ram_list(&list);
|
|
|
|
if (ret) {
|
|
|
|
/* Couldn't get the RAM list, try again next time. */
|
|
|
|
WRITE_ONCE(kcore_need_update, 1);
|
|
|
|
list_splice_tail(&list, &garbage);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_for_each_entry_safe(pos, tmp, &kclist_head, list) {
|
|
|
|
if (pos->type == KCORE_RAM || pos->type == KCORE_VMEMMAP)
|
|
|
|
list_move(&pos->list, &garbage);
|
|
|
|
}
|
|
|
|
list_splice_tail(&list, &kclist_head);
|
|
|
|
|
2018-08-22 04:55:09 +00:00
|
|
|
proc_root_kcore->size = get_kcore_size(&nphdr, &phdrs_len, ¬es_len,
|
|
|
|
&data_offset);
|
2018-08-22 04:55:02 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
up_write(&kclist_lock);
|
|
|
|
list_for_each_entry_safe(pos, tmp, &garbage, list) {
|
|
|
|
list_del(&pos->list);
|
|
|
|
kfree(pos);
|
2009-09-22 23:45:48 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2018-08-22 04:55:09 +00:00
|
|
|
static void append_kcore_note(char *notes, size_t *i, const char *name,
|
|
|
|
unsigned int type, const void *desc,
|
|
|
|
size_t descsz)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2018-08-22 04:55:09 +00:00
|
|
|
struct elf_note *note = (struct elf_note *)¬es[*i];
|
|
|
|
|
|
|
|
note->n_namesz = strlen(name) + 1;
|
|
|
|
note->n_descsz = descsz;
|
|
|
|
note->n_type = type;
|
|
|
|
*i += sizeof(*note);
|
|
|
|
memcpy(¬es[*i], name, note->n_namesz);
|
|
|
|
*i = ALIGN(*i + note->n_namesz, 4);
|
|
|
|
memcpy(¬es[*i], desc, descsz);
|
|
|
|
*i = ALIGN(*i + descsz, 4);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
static ssize_t
|
|
|
|
read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
|
|
|
|
{
|
2016-09-08 07:57:07 +00:00
|
|
|
char *buf = file->private_data;
|
2018-08-22 04:55:09 +00:00
|
|
|
size_t phdrs_offset, notes_offset, data_offset;
|
2021-07-01 01:50:21 +00:00
|
|
|
size_t page_offline_frozen = 1;
|
2018-08-22 04:55:09 +00:00
|
|
|
size_t phdrs_len, notes_len;
|
|
|
|
struct kcore_list *m;
|
|
|
|
size_t tsz;
|
2005-04-16 22:20:36 +00:00
|
|
|
int nphdr;
|
|
|
|
unsigned long start;
|
2018-08-22 04:55:06 +00:00
|
|
|
size_t orig_buflen = buflen;
|
|
|
|
int ret = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2018-08-22 04:54:59 +00:00
|
|
|
down_read(&kclist_lock);
|
2021-07-01 01:50:21 +00:00
|
|
|
/*
|
|
|
|
* Don't race against drivers that set PageOffline() and expect no
|
|
|
|
* further page access.
|
|
|
|
*/
|
|
|
|
page_offline_freeze();
|
2009-09-22 23:45:51 +00:00
|
|
|
|
2018-08-22 04:55:09 +00:00
|
|
|
get_kcore_size(&nphdr, &phdrs_len, ¬es_len, &data_offset);
|
|
|
|
phdrs_offset = sizeof(struct elfhdr);
|
|
|
|
notes_offset = phdrs_offset + phdrs_len;
|
|
|
|
|
|
|
|
/* ELF file header. */
|
|
|
|
if (buflen && *fpos < sizeof(struct elfhdr)) {
|
|
|
|
struct elfhdr ehdr = {
|
|
|
|
.e_ident = {
|
|
|
|
[EI_MAG0] = ELFMAG0,
|
|
|
|
[EI_MAG1] = ELFMAG1,
|
|
|
|
[EI_MAG2] = ELFMAG2,
|
|
|
|
[EI_MAG3] = ELFMAG3,
|
|
|
|
[EI_CLASS] = ELF_CLASS,
|
|
|
|
[EI_DATA] = ELF_DATA,
|
|
|
|
[EI_VERSION] = EV_CURRENT,
|
|
|
|
[EI_OSABI] = ELF_OSABI,
|
|
|
|
},
|
|
|
|
.e_type = ET_CORE,
|
|
|
|
.e_machine = ELF_ARCH,
|
|
|
|
.e_version = EV_CURRENT,
|
|
|
|
.e_phoff = sizeof(struct elfhdr),
|
|
|
|
.e_flags = ELF_CORE_EFLAGS,
|
|
|
|
.e_ehsize = sizeof(struct elfhdr),
|
|
|
|
.e_phentsize = sizeof(struct elf_phdr),
|
|
|
|
.e_phnum = nphdr,
|
|
|
|
};
|
|
|
|
|
|
|
|
tsz = min_t(size_t, buflen, sizeof(struct elfhdr) - *fpos);
|
|
|
|
if (copy_to_user(buffer, (char *)&ehdr + *fpos, tsz)) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2018-08-22 04:55:09 +00:00
|
|
|
buffer += tsz;
|
|
|
|
buflen -= tsz;
|
|
|
|
*fpos += tsz;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2018-08-22 04:55:09 +00:00
|
|
|
/* ELF program headers. */
|
|
|
|
if (buflen && *fpos < phdrs_offset + phdrs_len) {
|
|
|
|
struct elf_phdr *phdrs, *phdr;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2018-08-22 04:55:09 +00:00
|
|
|
phdrs = kzalloc(phdrs_len, GFP_KERNEL);
|
|
|
|
if (!phdrs) {
|
2018-08-22 04:55:06 +00:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2018-08-22 04:55:09 +00:00
|
|
|
|
|
|
|
phdrs[0].p_type = PT_NOTE;
|
|
|
|
phdrs[0].p_offset = notes_offset;
|
|
|
|
phdrs[0].p_filesz = notes_len;
|
|
|
|
|
|
|
|
phdr = &phdrs[1];
|
|
|
|
list_for_each_entry(m, &kclist_head, list) {
|
|
|
|
phdr->p_type = PT_LOAD;
|
|
|
|
phdr->p_flags = PF_R | PF_W | PF_X;
|
|
|
|
phdr->p_offset = kc_vaddr_to_offset(m->addr) + data_offset;
|
fs/proc/kcore: drop KCORE_REMAP and KCORE_OTHER
Patch series "fs/proc/kcore: don't read offline sections, logically offline pages and hwpoisoned pages", v3.
Looking for places where the kernel might unconditionally read
PageOffline() pages, I stumbled over /proc/kcore; turns out /proc/kcore
needs some more love to not touch some other pages we really don't want to
read -- i.e., hwpoisoned ones.
Examples for PageOffline() pages are pages inflated in a balloon, memory
unplugged via virtio-mem, and partially-present sections in memory added
by the Hyper-V balloon.
When reading pages inflated in a balloon, we essentially produce
unnecessary load in the hypervisor; holes in partially present sections in
case of Hyper-V are not accessible and already were a problem for
/proc/vmcore, fixed in makedumpfile by detecting PageOffline() pages. In
the future, virtio-mem might disallow reading unplugged memory -- marked
as PageOffline() -- in some environments, resulting in undefined behavior
when accessed; therefore, I'm trying to identify and rework all these
(corner) cases.
With this series, there is really only access via /dev/mem, /proc/vmcore
and kdb left after I ripped out /dev/kmem. kdb is an advanced corner-case
use case -- we won't care for now if someone explicitly tries to do nasty
things by reading from/writing to physical addresses we better not touch.
/dev/mem is a use case we won't support for virtio-mem, at least for now,
so we'll simply disallow mapping any virtio-mem memory via /dev/mem next.
/proc/vmcore is really only a problem when dumping the old kernel via
something that's not makedumpfile (read: basically never), however, we'll
try sanitizing that as well in the second kernel in the future.
Tested via kcore_dump:
https://github.com/schlafwandler/kcore_dump
This patch (of 6):
Commit db779ef67ffe ("proc/kcore: Remove unused kclist_add_remap()")
removed the last user of KCORE_REMAP.
Commit 595dd46ebfc1 ("vfs/proc/kcore, x86/mm/kcore: Fix SMAP fault when
dumping vsyscall user page") removed the last user of KCORE_OTHER.
Let's drop both types. While at it, also drop vaddr in "struct
kcore_list", used by KCORE_REMAP only.
Link: https://lkml.kernel.org/r/20210526093041.8800-1-david@redhat.com
Link: https://lkml.kernel.org/r/20210526093041.8800-2-david@redhat.com
Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Mike Rapoport <rppt@linux.ibm.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Jason Wang <jasowang@redhat.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Roman Gushchin <guro@fb.com>
Cc: Alex Shi <alex.shi@linux.alibaba.com>
Cc: Steven Price <steven.price@arm.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Aili Yao <yaoaili@kingsoft.com>
Cc: Jiri Bohac <jbohac@suse.cz>
Cc: "K. Y. Srinivasan" <kys@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Cc: Stephen Hemminger <sthemmin@microsoft.com>
Cc: Wei Liu <wei.liu@kernel.org>
Cc: Naoya Horiguchi <naoya.horiguchi@nec.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-07-01 01:50:03 +00:00
|
|
|
phdr->p_vaddr = (size_t)m->addr;
|
|
|
|
if (m->type == KCORE_RAM)
|
2018-08-22 04:55:09 +00:00
|
|
|
phdr->p_paddr = __pa(m->addr);
|
|
|
|
else if (m->type == KCORE_TEXT)
|
|
|
|
phdr->p_paddr = __pa_symbol(m->addr);
|
|
|
|
else
|
|
|
|
phdr->p_paddr = (elf_addr_t)-1;
|
|
|
|
phdr->p_filesz = phdr->p_memsz = m->size;
|
|
|
|
phdr->p_align = PAGE_SIZE;
|
|
|
|
phdr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
tsz = min_t(size_t, buflen, phdrs_offset + phdrs_len - *fpos);
|
|
|
|
if (copy_to_user(buffer, (char *)phdrs + *fpos - phdrs_offset,
|
|
|
|
tsz)) {
|
|
|
|
kfree(phdrs);
|
2018-08-22 04:55:06 +00:00
|
|
|
ret = -EFAULT;
|
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2018-08-22 04:55:09 +00:00
|
|
|
kfree(phdrs);
|
|
|
|
|
|
|
|
buffer += tsz;
|
2005-04-16 22:20:36 +00:00
|
|
|
buflen -= tsz;
|
|
|
|
*fpos += tsz;
|
2018-08-22 04:55:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ELF note segment. */
|
|
|
|
if (buflen && *fpos < notes_offset + notes_len) {
|
|
|
|
struct elf_prstatus prstatus = {};
|
|
|
|
struct elf_prpsinfo prpsinfo = {
|
|
|
|
.pr_sname = 'R',
|
|
|
|
.pr_fname = "vmlinux",
|
|
|
|
};
|
|
|
|
char *notes;
|
|
|
|
size_t i = 0;
|
|
|
|
|
|
|
|
strlcpy(prpsinfo.pr_psargs, saved_command_line,
|
|
|
|
sizeof(prpsinfo.pr_psargs));
|
|
|
|
|
|
|
|
notes = kzalloc(notes_len, GFP_KERNEL);
|
|
|
|
if (!notes) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
append_kcore_note(notes, &i, CORE_STR, NT_PRSTATUS, &prstatus,
|
|
|
|
sizeof(prstatus));
|
|
|
|
append_kcore_note(notes, &i, CORE_STR, NT_PRPSINFO, &prpsinfo,
|
|
|
|
sizeof(prpsinfo));
|
|
|
|
append_kcore_note(notes, &i, CORE_STR, NT_TASKSTRUCT, current,
|
|
|
|
arch_task_struct_size);
|
2018-08-22 04:55:20 +00:00
|
|
|
/*
|
|
|
|
* vmcoreinfo_size is mostly constant after init time, but it
|
|
|
|
* can be changed by crash_save_vmcoreinfo(). Racing here with a
|
|
|
|
* panic on another CPU before the machine goes down is insanely
|
|
|
|
* unlikely, but it's better to not leave potential buffer
|
|
|
|
* overflows lying around, regardless.
|
|
|
|
*/
|
|
|
|
append_kcore_note(notes, &i, VMCOREINFO_NOTE_NAME, 0,
|
|
|
|
vmcoreinfo_data,
|
|
|
|
min(vmcoreinfo_size, notes_len - i));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2018-08-22 04:55:09 +00:00
|
|
|
tsz = min_t(size_t, buflen, notes_offset + notes_len - *fpos);
|
|
|
|
if (copy_to_user(buffer, notes + *fpos - notes_offset, tsz)) {
|
|
|
|
kfree(notes);
|
|
|
|
ret = -EFAULT;
|
2018-08-22 04:55:06 +00:00
|
|
|
goto out;
|
2018-08-22 04:55:09 +00:00
|
|
|
}
|
|
|
|
kfree(notes);
|
|
|
|
|
|
|
|
buffer += tsz;
|
|
|
|
buflen -= tsz;
|
|
|
|
*fpos += tsz;
|
2018-08-22 04:55:06 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check to see if our file offset matches with any of
|
|
|
|
* the addresses in the elf_phdr on our list.
|
|
|
|
*/
|
2018-08-22 04:55:09 +00:00
|
|
|
start = kc_offset_to_vaddr(*fpos - data_offset);
|
2005-04-16 22:20:36 +00:00
|
|
|
if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
|
|
|
|
tsz = buflen;
|
|
|
|
|
2018-08-22 04:55:13 +00:00
|
|
|
m = NULL;
|
2018-08-22 04:55:09 +00:00
|
|
|
while (buflen) {
|
2021-07-01 01:50:10 +00:00
|
|
|
struct page *page;
|
|
|
|
unsigned long pfn;
|
|
|
|
|
2018-08-22 04:55:13 +00:00
|
|
|
/*
|
|
|
|
* If this is the first iteration or the address is not within
|
|
|
|
* the previous entry, search for a matching entry.
|
|
|
|
*/
|
|
|
|
if (!m || start < m->addr || start >= m->addr + m->size) {
|
|
|
|
list_for_each_entry(m, &kclist_head, list) {
|
|
|
|
if (start >= m->addr &&
|
|
|
|
start < m->addr + m->size)
|
|
|
|
break;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2021-07-01 01:50:21 +00:00
|
|
|
if (page_offline_frozen++ % MAX_ORDER_NR_PAGES == 0) {
|
|
|
|
page_offline_thaw();
|
|
|
|
cond_resched();
|
|
|
|
page_offline_freeze();
|
|
|
|
}
|
|
|
|
|
2010-03-23 20:35:42 +00:00
|
|
|
if (&m->list == &kclist_head) {
|
2018-08-22 04:55:06 +00:00
|
|
|
if (clear_user(buffer, tsz)) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
2018-09-20 19:22:35 +00:00
|
|
|
m = NULL; /* skip the list anchor */
|
2021-07-01 01:50:07 +00:00
|
|
|
goto skip;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (m->type) {
|
|
|
|
case KCORE_VMALLOC:
|
2016-09-08 07:57:07 +00:00
|
|
|
vread(buf, (char *)start, tsz);
|
2009-09-22 00:02:35 +00:00
|
|
|
/* we have to zero-fill user buffer even if no read */
|
2018-08-22 04:55:06 +00:00
|
|
|
if (copy_to_user(buffer, buf, tsz)) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
2021-07-01 01:50:07 +00:00
|
|
|
break;
|
|
|
|
case KCORE_USER:
|
2018-02-12 14:44:53 +00:00
|
|
|
/* User page is handled prior to normal kernel page: */
|
2018-08-22 04:55:06 +00:00
|
|
|
if (copy_to_user(buffer, (char *)start, tsz)) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
2021-07-01 01:50:07 +00:00
|
|
|
break;
|
|
|
|
case KCORE_RAM:
|
2021-07-01 01:50:10 +00:00
|
|
|
pfn = __pa(start) >> PAGE_SHIFT;
|
|
|
|
page = pfn_to_online_page(pfn);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't read offline sections, logically offline pages
|
|
|
|
* (e.g., inflated in a balloon), hwpoisoned pages,
|
|
|
|
* and explicitly excluded physical ranges.
|
|
|
|
*/
|
|
|
|
if (!page || PageOffline(page) ||
|
|
|
|
is_page_hwpoison(page) || !pfn_is_ram(pfn)) {
|
2021-07-01 01:50:07 +00:00
|
|
|
if (clear_user(buffer, tsz)) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fallthrough;
|
|
|
|
case KCORE_VMEMMAP:
|
|
|
|
case KCORE_TEXT:
|
2005-04-16 22:20:36 +00:00
|
|
|
if (kern_addr_valid(start)) {
|
2016-09-08 07:57:08 +00:00
|
|
|
/*
|
|
|
|
* Using bounce buffer to bypass the
|
|
|
|
* hardened user copy kernel text checks.
|
|
|
|
*/
|
2020-06-17 07:37:53 +00:00
|
|
|
if (copy_from_kernel_nofault(buf, (void *)start,
|
|
|
|
tsz)) {
|
2018-08-22 04:55:06 +00:00
|
|
|
if (clear_user(buffer, tsz)) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
2018-02-06 23:37:13 +00:00
|
|
|
} else {
|
2018-08-22 04:55:06 +00:00
|
|
|
if (copy_to_user(buffer, buf, tsz)) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-08-22 04:55:06 +00:00
|
|
|
if (clear_user(buffer, tsz)) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2021-07-01 01:50:07 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pr_warn_once("Unhandled KCORE type: %d\n", m->type);
|
|
|
|
if (clear_user(buffer, tsz)) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2021-07-01 01:50:07 +00:00
|
|
|
skip:
|
2005-04-16 22:20:36 +00:00
|
|
|
buflen -= tsz;
|
|
|
|
*fpos += tsz;
|
|
|
|
buffer += tsz;
|
|
|
|
start += tsz;
|
|
|
|
tsz = (buflen > PAGE_SIZE ? PAGE_SIZE : buflen);
|
|
|
|
}
|
|
|
|
|
2018-08-22 04:55:06 +00:00
|
|
|
out:
|
2021-07-01 01:50:21 +00:00
|
|
|
page_offline_thaw();
|
2018-08-22 04:55:06 +00:00
|
|
|
up_read(&kclist_lock);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return orig_buflen - buflen;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2008-10-06 10:14:19 +00:00
|
|
|
|
2009-09-22 23:45:48 +00:00
|
|
|
static int open_kcore(struct inode *inode, struct file *filp)
|
|
|
|
{
|
2019-08-20 00:17:57 +00:00
|
|
|
int ret = security_locked_down(LOCKDOWN_KCORE);
|
|
|
|
|
2009-09-22 23:45:48 +00:00
|
|
|
if (!capable(CAP_SYS_RAWIO))
|
|
|
|
return -EPERM;
|
2016-09-08 07:57:07 +00:00
|
|
|
|
2019-08-20 00:18:05 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2016-09-08 07:57:07 +00:00
|
|
|
filp->private_data = kmalloc(PAGE_SIZE, GFP_KERNEL);
|
|
|
|
if (!filp->private_data)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2009-09-22 23:45:48 +00:00
|
|
|
if (kcore_need_update)
|
|
|
|
kcore_update_ram();
|
2009-09-22 23:45:52 +00:00
|
|
|
if (i_size_read(inode) != proc_root_kcore->size) {
|
2016-01-22 20:40:57 +00:00
|
|
|
inode_lock(inode);
|
2009-09-22 23:45:52 +00:00
|
|
|
i_size_write(inode, proc_root_kcore->size);
|
2016-01-22 20:40:57 +00:00
|
|
|
inode_unlock(inode);
|
2009-09-22 23:45:52 +00:00
|
|
|
}
|
2009-09-22 23:45:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-09-08 07:57:07 +00:00
|
|
|
static int release_kcore(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
kfree(file->private_data);
|
|
|
|
return 0;
|
|
|
|
}
|
2009-09-22 23:45:48 +00:00
|
|
|
|
2020-02-04 01:37:17 +00:00
|
|
|
static const struct proc_ops kcore_proc_ops = {
|
|
|
|
.proc_read = read_kcore,
|
|
|
|
.proc_open = open_kcore,
|
|
|
|
.proc_release = release_kcore,
|
|
|
|
.proc_lseek = default_llseek,
|
2009-09-22 23:45:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* just remember that we have to update kcore */
|
|
|
|
static int __meminit kcore_callback(struct notifier_block *self,
|
|
|
|
unsigned long action, void *arg)
|
|
|
|
{
|
|
|
|
switch (action) {
|
|
|
|
case MEM_ONLINE:
|
|
|
|
case MEM_OFFLINE:
|
|
|
|
kcore_need_update = 1;
|
2018-08-22 04:54:55 +00:00
|
|
|
break;
|
2009-09-22 23:45:48 +00:00
|
|
|
}
|
|
|
|
return NOTIFY_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-29 22:08:08 +00:00
|
|
|
static struct notifier_block kcore_callback_nb __meminitdata = {
|
|
|
|
.notifier_call = kcore_callback,
|
|
|
|
.priority = 0,
|
|
|
|
};
|
2009-09-22 23:45:48 +00:00
|
|
|
|
2009-09-22 23:45:44 +00:00
|
|
|
static struct kcore_list kcore_vmalloc;
|
|
|
|
|
2009-09-22 23:45:45 +00:00
|
|
|
#ifdef CONFIG_ARCH_PROC_KCORE_TEXT
|
|
|
|
static struct kcore_list kcore_text;
|
|
|
|
/*
|
|
|
|
* If defined, special segment is used for mapping kernel text instead of
|
|
|
|
* direct-map area. We need to create special TEXT section.
|
|
|
|
*/
|
|
|
|
static void __init proc_kcore_text_init(void)
|
|
|
|
{
|
kcore: add _text to KCORE_TEXT
Extend KCORE_TEXT to cover the pages between _text and _stext, to allow
examining some important page table pages.
`readelf -a` output on x86_64 before and after patch:
Type Offset VirtAddr PhysAddr
before LOAD 0x00007fff8100c000 0xffffffff81009000 0x0000000000000000
after LOAD 0x00007fff81003000 0xffffffff81000000 0x0000000000000000
The newly covered pages are:
0xffffffff81000000 <startup_64> etc.
0xffffffff81001000 <init_level4_pgt>
0xffffffff81002000 <level3_ident_pgt>
0xffffffff81003000 <level3_kernel_pgt>
0xffffffff81004000 <level2_fixmap_pgt>
0xffffffff81005000 <level1_fixmap_pgt>
0xffffffff81006000 <level2_ident_pgt>
0xffffffff81007000 <level2_kernel_pgt>
0xffffffff81008000 <level2_spare_pgt>
Before patch, /proc/kcore shows outdated contents for the above page
table pages, for example:
(gdb) p level3_ident_pgt
$1 = {<text variable, no debug info>} 0xffffffff81002000 <level3_ident_pgt>
(gdb) p/x *((pud_t *)&level3_ident_pgt)@512
$2 = {{pud = 0x1006063}, {pud = 0x0} <repeats 511 times>}
while the real content is:
root@hp /home/wfg# hexdump -s 0x1002000 -n 4096 /dev/mem
1002000 6063 0100 0000 0000 8067 0000 0000 0000
1002010 0000 0000 0000 0000 0000 0000 0000 0000
*
1003000
That is, on a x86_64 box with 2GB memory, we can see first-1GB / full-2GB
identity mapping before/after patch:
(gdb) p/x *((pud_t *)&level3_ident_pgt)@512
before $1 = {{pud = 0x1006063}, {pud = 0x0} <repeats 511 times>}
after $1 = {{pud = 0x1006063}, {pud = 0x8067}, {pud = 0x0} <repeats 510 times>}
Obviously the content before patch is wrong.
Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2010-05-26 21:43:27 +00:00
|
|
|
kclist_add(&kcore_text, _text, _end - _text, KCORE_TEXT);
|
2009-09-22 23:45:45 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
static void __init proc_kcore_text_init(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-22 23:45:49 +00:00
|
|
|
#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
|
|
|
|
/*
|
|
|
|
* MODULES_VADDR has no intersection with VMALLOC_ADDR.
|
|
|
|
*/
|
2019-03-29 03:44:09 +00:00
|
|
|
static struct kcore_list kcore_modules;
|
2009-09-22 23:45:49 +00:00
|
|
|
static void __init add_modules_range(void)
|
|
|
|
{
|
2014-10-09 22:25:56 +00:00
|
|
|
if (MODULES_VADDR != VMALLOC_START && MODULES_END != VMALLOC_END) {
|
|
|
|
kclist_add(&kcore_modules, (void *)MODULES_VADDR,
|
2009-09-22 23:45:49 +00:00
|
|
|
MODULES_END - MODULES_VADDR, KCORE_VMALLOC);
|
2014-10-09 22:25:56 +00:00
|
|
|
}
|
2009-09-22 23:45:49 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
static void __init add_modules_range(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-10-06 10:14:19 +00:00
|
|
|
static int __init proc_kcore_init(void)
|
|
|
|
{
|
2020-02-04 01:37:17 +00:00
|
|
|
proc_root_kcore = proc_create("kcore", S_IRUSR, NULL, &kcore_proc_ops);
|
2009-09-22 23:45:50 +00:00
|
|
|
if (!proc_root_kcore) {
|
2013-02-28 01:03:16 +00:00
|
|
|
pr_err("couldn't create /proc/kcore\n");
|
2009-09-22 23:45:50 +00:00
|
|
|
return 0; /* Always returns 0. */
|
|
|
|
}
|
2009-09-22 23:45:48 +00:00
|
|
|
/* Store text area if it's special */
|
2009-09-22 23:45:45 +00:00
|
|
|
proc_kcore_text_init();
|
2009-09-22 23:45:48 +00:00
|
|
|
/* Store vmalloc area */
|
2009-09-22 23:45:44 +00:00
|
|
|
kclist_add(&kcore_vmalloc, (void *)VMALLOC_START,
|
|
|
|
VMALLOC_END - VMALLOC_START, KCORE_VMALLOC);
|
2009-09-22 23:45:49 +00:00
|
|
|
add_modules_range();
|
2009-09-22 23:45:48 +00:00
|
|
|
/* Store direct-map area from physical memory map */
|
|
|
|
kcore_update_ram();
|
2013-04-29 22:08:08 +00:00
|
|
|
register_hotmemory_notifier(&kcore_callback_nb);
|
2009-09-22 23:45:48 +00:00
|
|
|
|
2008-10-06 10:14:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-01-23 23:55:45 +00:00
|
|
|
fs_initcall(proc_kcore_init);
|