Skip to content

create-diff-object: register patchable child functions - #1526

Open
benjamindonnachie wants to merge 3 commits into
dynup:masterfrom
benjamindonnachie:fix-patchable-child-registration-upstream
Open

benjamindonnachie wants to merge 3 commits into
dynup:masterfrom
benjamindonnachie:fix-patchable-child-registration-upstream

Conversation

@benjamindonnachie

Copy link
Copy Markdown

Summary

  • register changed compiler-generated child functions when they have their own profiling entry
  • continue carrying children without a profiling entry through their changed parent
  • avoid registering a child separately when a changed ancestor already carries its replacement code

Problem

GCC split snd_timer_interrupt() into an unchanged wrapper and a changed
snd_timer_interrupt.part.0. The child had its own __fentry__, so
kpatch_compare_sections() correctly avoided promoting the unchanged parent.

Later, kpatch_create_patches_sections() unconditionally skipped every symbol
with sym->parent. The resulting livepatch module contained the changed child
text and its KLP relocations, but no .kpatch.funcs registration record. The
module loaded successfully while the changed execution path remained unpatched.

Validation

  • make -C kpatch-build -j4 (with -Werror): pass
  • make -C test/unit ARCHES=x86_64: pass
  • full EL9 exact-kernel build for 5.14.0-687.48.1.el9_8.x86_64: pass
  • module metadata increased from 26 to 27 function records and included snd_timer_interrupt.part.0
  • privileged runtime load: enabled=1, transition=0
  • livepatch sysfs registered both snd_timer_interrupt.part.0,1 and snd_timer_close_locked,1

The 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

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>
@joe-lawrence

Copy link
Copy Markdown
Contributor

/packit test

@kazuru-chidumbwe

Copy link
Copy Markdown

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 synchronize_rcu() call added to padata_free_shell()). GCC splits padata_free_shell into a 20-byte wrapper and padata_free_shell.part.0, which has its own __fentry__. The fix changes only the .part.0 body. The module contains the fixed padata_free_shell.part.0, but its .kpatch.funcs names neither padata_free_shell nor padata_free_shell.part.0. On a running kernel the module loads, enabled is 1, the transition completes, and calls still enter the original padata_free_shell.part.0. The earlier cumulative hotpatches ACC-1-3 to ACC-1-5 omit the clone in the same way. create-diff-object at e0a8f7c on the same objects reports the clone CHANGED and the wrapper SAME, and writes no entry for either. openEuler has since released a corrected hotpatch, ACC-1-7, announced in advisory openEuler-HotPatchSA-2026-1000 (https://www.openeuler.org/en/security/security-bulletins/detail/?id=openEuler-HotPatchSA-2026-1000).

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 .part clone that has its own ftrace entry while the parent in the same object stays unchanged.

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 .init.text function). All nine leave the changed clone out of .kpatch.funcs. We list six of them below. The other three are for a fix whose shipped livepatch is still under coordinated disclosure with another vendor, so we leave them out for now. In five of the six the clone is the only change, so the table is empty (.part.N is the compiler's clone of that function on each kernel):

kernel CVE clone left out other entries
6.1.119 CVE-2026-89983 i2c_del_adapter.part.N none
6.1.119 CVE-2026-90054 __tcp_retransmit_skb.part.N none
6.6.47 CVE-2026-90054 __tcp_retransmit_skb.part.N none
6.12.51 CVE-2026-68200 snd_timer_interrupt.part.N none
6.12.51 CVE-2026-89983 i2c_del_adapter.part.N none
6.12.51 CVE-2026-52990 fsnotify_recalc_mask.part.N __fsnotify_recalc_mask, fsnotify_put_mark

The 6.12 CVE-2026-68200 row is the same snd_timer_interrupt clone as in #1525. Each of the nine modules loaded on its kernel under KVM, reported enabled, completed its transition, and /sys/kernel/livepatch lists no clone. No build printed a warning. For comparison, klp-build on 6.19 patches the clone directly in all three such fixes on that kernel.

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 -fno-partial-inlining.

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 joe-lawrence left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread kpatch-build/create-diff-object.c Outdated
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) ||

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :)

@joe-lawrence

Copy link
Copy Markdown
Contributor

@benjamindonnachie : I also created a new unit test, x86_64/part-change-sub.test based on #1525 and @kazuru-chidumbwe 's similarly excellent bug report here. (The unit test .patch copied from the CVE-2026-68200 fix for rhel-9.)

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.

Benjamin Donnachie added 2 commits December 3, 2026 15:36
…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>
@benjamindonnachie

Copy link
Copy Markdown
Author

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.

@joe-lawrence

Copy link
Copy Markdown
Contributor

/packit test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

create-diff-object can omit patchable changed child functions

3 participants