mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-23 17:30:02 +00:00
![Xunlei Pang](/assets/img/avatar_default.png)
Currently vmcoreinfo data is updated at boot time subsys_initcall(), it has the risk of being modified by some wrong code during system is running. As a result, vmcore dumped may contain the wrong vmcoreinfo. Later on, when using "crash", "makedumpfile", etc utility to parse this vmcore, we probably will get "Segmentation fault" or other unexpected errors. E.g. 1) wrong code overwrites vmcoreinfo_data; 2) further crashes the system; 3) trigger kdump, then we obviously will fail to recognize the crash context correctly due to the corrupted vmcoreinfo. Now except for vmcoreinfo, all the crash data is well protected(including the cpu note which is fully updated in the crash path, thus its correctness is guaranteed). Given that vmcoreinfo data is a large chunk prepared for kdump, we better protect it as well. To solve this, we relocate and copy vmcoreinfo_data to the crash memory when kdump is loading via kexec syscalls. Because the whole crash memory will be protected by existing arch_kexec_protect_crashkres() mechanism, we naturally protect vmcoreinfo_data from write(even read) access under kernel direct mapping after kdump is loaded. Since kdump is usually loaded at the very early stage after boot, we can trust the correctness of the vmcoreinfo data copied. On the other hand, we still need to operate the vmcoreinfo safe copy when crash happens to generate vmcoreinfo_note again, we rely on vmap() to map out a new kernel virtual address and update to use this new one instead in the following crash_save_vmcoreinfo(). BTW, we do not touch vmcoreinfo_note, because it will be fully updated using the protected vmcoreinfo_data after crash which is surely correct just like the cpu crash note. Link: http://lkml.kernel.org/r/1493281021-20737-3-git-send-email-xlpang@redhat.com Signed-off-by: Xunlei Pang <xlpang@redhat.com> Tested-by: Michael Holzheu <holzheu@linux.vnet.ibm.com> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Dave Young <dyoung@redhat.com> Cc: Eric Biederman <ebiederm@xmission.com> Cc: Hari Bathini <hbathini@linux.vnet.ibm.com> Cc: Juergen Gross <jgross@suse.com> Cc: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
73 lines
2.8 KiB
C
73 lines
2.8 KiB
C
#ifndef LINUX_CRASH_CORE_H
|
|
#define LINUX_CRASH_CORE_H
|
|
|
|
#include <linux/linkage.h>
|
|
#include <linux/elfcore.h>
|
|
#include <linux/elf.h>
|
|
|
|
#define CRASH_CORE_NOTE_NAME "CORE"
|
|
#define CRASH_CORE_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4)
|
|
#define CRASH_CORE_NOTE_NAME_BYTES ALIGN(sizeof(CRASH_CORE_NOTE_NAME), 4)
|
|
#define CRASH_CORE_NOTE_DESC_BYTES ALIGN(sizeof(struct elf_prstatus), 4)
|
|
|
|
/*
|
|
* The per-cpu notes area is a list of notes terminated by a "NULL"
|
|
* note header. For kdump, the code in vmcore.c runs in the context
|
|
* of the second kernel to combine them into one note.
|
|
*/
|
|
#define CRASH_CORE_NOTE_BYTES ((CRASH_CORE_NOTE_HEAD_BYTES * 2) + \
|
|
CRASH_CORE_NOTE_NAME_BYTES + \
|
|
CRASH_CORE_NOTE_DESC_BYTES)
|
|
|
|
#define VMCOREINFO_BYTES PAGE_SIZE
|
|
#define VMCOREINFO_NOTE_NAME "VMCOREINFO"
|
|
#define VMCOREINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCOREINFO_NOTE_NAME), 4)
|
|
#define VMCOREINFO_NOTE_SIZE ((CRASH_CORE_NOTE_HEAD_BYTES * 2) + \
|
|
VMCOREINFO_NOTE_NAME_BYTES + \
|
|
VMCOREINFO_BYTES)
|
|
|
|
typedef u32 note_buf_t[CRASH_CORE_NOTE_BYTES/4];
|
|
|
|
void crash_update_vmcoreinfo_safecopy(void *ptr);
|
|
void crash_save_vmcoreinfo(void);
|
|
void arch_crash_save_vmcoreinfo(void);
|
|
__printf(1, 2)
|
|
void vmcoreinfo_append_str(const char *fmt, ...);
|
|
phys_addr_t paddr_vmcoreinfo_note(void);
|
|
|
|
#define VMCOREINFO_OSRELEASE(value) \
|
|
vmcoreinfo_append_str("OSRELEASE=%s\n", value)
|
|
#define VMCOREINFO_PAGESIZE(value) \
|
|
vmcoreinfo_append_str("PAGESIZE=%ld\n", value)
|
|
#define VMCOREINFO_SYMBOL(name) \
|
|
vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name)
|
|
#define VMCOREINFO_SIZE(name) \
|
|
vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
|
|
(unsigned long)sizeof(name))
|
|
#define VMCOREINFO_STRUCT_SIZE(name) \
|
|
vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
|
|
(unsigned long)sizeof(struct name))
|
|
#define VMCOREINFO_OFFSET(name, field) \
|
|
vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \
|
|
(unsigned long)offsetof(struct name, field))
|
|
#define VMCOREINFO_LENGTH(name, value) \
|
|
vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value)
|
|
#define VMCOREINFO_NUMBER(name) \
|
|
vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name)
|
|
#define VMCOREINFO_CONFIG(name) \
|
|
vmcoreinfo_append_str("CONFIG_%s=y\n", #name)
|
|
|
|
extern u32 *vmcoreinfo_note;
|
|
|
|
Elf_Word *append_elf_note(Elf_Word *buf, char *name, unsigned int type,
|
|
void *data, size_t data_len);
|
|
void final_note(Elf_Word *buf);
|
|
|
|
int __init parse_crashkernel(char *cmdline, unsigned long long system_ram,
|
|
unsigned long long *crash_size, unsigned long long *crash_base);
|
|
int parse_crashkernel_high(char *cmdline, unsigned long long system_ram,
|
|
unsigned long long *crash_size, unsigned long long *crash_base);
|
|
int parse_crashkernel_low(char *cmdline, unsigned long long system_ram,
|
|
unsigned long long *crash_size, unsigned long long *crash_base);
|
|
|
|
#endif /* LINUX_CRASH_CORE_H */
|