mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-09-10 18:11:43 -04:00
An x86 alternative with an empty replacement, e.g. the second entry of
ALTERNATIVE_2("orig", "repl", ft1, "", ft2)
has a replacementlen of zero. Its replacement offset still gets a
relocation, but the label it points at is the end of the previous
replacement, which is also the beginning of the *next* alternative's
replacement. The value is meaningless; get_alt_entry() already ignores
it for that reason.
klp diff doesn't ignore it. When such an alternative belongs to a
changed function, cloning its relocations drags in the unrelated
neighboring replacement, along with everything that replacement
references. On an x86 clang/lto build an empty alternative in
meminfo_proc_show() pulled in the replacement of an alternative in
proc_kcore_init(), silently emitting a klp relocation against init text
which has long since been freed by the time the patch is applied.
Add arch_alt_ignore_new_reloc() and skip such relocations when cloning.
This has to be arch specific: on arm64 a zero-length replacement instead
identifies an alternative callback, whose replacement offset points at
the callback function and must be preserved.
Fixes: dd590d4d57 ("objtool/klp: Introduce klp diff subcommand for diffing object files")
Acked-by: Song Liu <song@kernel.org>
Acked-by: Joe Lawrence <joe.lawrence@redhat.com>
Link: https://patch.msgid.link/7a885b70974795c3417f3358869e62aafd4ef783.1786138493.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
51 lines
1.3 KiB
C
51 lines
1.3 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* Copyright (C) 2015 Josh Poimboeuf <jpoimboe@redhat.com>
|
|
*/
|
|
|
|
#ifndef _SPECIAL_H
|
|
#define _SPECIAL_H
|
|
|
|
#include <stdbool.h>
|
|
#include <objtool/check.h>
|
|
#include <objtool/elf.h>
|
|
|
|
#define C_JUMP_TABLE_SECTION ".data.rel.ro.c_jump_table"
|
|
|
|
struct special_alt {
|
|
struct list_head list;
|
|
|
|
bool group;
|
|
bool jump_or_nop;
|
|
u8 key_addend;
|
|
|
|
struct section *orig_sec;
|
|
unsigned long orig_off;
|
|
|
|
struct section *new_sec;
|
|
unsigned long new_off;
|
|
|
|
unsigned int orig_len, new_len, feature; /* group only */
|
|
};
|
|
|
|
int special_get_alts(struct elf *elf, struct list_head *alts);
|
|
|
|
void arch_handle_alternative(struct special_alt *alt);
|
|
|
|
/*
|
|
* Should the reloc at @offset -- the "new" (replacement) field of a special
|
|
* section group entry -- be ignored? The meaning of a zero-length replacement
|
|
* is arch specific, so the arch decides.
|
|
*/
|
|
bool arch_alt_ignore_new_reloc(struct section *sec, unsigned long offset);
|
|
|
|
bool arch_support_alt_relocation(struct special_alt *special_alt,
|
|
struct instruction *insn,
|
|
struct reloc *reloc);
|
|
struct reloc *arch_find_switch_table(struct objtool_file *file,
|
|
struct instruction *insn,
|
|
unsigned long *table_size);
|
|
const char *arch_cpu_feature_name(int feature_number);
|
|
|
|
#endif /* _SPECIAL_H */
|