Repository navigation
create-diff-object: register patchable child functions - #1526
benjamindonnachie wants to merge 3 commits into
Conversation
Compiler-generated child functions such as *.part.* can have their own profiling call. In that case kpatch_compare_sections() deliberately leaves an unchanged parent unmodified because the child can be patched independently. However, kpatch_create_patches_sections() unconditionally skips every symbol with a parent. The replacement child text and relocations are retained in the module, but no .kpatch.funcs record is emitted, so the kernel never registers or redirects the changed function. Use one predicate for change reporting and patch metadata generation. Register a changed child when it has its own profiling entry and no changed ancestor already carries its replacement code. Continue excluding unpatchable children and children covered by a changed ancestor. Fixes: af1fe26 ("create-diff-object: Avoid unnecessary parent symbol inclusion") Signed-off-by: Benjamin Donnachie <benjamin@py-soft.co.uk> Co-authored-by: OpenAI Codex <codex@openai.com>
|
/packit test |
|
Hello, We ran into the same omission independently, in a study of live-patch modules, and have evidence that it affects shipped hotpatches and real stable fixes. We are posting it here in support of this change. A shipped case. openEuler 22.03 LTS SP4 hotpatch ACC-1-6 for kernel 5.10.0-216.0.0.115 (x86_64, GCC 10.3.1) carries the fix for CVE-2025-21727 (upstream e01780ea4661, a How often real fixes have this shape. We compiled, before and after the fix, every object changed by 2,445 stable fixes on 6.1.119, 6.6.47, 6.12.51 and 6.19. 13 of them (0.53%, Wilson 95% interval 0.31% to 0.91%; 8 distinct CVEs) change a What kpatch-build v0.9.11 makes of them. Ten of the 13 are on the 6.1, 6.6 and 6.12 kernels. kpatch-build v0.9.11 (gcc 13) built a module for nine and refused the tenth (CVE-2025-40196, which also changes an
The 6.12 CVE-2026-68200 row is the same On the fix. Registering the changed child when it has its own entry and no changed ancestor carries it, as this PR does, matches what we would expect to close all of the cases above. The alternative of marking the parent CHANGED whenever any child changed would also close them, at the cost of replacing unchanged wrappers. openEuler's kpatch maintainers reproduced the problem and tested a change along the lines of this PR on x86_64. Their shipped fix avoids the clone instead, by building the object with We can share the objects and a script that reproduces the omission with create-diff-object at HEAD, and we are glad to run this PR over the nine fixes above if that helps the review. Thank you for working on this. |
joe-lawrence
left a comment
There was a problem hiding this comment.
Hi @benjamindonnachie, thanks for posting and apologies for taking an eternity to review this.
The good news, AFAICT this is a kpatch-build-specific bug, so the upstream klp-build tooling (where most development happens these days) isn't affected by it.
The implementation looks fine overall. One nitpick on the kpatch_print_changes update (see inline comment): the revised loop filter looks a little too strict since kpatch_is_patch_func() only returns true for CHANGED symbols, it also filters out NEW functions, which used to be reported.
Separately (and this may be entirely academic), the new kpatch_is_patch_func() walks the whole ancestor chain looking for a changed ancestor, whereas the existing kpatch_check_func_profiling_calls() only checks the immediate parent. Is that worth a follow-up fixup, or do compilers not really generate multi-generational child functions in practice?
Thanks again.
| list_for_each_entry(sym, &kelf->symbols, list) { | ||
| if (!sym->include || !sym->sec || sym->type != STT_FUNC || | ||
| sym->parent || sym->is_pfx) | ||
| if (!sym->include || !sym->sec || !kpatch_is_patch_func(sym) || |
There was a problem hiding this comment.
I think checking for only !kpatch_is_patch_func() here would inadvertently filter out any NEW function from the report* as they won't be sym->status == CHANGED ... maybe we need to relax the filter for those, too:
bool is_new_func = sym->type == STT_FUNC &&
sym->status == NEW && !sym->parent;
if (!sym->include || !sym->sec || sym->is_pfx ||
!(kpatch_is_patch_func(sym) || is_new_func))
continue;* the function may be called print changes, but you can see a few lines below it also prints out new functions as well :)
|
@benjamindonnachie : I also created a new unit test, If you could bump the submodule test/unit/objs commit pin up to include that test case, that would be great. It fails before this PR and passes after. |
…checks Keep reporting included NEW top-level functions alongside independently patchable CHANGED functions. The patch-function predicate intentionally excludes NEW symbols, so it cannot alone select functions for the change report. Share the changed-ancestor traversal with profiling validation. A changed grandparent can carry an unprofiled descendant even when its immediate parent is unchanged; checking only the immediate parent would reject that descendant despite the patch registration logic excluding it. Signed-off-by: Benjamin Donnachie <benjamin@py-soft.co.uk>
Advance test/unit/objs to 962d0c616cb8f58842ecc297e34d97510836dadb, including the x86_64/part-change-sub regression test from dynup/kpatch-unit-test-objs#59. Signed-off-by: Benjamin Donnachie <benjamin@py-soft.co.uk>
|
Thanks, @joe-lawrence. I’ve corrected the reporting filter and updated the test submodule pin. On the ancestor question, my compiler testing has been limited to gcc (GCC) 11.5.0 20240719 (Red Hat 11.5.0-14), so I cannot say how commonly compilers produce these nested relationships. The parent-detection code can represent them, though. I’ve therefore shared the ancestor traversal between profiling validation and patch-function selection, so they apply the same rule. A focused synthetic check reproduces the inconsistent behaviour with a changed grandparent and an unchanged immediate parent, and passes after this adjustment. The full Linux build and unit suite have not yet been rerun for these updates. |
|
/packit test |
Summary
Problem
GCC split
snd_timer_interrupt()into an unchanged wrapper and a changedsnd_timer_interrupt.part.0. The child had its own__fentry__, sokpatch_compare_sections()correctly avoided promoting the unchanged parent.Later,
kpatch_create_patches_sections()unconditionally skipped every symbolwith
sym->parent. The resulting livepatch module contained the changed childtext and its KLP relocations, but no
.kpatch.funcsregistration record. Themodule loaded successfully while the changed execution path remained unpatched.
Validation
make -C kpatch-build -j4(with-Werror): passmake -C test/unit ARCHES=x86_64: pass5.14.0-687.48.1.el9_8.x86_64: passsnd_timer_interrupt.part.0enabled=1,transition=0snd_timer_interrupt.part.0,1andsnd_timer_close_locked,1The failure was discovered while auditing a cumulative security livepatch: the
source/CVE manifest claimed coverage and the module loaded normally, but sysfs
showed the missing child-function registration.
Closes #1525