objtool,livepatch: klp-build livepatch module generation
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v4 Latest63 patches 28 repliesIn review
- v364 patches 18 repliesSuperseded
- v262 patches 71 repliesSuperseded
Earlier versions · 1
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v1 RFC | 31 patches | 62 replies | Superseded |
Patches in v4 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/63 | s390/vmlinux.lds.S: Prevent thunk functions from getting placed with normal textarch/ arch/ | +2 | 0 replies | |
| 2/63 | vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macrosinclude/ scripts/ | +17 | 3 replies | |
| 3/63 | x86/module: Improve relocation error messagesarch/ kernel/ | +11 | 0 replies | |
| 4/63 | x86/kprobes: Remove STACK_FRAME_NON_STANDARD annotationarch/ | +0 | 0 replies | |
| 5/63 | compiler: Tweak __UNIQUE_ID() naminginclude/ | +5 | 0 replies | |
| 6/63 | compiler.h: Make addressable symbols less of an eyesoreinclude/ | +1 | 0 replies | |
| 7/63 | elfnote: Change ELFNOTE() to use __UNIQUE_ID()include/ | +5 | 0 replies | |
| 8/63 | kbuild: Remove 'kmod_' prefix from __KBUILD_MODNAMEinclude/ scripts/ | +3 | 6 replies | |
| 9/63 | modpost: Ignore unresolved section bounds symbolsscripts/ | +5 | 0 replies | |
| 10/63 | x86/alternative: Refactor INT3 call emulation selftestarch/ | +28 | 0 replies | |
| 11/63 | interval_tree: Sync interval_tree_generic.h with toolstools/ tools/ | +3 | 0 replies | |
| 12/63 | interval_tree: Fix ITSTATIC usage for *_subtree_search()include/ include/ include/ +1 more | +8 | 0 replies | |
| 12/63 | interval_tree: Fix ITSTATIC usage for *_subtree_search()drivers/ include/ include/ +3 more | +13 | 0 replies | |
| 13/63 | objtool: Make find_symbol_containing() less arbitrarytools/ | +20 | 0 replies | |
| 14/63 | objtool: Fix broken error handling in read_symbols()tools/ | +3 | 0 replies | |
| 15/63 | objtool: Propagate elf_truncate_section() error in elf_write()tools/ | +2 | 0 replies | |
| 16/63 | objtool: Remove error handling boilerplatetools/ tools/ | +59 | 0 replies | |
| 17/63 | objtool: Add empty symbols to the symbol tree againtools/ | +2 | 0 replies | |
| 18/63 | objtool: Fix interval tree insertion for zero-length symbolstools/ | +1 | 0 replies | |
| 19/63 | objtool: Fix weak symbol detectiontools/ | +4 | 0 replies | |
| 20/63 | objtool: Fix x86 addend calculationtools/ tools/ tools/ +2 more | +17 | 0 replies | |
| 21/63 | objtool: Fix __pa_symbol() relocation handlingtools/ | +12 | 0 replies | |
| 22/63 | objtool: Fix "unexpected end of section" warning for alternativestools/ | +1 | 0 replies | |
| 23/63 | objtool: Check for missing annotation entries in read_annotate()tools/ | +5 | 0 replies | |
| 24/63 | objtool: Const string cleanuptools/ tools/ tools/ +3 more | +10 | 0 replies | |
| 25/63 | objtool: Clean up compiler flag usagetools/ tools/ tools/ | +13 | 0 replies | |
| 26/63 | objtool: Remove .parainstructions referencetools/ | +0 | 0 replies | |
| 27/63 | objtool: Convert elf iterator macros to use 'struct elf'tools/ tools/ tools/ | +17 | 0 replies | |
| 28/63 | objtool: Add section/symbol type helperstools/ tools/ tools/ +2 more | +108 | 0 replies | |
| 29/63 | objtool: Mark .cold subfunctionstools/ tools/ tools/ | +17 | 0 replies | |
| 30/63 | objtool: Fix weak symbol hole detection for .cold functionstools/ tools/ | +45 | 0 replies | |
| 31/63 | objtool: Mark prefix functionstools/ tools/ tools/ | +14 | 0 replies | |
| 32/63 | objtool: Simplify reloc offset calculation in unwind_read_hints()tools/ | +1 | 0 replies | |
| 33/63 | objtool: Avoid emptying lists for duplicate sectionstools/ | +0 | 0 replies | |
| 34/63 | objtool: Rename --Werror to --werrorscripts/ scripts/ tools/ | +3 | 0 replies | |
| 35/63 | objtool: Resurrect --backup optiontools/ tools/ tools/ | +16 | 0 replies | |
| 36/63 | objtool: Reindent check_options[]tools/ | +27 | 0 replies | |
| 37/63 | objtool: Refactor add_jump_destinations()tools/ tools/ | +106 | 0 replies | |
| 38/63 | objtool: Simplify special symbol handling in elf_update_symbol()tools/ | +2 | 0 replies | |
| 39/63 | objtool: Generalize elf_create_symbol()tools/ tools/ | +69 | 0 replies | |
| 40/63 | objtool: Generalize elf_create_section()tools/ tools/ tools/ | +77 | 0 replies | |
| 41/63 | objtool: Add elf_create_data()tools/ tools/ | +54 | 0 replies | |
| 42/63 | objtool: Add elf_create_reloc() and elf_init_reloc()tools/ tools/ | +165 | 0 replies | |
| 43/63 | objtool: Add elf_create_file()tools/ tools/ tools/ | +147 | 0 replies | |
| 44/63 | objtool: Add annotype() helpertools/ tools/ tools/ +7 more | +18 | 0 replies | |
| 45/63 | objtool: Move ANNOTATE* macros to annotate.hinclude/ include/ | +110 | 0 replies | |
| 46/63 | objtool: Add ANNOTATE_DATA_SPECIALinclude/ include/ tools/ | +41 | 0 replies | |
| 47/63 | x86/asm: Annotate special section entriesarch/ arch/ arch/ +3 more | +15 | 0 replies | |
| 48/63 | objtool: Unify STACK_FRAME_NON_STANDARD entry sizesinclude/ | +1 | 0 replies | |
| 49/63 | objtool/klp: Add --checksum option to generate per-function checksumstools/ tools/ tools/ +6 more | +289 | 11 replies | |
| 50/63 | objtool/klp: Add --debug-checksum=<funcs> to show per-instruction checksumstools/ tools/ tools/ +3 more | +70 | 0 replies | |
| 51/63 | objtool/klp: Introduce klp diff subcommand for diffing object filesMAINTAINERS include/ include/ +20 more | +2088 | 4 replies | |
| 52/63 | objtool/klp: Add --debug option to show cloning decisionstools/ tools/ tools/ | +99 | 0 replies | |
| 53/63 | objtool/klp: Add post-link subcommand to finalize livepatch modulestools/ tools/ tools/ +1 more | +174 | 0 replies | |
| 54/63 | objtool: Refactor prefix symbol creation codetools/ tools/ tools/ | +46 | 0 replies | |
| 55/63 | objtool: Add base objtool support for livepatch modulestools/ tools/ tools/ +1 more | +53 | 0 replies | |
| 56/63 | livepatch: Add CONFIG_KLP_BUILDarch/ kernel/ | +13 | 0 replies | |
| 57/63 | kbuild,objtool: Defer objtool validation step for CONFIG_KLP_BUILDscripts/ scripts/ | +3 | 0 replies | |
| 58/63 | livepatch/klp-build: Introduce fix-patch-lines script to avoid __LINE__ diff noiseMAINTAINERS scripts/ | +80 | 0 replies | |
| 59/63 | livepatch/klp-build: Add stub init code for livepatch modulesscripts/ | +108 | 0 replies | |
| 60/63 | livepatch/klp-build: Introduce klp-build script for generating livepatch modulesscripts/ scripts/ scripts/ +1 more | +749 | 0 replies | |
| 61/63 | livepatch/klp-build: Add --debug option to show cloning decisionsscripts/ | +13 | 0 replies | |
| 62/63 | livepatch/klp-build: Add --show-first-changed option to show function divergencescripts/ | +78 | 0 replies | |
| 63/63 | livepatch: Introduce source code helpers for livepatch modulesinclude/ | +77 | 0 replies |
Reviews trailers per patch
1 of 64 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.
| Patch | Heiko Carstens | Joe Lawrence | Petr Mladek | Anders Roxell |
|---|---|---|---|---|
| Series | Tested-off-by | A-b | ||
| 1/63 | A-b | |||
| 2/63 | ||||
| 3/63 | ||||
| 4/63 | ||||
| 5/63 | ||||
| 6/63 | ||||
| 7/63 | ||||
| 8/63 | T-b | |||
| 9/63 | ||||
| 10/63 | ||||
| 11/63 | ||||
| 12/63 | ||||
| 12/63 | ||||
| 13/63 | ||||
| 14/63 | ||||
| 15/63 | ||||
| 16/63 | ||||
| 17/63 | ||||
| 18/63 | ||||
| 19/63 | ||||
| 20/63 | ||||
| 21/63 | ||||
| 22/63 | ||||
| 23/63 | ||||
| 24/63 | ||||
| 25/63 | ||||
| 26/63 | ||||
| 27/63 | ||||
| 28/63 | ||||
| 29/63 | ||||
| 30/63 | ||||
| 31/63 | ||||
| 32/63 | ||||
| 33/63 | ||||
| 34/63 | ||||
| 35/63 | ||||
| 36/63 | ||||
| 37/63 | ||||
| 38/63 | ||||
| 39/63 | ||||
| 40/63 | ||||
| 41/63 | ||||
| 42/63 | ||||
| 43/63 | ||||
| 44/63 | ||||
| 45/63 | ||||
| 46/63 | ||||
| 47/63 | ||||
| 48/63 | ||||
| 49/63 | ||||
| 50/63 | ||||
| 51/63 | ||||
| 52/63 | ||||
| 53/63 | ||||
| 54/63 | ||||
| 55/63 | ||||
| 56/63 | ||||
| 57/63 | ||||
| 58/63 | ||||
| 59/63 | ||||
| 60/63 | ||||
| 61/63 | ||||
| 62/63 | ||||
| 63/63 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.
Cover letter [PATCH v4 00/63] objtool,livepatch: klp-build livepatch module generation
Changes since v3 (https://lore.kernel.org/[email protected]):
- Get rid of the SHF_MERGE+SHF_WRITE toolchain shenanigans in favor of simple .discard.annotate_data annotations
- Fix potential double free in elf_create_reloc()
- Sync interval_tree_generic.h (Peter)
- Refactor prefix symbol creation error handling
- Rebase on tip/master and fix new issue (--checksum getting added with --noabs)
(v3..v4 diff below)
----
This series introduces new objtool features and a klp-build script to generate livepatch modules using a source .patch as input.
This builds on concepts from the longstanding out-of-tree kpatch [1] project which began in 2012 and has been used for many years to generate livepatch modules for production kernels. However, this is a complete rewrite which incorporates hard-earned lessons from 12+ years of maintaining kpatch.
Key improvements compared to kpatch-build:
- Integrated with objtool: Leverages objtool's existing control-flow graph analysis to help detect changed functions.
- Works on vmlinux.o: Supports late-linked objects, making it compatible with LTO, IBT, and similar.
- Simplified code base: ~3k fewer lines of code.
- Upstream: No more out-of-tree #ifdef hacks, far less cruft.
- Cleaner internals: Vastly simplified logic for symbol/section/reloc inclusion and special section extraction.
- Robust __LINE__ macro handling: Avoids false positive binary diffs caused by the __LINE__ macro by introducing a fix-patch-lines script which injects #line directives into the source .patch to preserve the original line numbers at compile time.
The primary user interface is the klp-build script which does the following:
- Builds an original kernel with -function-sections and -fdata-sections, plus objtool function checksumming.
- Applies the .patch file and rebuilds the kernel using the same options.
- Runs 'objtool klp diff' to detect changed functions and generate intermediate binary diff objects.
- Builds a kernel module which links the diff objects with some livepatch module init code (scripts/livepatch/init.c).
- Finalizes the livepatch module (aka work around linker wreckage) using 'objtool klp post-link'.
I've tested with a variety of patches on defconfig and Fedora-config kernels with both GCC and Clang.
These patches can also be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/jpoimboe/linux.git klp-build-v3
Please test!
[1] https://github.com/dynup/kpatch
Josh Poimboeuf (63):
s390/vmlinux.lds.S: Prevent thunk functions from getting placed with
normal text
vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros x86/module: Improve relocation error messages
x86/kprobes: Remove STACK_FRAME_NON_STANDARD annotation
compiler: Tweak __UNIQUE_ID() naming
compiler.h: Make addressable symbols less of an eyesore
elfnote: Change ELFNOTE() to use __UNIQUE_ID()
kbuild: Remove 'kmod_' prefix from __KBUILD_MODNAME
modpost: Ignore unresolved section bounds symbols x86/alternative: Refactor INT3 call emulation selftest
interval_tree: Sync interval_tree_generic.h with tools
interval_tree: Fix ITSTATIC usage for *_subtree_search()
objtool: Make find_symbol_containing() less arbitrary
objtool: Fix broken error handling in read_symbols()
objtool: Propagate elf_truncate_section() error in elf_write()
objtool: Remove error handling boilerplate
objtool: Add empty symbols to the symbol tree again
objtool: Fix interval tree insertion for zero-length symbols
objtool: Fix weak symbol detection
objtool: Fix x86 addend calculation
objtool: Fix __pa_symbol() relocation handling
objtool: Fix "unexpected end of section" warning for alternatives
objtool: Check for missing annotation entries in read_annotate()
objtool: Const string cleanup
objtool: Clean up compiler flag usage
objtool: Remove .parainstructions reference
objtool: Convert elf iterator macros to use 'struct elf'
objtool: Add section/symbol type helpers
objtool: Mark .cold subfunctions
objtool: Fix weak symbol hole detection for .cold functions
objtool: Mark prefix functions
objtool: Simplify reloc offset calculation in unwind_read_hints()
objtool: Avoid emptying lists for duplicate sections
objtool: Rename --Werror to --werror
objtool: Resurrect --backup option
objtool: Reindent check_options[]
objtool: Refactor add_jump_destinations()
objtool: Simplify special symbol handling in elf_update_symbol()
objtool: Generalize elf_create_symbol()
objtool: Generalize elf_create_section()
objtool: Add elf_create_data()
objtool: Add elf_create_reloc() and elf_init_reloc()
objtool: Add elf_create_file()
objtool: Add annotype() helper
objtool: Move ANNOTATE* macros to annotate.h
objtool: Add ANNOTATE_DATA_SPECIAL
x86/asm: Annotate special section entries
objtool: Unify STACK_FRAME_NON_STANDARD entry sizes objtool/klp: Add --checksum option to generate per-function checksums objtool/klp: Add --debug-checksum=<funcs> to show per-instruction
checksums
objtool/klp: Introduce klp diff subcommand for diffing object files objtool/klp: Add --debug option to show cloning decisions objtool/klp: Add post-link subcommand to finalize livepatch modules
objtool: Refactor prefix symbol creation code
objtool: Add base objtool support for livepatch modules
livepatch: Add CONFIG_KLP_BUILD
kbuild,objtool: Defer objtool validation step for CONFIG_KLP_BUILD livepatch/klp-build: Introduce fix-patch-lines script to avoid
__LINE__ diff noise
livepatch/klp-build: Add stub init code for livepatch modules livepatch/klp-build: Introduce klp-build script for generating
livepatch modules
livepatch/klp-build: Add --debug option to show cloning decisions livepatch/klp-build: Add --show-first-changed option to show function
divergence
livepatch: Introduce source code helpers for livepatch modules
MAINTAINERS | 3 +- arch/s390/include/asm/nospec-insn.h | 2 +- arch/s390/kernel/vmlinux.lds.S | 2 +- arch/x86/Kconfig | 1 + arch/x86/include/asm/alternative.h | 4 + arch/x86/include/asm/asm.h | 5 + arch/x86/include/asm/bug.h | 1 + arch/x86/include/asm/cpufeature.h | 1 + arch/x86/include/asm/jump_label.h | 1 + arch/x86/kernel/alternative.c | 51 +- arch/x86/kernel/kprobes/opt.c | 4 - arch/x86/kernel/module.c | 15 +- include/asm-generic/vmlinux.lds.h | 40 +- include/linux/annotate.h | 134 ++ include/linux/compiler.h | 8 +- include/linux/elfnote.h | 13 +- include/linux/init.h | 3 +- include/linux/interval_tree.h | 4 + include/linux/interval_tree_generic.h | 2 +- include/linux/livepatch.h | 25 +- include/linux/livepatch_external.h | 76 + include/linux/livepatch_helpers.h | 77 + include/linux/mm.h | 2 + include/linux/objtool.h | 96 +- include/linux/objtool_types.h | 2 + kernel/livepatch/Kconfig | 12 + kernel/livepatch/core.c | 8 +- scripts/Makefile.lib | 7 +- scripts/Makefile.vmlinux_o | 2 +- scripts/link-vmlinux.sh | 3 +- scripts/livepatch/fix-patch-lines | 79 + scripts/livepatch/init.c | 108 ++ scripts/livepatch/klp-build | 827 ++++++++ scripts/mod/modpost.c | 5 + scripts/module.lds.S | 22 +- tools/include/linux/interval_tree_generic.h | 10 +- tools/include/linux/livepatch_external.h | 76 + tools/include/linux/objtool_types.h | 2 + tools/include/linux/string.h | 14 + tools/objtool/Build | 4 +- tools/objtool/Makefile | 48 +- tools/objtool/arch/loongarch/decode.c | 6 +- tools/objtool/arch/loongarch/orc.c | 1 - tools/objtool/arch/powerpc/decode.c | 7 +- tools/objtool/arch/x86/decode.c | 63 +- tools/objtool/arch/x86/orc.c | 1 - tools/objtool/arch/x86/special.c | 2 +- tools/objtool/builtin-check.c | 96 +- tools/objtool/builtin-klp.c | 53 + tools/objtool/check.c | 875 +++++---- tools/objtool/elf.c | 781 ++++++-- tools/objtool/include/objtool/arch.h | 5 +- tools/objtool/include/objtool/builtin.h | 11 +- tools/objtool/include/objtool/check.h | 6 +- tools/objtool/include/objtool/checksum.h | 43 + .../objtool/include/objtool/checksum_types.h | 25 + tools/objtool/include/objtool/elf.h | 196 +- tools/objtool/include/objtool/endianness.h | 9 +- tools/objtool/include/objtool/klp.h | 35 + tools/objtool/include/objtool/objtool.h | 4 +- tools/objtool/include/objtool/util.h | 19 + tools/objtool/include/objtool/warn.h | 40 + tools/objtool/klp-diff.c | 1723 +++++++++++++++++ tools/objtool/klp-post-link.c | 168 ++ tools/objtool/objtool.c | 42 +- tools/objtool/orc_dump.c | 1 - tools/objtool/orc_gen.c | 9 +- tools/objtool/special.c | 14 +- tools/objtool/sync-check.sh | 2 + tools/objtool/weak.c | 7 + 70 files changed, 5152 insertions(+), 891 deletions(-) create mode 100644 include/linux/annotate.h create mode 100644 include/linux/livepatch_external.h create mode 100644 include/linux/livepatch_helpers.h create mode 100755 scripts/livepatch/fix-patch-lines create mode 100644 scripts/livepatch/init.c create mode 100755 scripts/livepatch/klp-build create mode 100644 tools/include/linux/livepatch_external.h create mode 100644 tools/objtool/builtin-klp.c create mode 100644 tools/objtool/include/objtool/checksum.h create mode 100644 tools/objtool/include/objtool/checksum_types.h create mode 100644 tools/objtool/include/objtool/klp.h create mode 100644 tools/objtool/include/objtool/util.h create mode 100644 tools/objtool/klp-diff.c create mode 100644 tools/objtool/klp-post-link.c
Signature · 1 line
2.50.0
arch/Kconfig +0 -3
@@ -1368,9 +1368,6 @@ config HAVE_NOINSTR_HACK config HAVE_NOINSTR_VALIDATION bool -config NEED_MODULE_PERMISSIONS_FIX - bool - config HAVE_UACCESS_VALIDATION bool select OBJTOOL
arch/um/include/asm/Kbuild +1 -0
@@ -5,6 +5,7 @@ generic-y += device.h generic-y += dma-mapping.h generic-y += emergency-restart.h generic-y += exec.h +generic-y += extable.h generic-y += ftrace.h generic-y += hw_irq.h generic-y += irq_regs.h
arch/um/include/shared/common-offsets.h +0 -3
@@ -18,6 +18,3 @@ DEFINE(UM_NSEC_PER_USEC, NSEC_PER_USEC);DEFINE (UM_KERN_GDT_ENTRY_TLS_ENTRIES ,GDT_ENTRY_TLS_ENTRIES );DEFINE (UM_SECCOMP_ARCH_NATIVE ,SECCOMP_ARCH_NATIVE ); - -DEFINE (ALT_INSTR_SIZE ,sizeof (struct alt_instr )); -DEFINE (EXTABLE_SIZE ,sizeof (struct exception_table_entry ));
arch/x86/Kconfig +0 -1
@@ -305,7 +305,6 @@ config X86 select HOTPLUG_SPLIT_STARTUP if SMP && X86_32 select IRQ_FORCED_THREADING select LOCK_MM_AND_FIND_VMA - select NEED_MODULE_PERMISSIONS_FIX select NEED_PER_CPU_EMBED_FIRST_CHUNK select NEED_PER_CPU_PAGE_FIRST_CHUNK select NEED_SG_DMA_LENGTH
arch/x86/include/asm/alternative.h +6 -3
@@ -197,8 +197,8 @@ static inline int alternatives_text_reserved(void *start, void *end) "773:\n"#define ALTINSTR_ENTRY (ft_flags) \ - ".pushsection .altinstructions, \"aM\", @progbits, " \ - __stringify(ALT_INSTR_SIZE) "\n" \ + ".pushsection .altinstructions,\"a\"\n" \ + ANNOTATE_DATA_SPECIAL \ " .long 771b - .\n"/* label */ \" .long 774f - .\n" /* new instruction */ \ " .4byte " __stringify(ft_flags) "\n" /* feature + flags */ \
@@ -208,6 +208,7 @@ static inline int alternatives_text_reserved(void *start, void *end)#define ALTINSTR_REPLACEMENT (newinstr)/* replacement */ \ ".pushsection .altinstr_replacement, \"ax\"\n" \ + ANNOTATE_DATA_SPECIAL \ "# ALT: replacement\n" \ "774:\n\t" newinstr "\n775:\n" \ ".popsection\n"
@@ -338,6 +339,7 @@ void nop_func(void);* instruction. See apply_alternatives(). */ .macro altinstr_entry orig alt ft_flags orig_len alt_len + ANNOTATE_DATA_SPECIAL .long \orig - . .long \alt - . .4byte \ft_flags
@@ -361,11 +363,12 @@ void nop_func(void); 741: \ .skip -(((744f-743f)-(741b-740b)) > 0) * ((744f-743f)-(741b-740b)),0x90 ;\ 742: \ - .pushsection .altinstructions, "aM", @progbits, ALT_INSTR_SIZE ;\ + .pushsection .altinstructions,"a" ; \altinstr_entry 740b,743f,flag,742b-740b,744f-743f ; \ .popsection ; \ .pushsection .altinstr_replacement," ax" ; \ 743: \ +ANNOTATE_DATA_SPECIAL ; \ newinst ; \ 744: \ .popsection ;
arch/x86/include/asm/asm.h +13 -14
@@ -2,6 +2,8 @@#ifndef _ASM_X86_ASM_H#define _ASM_X86_ASM_H +#include <linux/annotate.h> +#ifdef __ASSEMBLER__# define __ASM_FORM (x, ...) x,## __VA_ARGS__# define __ASM_FORM_RAW (x, ...) x,## __VA_ARGS__
@@ -124,21 +126,18 @@ static __always_inline __pure void *rip_rel_ptr(void *p)#ifdef __KERNEL__ -#ifndef COMPILE_OFFSETS -#include <asm/asm-offsets.h> -#endif -# include <asm/extable_fixup_types.h> /* Exception table entry */ #ifdef __ASSEMBLER__ -# define _ASM_EXTABLE_TYPE (from, to, type) \ - .pushsection "__ex_table", "aM", @progbits, EXTABLE_SIZE; \ - .balign 4 ; \ - .long (from) - . ; \ - .long (to) - . ; \ - .long type ; \ +# define _ASM_EXTABLE_TYPE (from, to, type) \ + .pushsection "__ex_table","a" ; \ + .balign 4 ; \ + ANNOTATE_DATA_SPECIAL ; \ + .long (from) - . ; \ + .long (to) - . ; \ + .long type ; \ .popsection# ifdef CONFIG_KPROBES
@@ -181,18 +180,18 @@ static __always_inline __pure void *rip_rel_ptr(void *p) ".purgem extable_type_reg\n"# define _ASM_EXTABLE_TYPE (from, to, type) \ - " .pushsection __ex_table, \"aM\", @progbits, " \ - __stringify(EXTABLE_SIZE) "\n" \ + " .pushsection \"__ex_table\",\"a\"\n" \ " .balign 4\n" \ + ANNOTATE_DATA_SPECIAL \ " .long (" #from ") - .\n" \ " .long (" #to ") - .\n" \ " .long " __stringify(type) " \n" \ " .popsection\n"# define _ASM_EXTABLE_TYPE_REG (from, to, type, reg) \ - " .pushsection __ex_table, \"aM\", @progbits, " \ - __stringify(EXTABLE_SIZE) "\n" \ + " .pushsection \"__ex_table\",\"a\"\n" \ " .balign 4\n" \ + ANNOTATE_DATA_SPECIAL \ " .long (" #from ") - .\n" \ " .long (" #to ") - .\n" \ DEFINE_EXTABLE_TYPE_REG \
arch/x86/include/asm/bug.h +2 -1
@@ -56,7 +56,8 @@#define _BUG_FLAGS_ASM (ins, file, line, flags, size, extra) \ "1:\t" ins "\n" \ - ".pushsection __bug_table, \"aM\", @progbits, " size "\n" \ + ".pushsection __bug_table,\"aw\"\n" \ + ANNOTATE_DATA_SPECIAL \ __BUG_ENTRY(file, line, flags) \ "\t.org 2b + " size "\n" \ ".popsection\n" \
arch/x86/include/asm/cpufeature.h +1 -0
@@ -101,6 +101,7 @@ static __always_inline bool _static_cpu_has(u16 bit) asm goto(ALTERNATIVE_TERNARY("jmp 6f", %c[feature], "", "jmp %l[t_no]")".pushsection .altinstr_aux,\"ax\"\n" "6:\n" +ANNOTATE_DATA_SPECIAL " testb %[bitnum], %a[cap_byte]\n" " jnz %l[t_yes]\n" " jmp %l[t_no]\n"
arch/x86/include/asm/jump_label.h +7 -11
@@ -12,17 +12,13 @@#include <linux/stringify.h> #include <linux/types.h> -#ifndef COMPILE_OFFSETS -#include <generated/bounds.h> -#endif - -#define JUMP_TABLE_ENTRY (key, label) \ - ".pushsection __jump_table, \"aM\", @progbits, " \ - __stringify(JUMP_ENTRY_SIZE) "\n\t" \ - _ASM_ALIGN "\n\t" \ - ".long 1b - . \n\t" \ - ".long " label " - . \n\t" \ - _ASM_PTR " " key " - . \n\t" \ +#define JUMP_TABLE_ENTRY (key, label) \ + ".pushsection __jump_table, \"aw\" \n\t" \ + _ASM_ALIGN "\n\t" \ + ANNOTATE_DATA_SPECIAL \ + ".long 1b - . \n\t" \ + ".long " label " - . \n\t" \ + _ASM_PTR " " key " - . \n\t" \ ".popsection \n\t"/* This macro is also expanded on the Rust side. */
arch/x86/include/asm/static_call.h +1 -2
@@ -58,8 +58,7 @@ ARCH_DEFINE_STATIC_CALL_TRAMP(name, __static_call_return0)#define ARCH_ADD_TRAMP_KEY (name) \ - asm(".pushsection .static_call_tramp_key, \"aM\", @progbits, " \ - __stringify(STATIC_CALL_TRAMP_KEY_SIZE) "\n" \ + asm(".pushsection .static_call_tramp_key, \"a\" \n" \ ".long " STATIC_CALL_TRAMP_STR(name) " - . \n" \ ".long " STATIC_CALL_KEY_STR(name) " - . \n" \ ".popsection \n")
arch/x86/kernel/asm-offsets.c +0 -3
@@ -124,7 +124,4 @@ static void __used common(void)OFFSET (ARIA_CTX_rounds, aria_ctx, rounds);#endif -BLANK (); -DEFINE (ALT_INSTR_SIZE ,sizeof (struct alt_instr )); -DEFINE (EXTABLE_SIZE ,sizeof (struct exception_table_entry )); }
arch/x86/um/shared/sysdep/kernel-offsets.h +0 -2
@@ -1,5 +1,4 @@/* SPDX-License-Identifier: GPL-2.0 */ -#define COMPILE_OFFSETS #include <linux/stddef.h> #include <linux/sched.h> #include <linux/elf.h>
@@ -8,7 +7,6 @@#include <linux/audit.h> #include <asm/mman.h> #include <asm/seccomp.h> -#include <asm/extable.h> /* workaround for a warning with -Wmissing-prototypes */ void foo (void );
include/linux/annotate.h new file +134 -0
134 lines not on this page · raw message
include/linux/interval_tree.h +4 -0
@@ -19,6 +19,10 @@ extern void interval_tree_remove(struct interval_tree_node *node, struct rb_root_cached *root); +extern struct interval_tree_node * +interval_tree_subtree_search (struct interval_tree_node *node, +unsigned long start,unsigned long last); +extern struct interval_tree_node *interval_tree_iter_first (struct rb_root_cached *root,unsigned long start,unsigned long last);
include/linux/interval_tree_generic.h +1 -1
@@ -77,7 +77,7 @@ ITSTATIC void ITPREFIX ## _remove(ITSTRUCT *node, \* Cond2: start <= ITLAST(node) \ */ \ \ -static ITSTRUCT * \ +ITSTATIC ITSTRUCT * \ ITPREFIX ## _subtree_search(ITSTRUCT *node, ITTYPE start, ITTYPE last) \ { \while (true) { \
include/linux/livepatch_helpers.h +0 -2
@@ -36,8 +36,6 @@__PASTE (__KLP_POST_UNPATCH_PREFIX,KLP_OBJNAME ) = func/* -* KLP_STATIC_CALL -* * Replace static_call() usage with this macro when create-diff-object * recommends it due to the original static call key living in a module. *
include/linux/mm.h +2 -0
@@ -3265,6 +3265,8 @@ void vma_interval_tree_insert_after(struct vm_area_struct *node, struct rb_root_cached *root);void vma_interval_tree_remove (struct vm_area_struct *node,struct rb_root_cached *root); +struct vm_area_struct *vma_interval_tree_subtree_search (struct vm_area_struct *node, +unsigned long start,unsigned long last);struct vm_area_struct *vma_interval_tree_iter_first (struct rb_root_cached *root,unsigned long start,unsigned long last); struct vm_area_struct *vma_interval_tree_iter_next(struct vm_area_struct *node,
include/linux/objtool.h +5 -96
148 lines not on this page · raw message
include/linux/objtool_types.h +2 -0
@@ -67,4 +67,6 @@ struct unwind_hint {#define ANNOTYPE_REACHABLE 8#define ANNOTYPE_NOCFI 9 +#define ANNOTYPE_DATA_SPECIAL 1 +#endif /* _LINUX_OBJTOOL_TYPES_H */
include/linux/static_call.h +6 -0
@@ -172,6 +172,12 @@ struct static_call_mod {struct static_call_site *sites; }; +/* For finding the key associated with a trampoline */ +struct static_call_tramp_key { +s32 tramp; +s32 key; +}; +extern void __static_call_update (struct static_call_key *key,void *tramp,void *func);extern int static_call_mod_init (struct module *mod);extern int static_call_text_reserved (void *start,void *end);
include/linux/static_call_types.h +0 -6
@@ -34,12 +34,6 @@ struct static_call_site {s32 key; }; -/* For finding the key associated with a trampoline */ -struct static_call_tramp_key { -s32 tramp; -s32 key; -}; -#define DECLARE_STATIC_CALL (name, func) \ extern struct static_call_key STATIC_CALL_KEY(name); \ extern typeof(func) STATIC_CALL_TRAMP(name);
kernel/bounds.c +0 -13
@@ -6,16 +6,12 @@*/ #define __GENERATING_BOUNDS_H -#define COMPILE_OFFSETS /* Include headers that define the enum constants of interest */ #include <linux/page-flags.h> #include <linux/mmzone.h> #include <linux/kbuild.h> #include <linux/log2.h> #include <linux/spinlock_types.h> -#include <linux/jump_label.h> -#include <linux/static_call_types.h> -#include <linux/objtool_types.h> int main (void ) {
@@ -32,15 +28,6 @@ int main(void)#else DEFINE (LRU_GEN_WIDTH ,0 );DEFINE (__LRU_REFS_WIDTH,0 ); -#endif -#if defined(CONFIG_HAVE_ARCH_JUMP_LABEL_RELATIVE ) && defined(CONFIG_JUMP_LABEL ) -DEFINE (JUMP_ENTRY_SIZE ,sizeof (struct jump_entry )); -#endif -#ifdef CONFIG_HAVE_STATIC_CALL_INLINE -DEFINE (STATIC_CALL_TRAMP_KEY_SIZE ,sizeof (struct static_call_tramp_key )); -#endif -#ifdef CONFIG_OBJTOOL -DEFINE (UNWIND_HINT_SIZE ,sizeof (struct unwind_hint ));#endif /* End of constants */
scripts/Makefile.lib +1 -0
@@ -173,6 +173,7 @@ ifdef CONFIG_OBJTOOL objtool := $(objtree)/tools/objtool/objtool +objtool-args-$(CONFIG_KLP_BUILD) += --checksum objtool-args-$(CONFIG_HAVE_JUMP_LABEL_HACK) += --hacks=jump_label objtool-args-$(CONFIG_HAVE_NOINSTR_HACK) += --hacks=noinstr objtool-args-$(CONFIG_MITIGATION_CALL_DEPTH_TRACKING) += --hacks=skylake
scripts/Makefile.modfinal +5 -14
@@ -28,24 +28,12 @@ ccflags-remove-y := $(CC_FLAGS_CFI) .module-common.o: $(srctree)/scripts/module-common.c FORCE $(call if_changed_rule,cc_o_c) -ifdef CONFIG_NEED_MODULE_PERMISSIONS_FIX -cmd_fix_mod_permissions = \ - $(OBJCOPY) --set-section-flags __jump_table=alloc,data \ - --set-section-flags __bug_table=alloc,data $@ \ - --set-section-flags .static_call_sites=alloc,data $@ -endif - quiet_cmd_ld_ko_o = LD [M] $@ cmd_ld_ko_o = \ $(LD) -r $(KBUILD_LDFLAGS) \ $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \ -T $(objtree)/scripts/module.lds -o $@ $(filter %.o, $^) -define rule_ld_ko_o - $(call cmd_and_savecmd,ld_ko_o) - $(call cmd,fix_mod_permissions) -endef - quiet_cmd_btf_ko = BTF [M] $@ cmd_btf_ko = \ if [ ! -f $(objtree)/vmlinux ]; then \
@@ -58,11 +46,14 @@ quiet_cmd_btf_ko = BTF [M] $@ # Same as newer-prereqs, but allows to exclude specified extra dependencies newer_prereqs_except = $(filter-out $(PHONY) $(1),$?) -if_changed_rule_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check),$(rule_$(1)),@:) +# Same as if_changed, but allows to exclude specified extra dependencies +if_changed_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check), \ + $(cmd); \ + printf '%s\n' 'savedcmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:) # Re-generate module BTFs if either module's .ko or vmlinux changed %.ko: %.o %.mod.o .module-common.o $(objtree)/scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),$(objtree)/vmlinux) FORCE - +$(call if_changed_rule_except,ld_ko_o,$(objtree)/vmlinux) + +$(call if_changed_except,ld_ko_o,$(objtree)/vmlinux) ifdef CONFIG_DEBUG_INFO_BTF_MODULES +$(if $(newer-prereqs),$(call cmd,btf_ko)) endif
scripts/livepatch/klp-build +2 -6
@@ -489,11 +489,8 @@ clean_kernel() { build_kernel() { local log="$TMP_DIR/build.log" - local objtool_args=() local cmd=() - objtool_args=("--checksum") - cmd=("make") # When a patch to a kernel module references a newly created unexported
@@ -516,7 +513,6 @@ build_kernel() { cmd+=("$VERBOSE") cmd+=("-j$JOBS") cmd+=("KCFLAGS=-ffunction-sections -fdata-sections") - cmd+=("OBJTOOL_ARGS=${objtool_args[*]}") cmd+=("vmlinux") cmd+=("modules")
@@ -794,7 +790,7 @@ process_args "$@" do_init if (( SHORT_CIRCUIT <= 1 )); then - status "Validating patches" + status "Validating patch(es)" validate_patches status "Building original kernel" clean_kernel
@@ -804,7 +800,7 @@ if (( SHORT_CIRCUIT <= 1 )); then fi if (( SHORT_CIRCUIT <= 2 )); then - status "Fixing patches" + status "Fixing patch(es)" fix_patches apply_patches status "Building patched kernel"
scripts/mod/devicetable-offsets.c +0 -1
@@ -1,5 +1,4 @@// SPDX-License-Identifier: GPL-2.0 -#define COMPILE_OFFSETS #include <linux/kbuild.h> #include <linux/mod_devicetable.h>
tools/include/linux/interval_tree_generic.h +2 -6
@@ -104,12 +104,8 @@ ITPREFIX ## _subtree_search(ITSTRUCT *node, ITTYPE start, ITTYPE last) \if (ITSTART (node) <= last) {/* Cond1 */ \if (start <=ITLAST (node))/* Cond2 */ \return node;/* node is leftmost match */ \ -if (node->ITRB.rb_right) { \ - node =rb_entry (node->ITRB.rb_right, \ -ITSTRUCT ,ITRB ); \ -if (start <= node->ITSUBTREE) \ -continue ; \ - } \ + node =rb_entry (node->ITRB.rb_right,ITSTRUCT ,ITRB ); \ +continue ; \ } \return NULL ;/* No match */ \ } \
tools/include/linux/objtool_types.h +2 -0
@@ -67,4 +67,6 @@ struct unwind_hint {#define ANNOTYPE_REACHABLE 8#define ANNOTYPE_NOCFI 9 +#define ANNOTYPE_DATA_SPECIAL 1 +#endif /* _LINUX_OBJTOOL_TYPES_H */
tools/include/linux/static_call_types.h +0 -6
@@ -34,12 +34,6 @@ struct static_call_site {s32 key; }; -/* For finding the key associated with a trampoline */ -struct static_call_tramp_key { -s32 tramp; -s32 key; -}; -#define DECLARE_STATIC_CALL (name, func) \ extern struct static_call_key STATIC_CALL_KEY(name); \ extern typeof(func) STATIC_CALL_TRAMP(name);
tools/objtool/arch/loongarch/orc.c +0 -1
@@ -5,7 +5,6 @@#include <objtool/check.h> #include <objtool/orc.h> #include <objtool/warn.h> -#include <objtool/endianness.h> int init_orc_entry (struct orc_entry *orc,struct cfi_state *cfi,struct instruction *insn) {
tools/objtool/arch/powerpc/decode.c +0 -1
@@ -7,7 +7,6 @@#include <objtool/arch.h> #include <objtool/warn.h> #include <objtool/builtin.h> -#include <objtool/endianness.h> int arch_ftrace_match (const char *name) {
tools/objtool/arch/x86/decode.c +0 -1
@@ -19,7 +19,6 @@#include <objtool/elf.h> #include <objtool/arch.h> #include <objtool/warn.h> -#include <objtool/endianness.h> #include <objtool/builtin.h> #include <arch/elf.h>
tools/objtool/arch/x86/orc.c +0 -1
@@ -5,7 +5,6 @@#include <objtool/check.h> #include <objtool/orc.h> #include <objtool/warn.h> -#include <objtool/endianness.h> int init_orc_entry (struct orc_entry *orc,struct cfi_state *cfi,struct instruction *insn) {
tools/objtool/builtin-check.c +1 -2
@@ -74,7 +74,7 @@ static int parse_hacks(const struct option *opt, const char *str, int unset)static const struct option check_options[] = {OPT_GROUP ("Actions:" ),OPT_BOOLEAN (0 ,"checksum" , &opts.checksum,"generate per-function checksums" ), -OPT_BOOLEAN (0 ,"cfi" , &opts.cfi,"annotate kernel control flow integrity (kCFI) function preambles" ), +OPT_BOOLEAN (0 ,"cfi" , &opts.cfi,"annotate kernel control flow integrity (kCFI) function preambles" ),OPT_CALLBACK_OPTARG ('h' ,"hacks" ,NULL ,NULL ,"jump_label,noinstr,skylake" ,"patch toolchain bugs/limitations" , parse_hacks),OPT_BOOLEAN ('i' ,"ibt" , &opts.ibt,"validate and annotate IBT" ),OPT_BOOLEAN ('m' ,"mcount" , &opts.mcount,"annotate mcount/fentry calls for ftrace" ),
@@ -162,7 +162,6 @@ static bool opts_valid(void)return false; } -#ifndef BUILD_KLP if (opts.checksum) {ERROR ("--checksum not supported; install xxhash-devel and recompile" );
tools/objtool/check.c +60 -41
178 lines not on this page · raw message
tools/objtool/elf.c +29 -34
90 lines not on this page · raw message
tools/objtool/include/objtool/builtin.h +1 -1
@@ -10,6 +10,7 @@struct opts {/* actions: */ bool cfi; +bool checksum;bool dump_orc;bool hack_jump_label;bool hack_noinstr;
@@ -25,7 +26,6 @@ struct opts {bool sls;bool stackval;bool static_call; -bool checksum;bool uaccess;int prefix;
tools/objtool/include/objtool/elf.h +17 -6
@@ -14,12 +14,15 @@#include <linux/rbtree.h> #include <linux/jhash.h> +#include <objtool/endianness.h> #include <objtool/checksum_types.h> #include <arch/elf.h> #define SEC_NAME_LEN 1024#define SYM_NAME_LEN 512 +#define bswap_if_needed (elf, val) __bswap_if_needed(&elf->ehdr, val) +#ifdef LIBELF_USE_DEPRECATED # define elf_getshdrnum elf_getshnum# define elf_getshdrstrndx elf_getshstrndx
@@ -146,8 +149,6 @@ struct symbol *elf_create_symbol(struct elf *elf, const char *name, unsigned int type, unsigned long offset, size_t size);struct symbol *elf_create_section_symbol (struct elf *elf,struct section *sec); -struct symbol *elf_create_prefix_symbol (struct elf *elf,struct symbol *orig, -size_t size);void *elf_add_data (struct elf *elf,struct section *sec,const void *data,size_t size);
@@ -274,7 +275,7 @@ static inline bool is_local_sym(struct symbol *sym)static inline bool is_prefix_func (struct symbol *sym) { -return is_func_sym (sym) && sym->prefix; +return sym->prefix; }static inline bool is_reloc_sec (struct section *sec)
@@ -414,6 +415,15 @@ static inline void set_reloc_type(struct elf *elf, struct reloc *reloc, unsignedmark_sec_changed (elf, reloc->sec, true); } +static inline unsigned int annotype (struct elf *elf,struct section *sec, +struct reloc *reloc) +{ +unsigned int type; + + type = *(u32 *)(sec->data->d_buf + (reloc_idx (reloc) *8 ) +4 ); +return bswap_if_needed (elf, type); +} +#define RELOC_JUMP_TABLE_BIT 1UL/* Does reloc mark the beginning of a jump table? */
@@ -445,9 +455,6 @@ static inline void set_sym_next_reloc(struct reloc *reloc, struct reloc *next)#define sec_for_each_sym (sec, sym) \ list_for_each_entry(sym, &sec->symbol_list, list) -#define sec_for_each_sym_continue_reverse (sec, sym) \ - list_for_each_entry_continue_reverse(sym, &sec->symbol_list, list) -#define sec_prev_sym (sym) \ sym->sec && sym->list.prev != &sym->sec->symbol_list ? \ list_prev_entry(sym, list) : NULL
@@ -467,6 +474,10 @@ static inline void set_sym_next_reloc(struct reloc *reloc, struct reloc *next)#define for_each_reloc_from (rsec, reloc) \ for (; reloc; reloc = rsec_next_reloc(rsec, reloc)) +#define for_each_reloc_continue (rsec, reloc) \ + for (reloc = rsec_next_reloc(rsec, reloc); reloc; \ + reloc = rsec_next_reloc(rsec, reloc)) +#define sym_for_each_reloc (elf, sym, reloc) \ for (reloc = find_reloc_by_dest_range(elf, sym->sec, \ sym->offset, sym->len); \
tools/objtool/include/objtool/endianness.h +4 -5
@@ -4,7 +4,6 @@#include <linux/kernel.h> #include <endian.h> -#include <objtool/elf.h> /* * Does a byte swap if target file endianness doesn't match the host, i.e. cross
@@ -12,16 +11,16 @@* To be used for multi-byte values conversion, which are read from / about * to be written to a target native endianness ELF file. */ -static inline bool need_bswap (struct elf *elf) +static inline bool need_bswap (GElf_Ehdr *ehdr) {return (__BYTE_ORDER == __LITTLE_ENDIAN) ^ - (elf->ehdr.e_ident[EI_DATA ] ==ELFDATA2LSB ); + (ehdr->e_ident[EI_DATA ] ==ELFDATA2LSB ); } -#define bswap_if_needed (elf, val) \ +#define __bswap_if_needed (ehdr, val) \ ({ \ __typeof__(val) __ret; \ - bool __need_bswap = need_bswap(elf); \ + bool __need_bswap = need_bswap(ehdr); \ switch (sizeof(val)) { \ case 8: \ __ret = __need_bswap ? bswap_64(val) : (val); break; \
tools/objtool/include/objtool/objtool.h +0 -2
@@ -14,8 +14,6 @@#define __weak __attribute__((weak)) -#define SYM_CHECKSUM_SEC ".discard.sym_checksum" -struct pv_state {bool clean;struct list_head targets;
tools/objtool/klp-diff.c +138 -92
277 lines not on this page · raw message
tools/objtool/orc_dump.c +0 -1
@@ -8,7 +8,6 @@#include <objtool/objtool.h> #include <objtool/orc.h> #include <objtool/warn.h> -#include <objtool/endianness.h> int orc_dump (const char *filename) {
tools/objtool/orc_gen.c +0 -1
@@ -12,7 +12,6 @@#include <objtool/check.h> #include <objtool/orc.h> #include <objtool/warn.h> -#include <objtool/endianness.h> struct orc_list_entry {struct list_head list;
tools/objtool/special.c +0 -1
@@ -15,7 +15,6 @@#include <objtool/builtin.h> #include <objtool/special.h> #include <objtool/warn.h> -#include <objtool/endianness.h> struct special_entry {const char *sec;
tools/objtool/sync-check.sh +1 -0
@@ -16,6 +16,7 @@ arch/x86/include/asm/orc_types.h arch/x86/include/asm/emulate_prefix.h arch/x86/lib/x86-opcode-map.txt arch/x86/tools/gen-insn-attr-x86.awk +include/linux/interval_tree_generic.h include/linux/livepatch_external.h include/linux/static_call_types.h "