Skip to content

ftrace/sorttable: Fix ftrace symbol table corruption with CONFIG_X86_KERNEL_IBT=y

Andrey Grodzovsky stable 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest27 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/27scripts/sorttable: Remove unused macro definesscripts/sorttable.h+0 -270 replies
2/27scripts/sorttable: Remove unused write functionsscripts/sorttable.c+0 -260 replies
3/27scripts/sorttable: Remove unneeded Elf_Relscripts/sorttable.h+2 -210 replies
4/27scripts/sorttable: Have the ORC code use the _r() functions to readscripts/sorttable.h+4 -40 replies
5/27scripts/sorttable: Make compare_extable() into two functionsscripts/sorttable.c scripts/sorttable.h+20 -140 replies
6/27scripts/sorttable: Convert Elf_Ehdr to unionscripts/sorttable.c scripts/sorttable.h+26 -220 replies
7/27scripts/sorttable: Replace Elf_Shdr Macro with a unionscripts/sorttable.c scripts/sorttable.h+51 -330 replies
8/27scripts/sorttable: Convert Elf_Sym MACRO over to a unionscripts/sorttable.c scripts/sorttable.h+19 -110 replies
9/27scripts/sorttable: Add helper functions for Elf_Ehdrscripts/sorttable.c scripts/sorttable.h+41 -40 replies
10/27scripts/sorttable: Add helper functions for Elf_Shdrscripts/sorttable.c scripts/sorttable.h+85 -230 replies
11/27scripts/sorttable: Add helper functions for Elf_Symscripts/sorttable.c scripts/sorttable.h+63 -140 replies
12/27scripts/sorttable: Use uint64_t for mcount sortingscripts/sorttable.h+11 -110 replies
13/27scripts/sorttable: Move code from sorttable.h into sorttable.cscripts/sorttable.c scripts/sorttable.h+460 -4980 replies
14/27scripts/sorttable: Get start/stop_mcount_loc from ELF file directlyscripts/sorttable.c+45 -500 replies
15/27scripts/sorttable: Use a structure of function pointers for elf helpersscripts/sorttable.c+118 -570 replies
16/27arm64: scripts/sorttable: Implement sorting mcount_loc at boot for arm64arch/arm64/Kconfig scripts/sorttable.c+183 -30 replies
17/27scripts/sorttable: Have mcount rela sort use direct valuesscripts/sorttable.c+25 -10 replies
18/27scripts/sorttable: Always use an array for the mcount_loc sortingscripts/sorttable.c+90 -320 replies
19/27scripts/sorttable: Zero out weak functions in mcount_loc tablekernel/trace/ftrace.c scripts/link-vmlinux.sh scripts/sorttable.c+134 -40 replies
20/27ftrace: Update the mcount_loc check of skipped entrieskernel/trace/ftrace.c+22 -10 replies
21/27ftrace: Have ftrace pages output reflect freed pageskernel/trace/ftrace.c+12 -30 replies
22/27ftrace: Do not over-allocate ftrace memorykernel/trace/ftrace.c+15 -140 replies
23/27ftrace: Test mcount_loc addr before calling ftrace_call_addr()kernel/trace/ftrace.c+5 -10 replies
24/27ftrace: Check against is_kernel_text() instead of kaslr_offset()kernel/trace/ftrace.c+12 -50 replies
25/27scripts/sorttable: Use normal sort if theres no relocs in the mcount sectionscripts/sorttable.c+7 -20 replies
26/27scripts/sorttable: Allow matches to functions before function entryscripts/sorttable.c+6 -10 replies
27/27scripts/sorttable: Fix endianness handling in build-time mcount sortscripts/sorttable.c+1 -10 replies

Reviews trailers per patch

1 of 27 patches has a Reviewed-by or Acked-by.

PatchCatalin MarinasNathan Chancellor
1/27
2/27
3/27
4/27
5/27
6/27
7/27
8/27
9/27
10/27
11/27
12/27
13/27
14/27
15/27
16/27A-b
17/27
18/27
19/27
20/27
21/27
22/27
23/27T-b
24/27T-b
25/27T-b
26/27T-b
27/27

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 6.12.y 00/27] ftrace/sorttable: Fix ftrace symbol table corruption with CONFIG_X86_KERNEL_IBT=y

This series backports the upstream fix for ftrace symbol table corruption on kernels with CONFIG_X86_KERNEL_IBT=y. Weak overridden functions corrupt the ftrace symbol table at boot, causing non-deterministic hook attachment failures across all ftrace consumers — most visibly fentry/trampoline-based hooks, but affecting any code that relies on ftrace symbol lookups.

The fix was merged to mainline in Linux 6.15 via:
https://lore.kernel.org/all/[email protected]/

The original backport request and bug description sent to stable:
https://lore.kernel.org/stable/CAOu3gNibeo3ov09CYpmzuqewB0EOsajB3hPU9pQmb_zoAUraHg@mail.gmail.com/

Red Hat independently backported this same set of patches to their RHEL 10 kernel (6.12). Their work is at:
https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-10/-/merge_requests/2689

The 27 patches are organized in four groups:
- Patches 01-14: sorttable.c rewrite (prereq, merged 6.14)
- Patch 15: function pointer struct cleanup (prereq, merged 6.14)
- Patches 16-21: the core IBT fix series (merged 6.15)
- Patches 22-27: post-merge correctness fixes for arm64 and s390

All patches applied cleanly to 6.12.y (at 6.12.93). Tested on x86_64 with CONFIG_X86_KERNEL_IBT=y:

  grep __ftrace_invalid_address___ \
    /sys/kernel/tracing/available_filter_functions | wc -l
  Before: 589   After: 0

ftrace kernel selftests (tools/testing/selftests/ftrace):
135 passed, 0 failed, 0 regressions introduced.

Guenter Roeck (1):
ftrace: Do not over-allocate ftrace memory

Steven Rostedt (25):
scripts/sorttable: Remove unused macro defines scripts/sorttable: Remove unused write functions scripts/sorttable: Remove unneeded Elf_Rel scripts/sorttable: Have the ORC code use the _r() functions to read scripts/sorttable: Make compare_extable() into two functions scripts/sorttable: Convert Elf_Ehdr to union scripts/sorttable: Replace Elf_Shdr Macro with a union scripts/sorttable: Convert Elf_Sym MACRO over to a union scripts/sorttable: Add helper functions for Elf_Ehdr scripts/sorttable: Add helper functions for Elf_Shdr scripts/sorttable: Add helper functions for Elf_Sym scripts/sorttable: Use uint64_t for mcount sorting scripts/sorttable: Move code from sorttable.h into sorttable.c scripts/sorttable: Get start/stop_mcount_loc from ELF file directly scripts/sorttable: Use a structure of function pointers for elf
helpers
arm64: scripts/sorttable: Implement sorting mcount_loc at boot for

    arm64

scripts/sorttable: Have mcount rela sort use direct values scripts/sorttable: Always use an array for the mcount_loc sorting scripts/sorttable: Zero out weak functions in mcount_loc table
ftrace: Update the mcount_loc check of skipped entries
ftrace: Have ftrace pages output reflect freed pages
ftrace: Test mcount_loc addr before calling ftrace_call_addr()
ftrace: Check against is_kernel_text() instead of kaslr_offset() scripts/sorttable: Use normal sort if theres no relocs in the mcount
section
scripts/sorttable: Allow matches to functions before function entry

Vasily Gorbik (1):
scripts/sorttable: Fix endianness handling in build-time mcount sort

 arch/arm64/Kconfig      |    1 +
 kernel/trace/ftrace.c   |   68 ++-
 scripts/link-vmlinux.sh |    4 +-
 scripts/sorttable.c     | 1119 +++++++++++++++++++++++++++++++++++++--
 scripts/sorttable.h     |  500 -----------------
 5 files changed, 1133 insertions(+), 559 deletions(-)
 delete mode 100644 scripts/sorttable.h
Signature · 1 line
2.34.1