mirror of
https://github.com/torvalds/linux.git
synced 2026-05-13 00:28:54 +02:00
The pstore ftrace frontend works by purely collecting the instruction address, saving it on the persistent area through the backend and when the log is read, on next boot for example, the address is then resolved by using the regular printk symbol lookup (%pS for example). Problem: if we are running a relocatable kernel with KASLR enabled, this is a recipe for failure in the symbol resolution on next boots, since the addresses are offset'ed by the KASLR address. So, naturally the way to go is factor the KASLR address out of instruction address collection, and adding the fresh offset when resolving the symbol on future boots. Problem #2: modules also have varying addresses that float based on module base address and potentially the module ordering in memory, meaning factoring KASLR offset for them is useless. So, let's hereby only take KASLR offset into account for core kernel addresses, leaving module ones as is. And we have yet a 3rd complexity: not necessarily the check range for core kernel addresses holds true on future boots, since the module base address will vary. With that, the choice was to mark the addresses as being core vs module based on its MSB. And with that... ...we have the 4th challenge here: for some "simple" architectures, the CPU number is saved bit-encoded on the instruction pointer, to allow bigger timestamps - this is set through the PSTORE_CPU_IN_IP define for such architectures. Hence, the approach here is to skip such architectures (at least in a first moment). Finished? No. On top of all previous complexities, we have one extra pain point: kaslr_offset() is inlined and fully "resolved" at boot-time, after kernel decompression, through ELF relocation mechanism. Once the offset is known, it's patched to the kernel text area, wherever it is used. The mechanism, and its users, are only built-in - incompatible with module usage. Though there are possibly some hacks (as computing the offset using some kallsym lookup), the choice here is to restrict this optimization to the (hopefully common) case of CONFIG_PSTORE=y. TL;DR: let's factor KASLR offsets on pstore/ftrace for core kernel addresses, only when PSTORE is built-in and leaving module addresses out, as well as architectures that define PSTORE_CPU_IN_IP. Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com> Link: https://patch.msgid.link/20260410205848.2607169-1-gpiccoli@igalia.com Signed-off-by: Kees Cook <kees@kernel.org>
55 lines
1.6 KiB
C
55 lines
1.6 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef __PSTORE_INTERNAL_H__
|
|
#define __PSTORE_INTERNAL_H__
|
|
|
|
#include <linux/types.h>
|
|
#include <linux/time.h>
|
|
#include <linux/pstore.h>
|
|
|
|
extern unsigned int kmsg_bytes;
|
|
|
|
#ifdef CONFIG_PSTORE_FTRACE
|
|
extern unsigned long decode_ip(unsigned long ip);
|
|
extern void pstore_register_ftrace(void);
|
|
extern void pstore_unregister_ftrace(void);
|
|
ssize_t pstore_ftrace_combine_log(char **dest_log, size_t *dest_log_size,
|
|
const char *src_log, size_t src_log_size);
|
|
#else
|
|
static inline void pstore_register_ftrace(void) {}
|
|
static inline void pstore_unregister_ftrace(void) {}
|
|
static inline unsigned long decode_ip(unsigned long ip) { return ip; }
|
|
static inline ssize_t
|
|
pstore_ftrace_combine_log(char **dest_log, size_t *dest_log_size,
|
|
const char *src_log, size_t src_log_size)
|
|
{
|
|
*dest_log_size = 0;
|
|
return 0;
|
|
}
|
|
#endif
|
|
|
|
#ifdef CONFIG_PSTORE_PMSG
|
|
extern void pstore_register_pmsg(void);
|
|
extern void pstore_unregister_pmsg(void);
|
|
#else
|
|
static inline void pstore_register_pmsg(void) {}
|
|
static inline void pstore_unregister_pmsg(void) {}
|
|
#endif
|
|
|
|
extern struct pstore_info *psinfo;
|
|
|
|
extern void pstore_set_kmsg_bytes(unsigned int bytes);
|
|
extern void pstore_get_records(int);
|
|
extern void pstore_get_backend_records(struct pstore_info *psi,
|
|
struct dentry *root, int quiet);
|
|
extern int pstore_put_backend_records(struct pstore_info *psi);
|
|
extern int pstore_mkfile(struct dentry *root,
|
|
struct pstore_record *record);
|
|
extern void pstore_record_init(struct pstore_record *record,
|
|
struct pstore_info *psi);
|
|
|
|
/* Called during pstore init/exit. */
|
|
int __init pstore_init_fs(void);
|
|
void __exit pstore_exit_fs(void);
|
|
|
|
#endif
|