Skip to content

Commit 442381a

Browse files
committed
create-diff-object: fix Clang UBSAN diff failure by ignoring unnamed data
This fixes a diff failure when generating livepatches for objects compiled with Clang and UBSAN (Undefined Behavior Sanitizer). When UBSAN is enabled, Clang heavily utilizes `.data..L__unnamed_XX` sections to store type descriptors and source location metadata. kpatch-build currently fails to handle these sections, resulting in errors like: fsnotify.o: changed section .data..L__unnamed_1 not selected for inclusion ERROR: fsnotify.o: 1 unsupported section change(s) create-diff-object: unreconcilable difference The numeric suffix (e.g., `_1`) in these section names is an unstable internal counter. If the patch modifies the code, these indices often shift, causing `create-diff-object` to incorrectly correlate unrelated UBSAN metadata between the original and patched objects. Since kpatch cannot support changes to existing data sections, the build aborts. Fix this by treating `.data..L__unnamed_` sections as unstable and uncorrelatable. This patch introduces `is_clang_unnamed_data()` to: 1. Explicitly skip these sections in `kpatch_correlate_sections()`. 2. Prevent `kpatch_correlate_static_local_variables()` from forcing correlation based on symbol usage. This ensures that UBSAN metadata sections are always marked as 'NEW' and allocated safely in the patch module, enabling support for livepatching UBSAN-instrumented kernels. Signed-off-by: Florent Revest <[email protected]>
1 parent 9f72959 commit 442381a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

kpatch-build/create-diff-object.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,17 @@ static bool is_string_literal_section(struct section *sec)
396396
return !strncmp(sec->name, ".rodata.", 8) && strstr(sec->name, ".str");
397397
}
398398

399+
/*
400+
* Clang generates .data..L__unnamed_XX sections for anonymous constants.
401+
* The numeric suffix is unstable (it can change if code is added/removed).
402+
* Therefore, we must never correlate these by name; the patched object
403+
* must always allocate a fresh copy (Status: NEW).
404+
*/
405+
static bool is_clang_unnamed_data(const char *name)
406+
{
407+
return !strncmp(name, ".data..L__unnamed_", 18);
408+
}
409+
399410
/*
400411
* This function detects whether the given symbol is a "special" static local
401412
* variable (for lack of a better term).
@@ -425,6 +436,10 @@ static bool is_special_static(struct symbol *sym)
425436
if (is_dynamic_debug_symbol(sym))
426437
return true;
427438

439+
/* Do not try to correlate statics inside unstable Clang sections */
440+
if (sym->sec && is_clang_unnamed_data(sym->sec->name))
441+
return true;
442+
428443
if (sym->type == STT_SECTION) {
429444
/* make sure section is bundled */
430445
if (!sym->sec->sym)
@@ -1142,6 +1157,11 @@ static void kpatch_correlate_sections(struct list_head *seclist_orig,
11421157
if (is_ubsan_sec(sec_orig->name))
11431158
continue;
11441159

1160+
/* Skip correlation for unstable Clang anonymous sections */
1161+
if (is_clang_unnamed_data(sec_orig->name) ||
1162+
is_clang_unnamed_data(sec_patched->name))
1163+
continue;
1164+
11451165
if (is_special_static(is_rela_section(sec_orig) ?
11461166
sec_orig->base->secsym :
11471167
sec_orig->secsym))

0 commit comments

Comments
 (0)