* [Devel] [PATCH hci-8.2 01/17] ms/objtool/klp: Fix detection of corrupt static branch/call entries
2026-11-24 5:00 [Devel] [PATCH hci-8.2 00/17] ms/objtool: fix silently wrong livepatches by klp-build Eva Kurchatova
@ 2026-11-24 5:00 ` Eva Kurchatova
2026-11-24 5:11 ` no-reply
2026-11-24 5:00 ` [Devel] [PATCH hci-8.2 02/17] ms/objtool/klp: Disable unsupported pr_debug() usage Eva Kurchatova
` (16 subsequent siblings)
17 siblings, 1 reply; 32+ messages in thread
From: Eva Kurchatova @ 2026-11-24 5:00 UTC (permalink / raw)
To: khorenko, vladimir.riabchun; +Cc: devel
From: Josh Poimboeuf <jpoimboe@kernel.org>
Patching a function which references a static key living in a kernel
module is unsupported due to ordering issues inherent to late module
patching:
1) Load a livepatch module which has a __jump_table entry which needs
a klp reloc to reference static key K which lives in module M.
2) The __jump_table klp reloc does *not* get resolved because module M
is not yet loaded.
3) jump_label_add_module() corrupts memory (or causes a panic) when
dereferencing the uninitialized pointer to key K.
validate_special_section_klp_reloc() intends to prevent that from ever
happening by catching it at build time. However, it incorrectly assumes
the special section entry's reloc symbol references have already been
converted from section symbols to object symbols, causing the validation
to miss corruption in extracted static branch/call table entries.
Make sure the references have been properly converted before doing the
validation.
Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffing object files")
Reported-by: Song Liu <song@kernel.org>
Reviewed-and-tested-by: Song Liu <song@kernel.org>
Link: https://patch.msgid.link/124ad747b751df0df1725eff89de8332e3fb26d6.1770759954.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
(cherry picked from commit f9fb44b0ecefc1f218db56661ed66d4e8d67317d)
https://virtuozzo.atlassian.net/browse/VSTOR-128510
Feature: klp-build support
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
tools/objtool/klp-diff.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index 4d1f9e9977eb..2db34b86e655 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -1335,6 +1335,9 @@ static int validate_special_section_klp_reloc(struct elfs *e, struct symbol *sym
const char *sym_modname;
struct export *export;
+ if (convert_reloc_sym(e->patched, reloc))
+ continue;
+
/* Static branch/call keys are always STT_OBJECT */
if (reloc->sym->type != STT_OBJECT) {
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 32+ messages in thread* [Devel] [PATCH hci-8.2 02/17] ms/objtool/klp: Disable unsupported pr_debug() usage
2026-11-24 5:00 [Devel] [PATCH hci-8.2 00/17] ms/objtool: fix silently wrong livepatches by klp-build Eva Kurchatova
2026-11-24 5:00 ` [Devel] [PATCH hci-8.2 01/17] ms/objtool/klp: Fix detection of corrupt static branch/call entries Eva Kurchatova
@ 2026-11-24 5:00 ` Eva Kurchatova
2026-11-24 5:10 ` no-reply
2026-11-24 5:00 ` [Devel] [PATCH hci-8.2 03/17] ms/objtool: Fix data alignment in elf_add_data() Eva Kurchatova
` (15 subsequent siblings)
17 siblings, 1 reply; 32+ messages in thread
From: Eva Kurchatova @ 2026-11-24 5:00 UTC (permalink / raw)
To: khorenko, vladimir.riabchun; +Cc: devel
From: Josh Poimboeuf <jpoimboe@kernel.org>
Instead of erroring out on unsupported pr_debug() (e.g., when patching a
module), issue a warning and make it inert, similar to how unsupported
tracepoints are currently handled.
Reviewed-and-tested-by: Song Liu <song@kernel.org>
Link: https://patch.msgid.link/3a7db3a5b7d4abf9b2534803a74e2e7231322738.1770759954.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
(cherry picked from commit e476bb277cf91b7ac3ea803ec78a4f0791bddec3)
https://virtuozzo.atlassian.net/browse/VSTOR-128510
Feature: klp-build support
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
tools/objtool/klp-diff.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index 2db34b86e655..13319ee9d56e 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -1305,18 +1305,18 @@ static bool should_keep_special_sym(struct elf *elf, struct symbol *sym)
* be applied after static branch/call init, resulting in code corruption.
*
* Validate a special section entry to avoid that. Note that an inert
- * tracepoint is harmless enough, in that case just skip the entry and print a
- * warning. Otherwise, return an error.
+ * tracepoint or pr_debug() is harmless enough, in that case just skip the
+ * entry and print a warning. Otherwise, return an error.
*
- * This is only a temporary limitation which will be fixed when livepatch adds
- * support for submodules: fully self-contained modules which are embedded in
- * the top-level livepatch module's data and which can be loaded on demand when
- * their corresponding to-be-patched module gets loaded. Then klp relocs can
- * be retired.
+ * TODO: This is only a temporary limitation which will be fixed when livepatch
+ * adds support for submodules: fully self-contained modules which are embedded
+ * in the top-level livepatch module's data and which can be loaded on demand
+ * when their corresponding to-be-patched module gets loaded. Then klp relocs
+ * can be retired.
*
* Return:
* -1: error: validation failed
- * 1: warning: tracepoint skipped
+ * 1: warning: disabled tracepoint or pr_debug()
* 0: success
*/
static int validate_special_section_klp_reloc(struct elfs *e, struct symbol *sym)
@@ -1374,6 +1374,13 @@ static int validate_special_section_klp_reloc(struct elfs *e, struct symbol *sym
continue;
}
+ if (strstr(reloc->sym->name, "__UNIQUE_ID_ddebug_")) {
+ WARN("%s: disabling unsupported pr_debug()",
+ code_sym->name);
+ ret = 1;
+ continue;
+ }
+
ERROR("%s+0x%lx: unsupported static branch key %s. Use static_key_enabled() instead",
code_sym->name, code_offset, reloc->sym->name);
return -1;
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 32+ messages in thread* [Devel] [PATCH hci-8.2 03/17] ms/objtool: Fix data alignment in elf_add_data()
2026-11-24 5:00 [Devel] [PATCH hci-8.2 00/17] ms/objtool: fix silently wrong livepatches by klp-build Eva Kurchatova
2026-11-24 5:00 ` [Devel] [PATCH hci-8.2 01/17] ms/objtool/klp: Fix detection of corrupt static branch/call entries Eva Kurchatova
2026-11-24 5:00 ` [Devel] [PATCH hci-8.2 02/17] ms/objtool/klp: Disable unsupported pr_debug() usage Eva Kurchatova
@ 2026-11-24 5:00 ` Eva Kurchatova
2026-11-24 5:11 ` no-reply
2026-11-24 5:00 ` [Devel] [PATCH hci-8.2 04/17] ms/objtool/klp: fix data alignment in __clone_symbol() Eva Kurchatova
` (14 subsequent siblings)
17 siblings, 1 reply; 32+ messages in thread
From: Eva Kurchatova @ 2026-11-24 5:00 UTC (permalink / raw)
To: khorenko, vladimir.riabchun; +Cc: devel
From: Josh Poimboeuf <jpoimboe@kernel.org>
Any data added to a section needs to be aligned in accordance with the
section's sh_addralign value. Particularly strings added to a .str1.8
section. Otherwise you may get some funky strings.
Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffing object files")
Link: https://patch.msgid.link/d962fc0ca24fa0825cca8dad71932dccdd9312a9.1772681234.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
(cherry picked from commit 356e4b2f5b80f757965f3f4d0219c81fca91b6f2)
https://virtuozzo.atlassian.net/browse/VSTOR-128510
Feature: klp-build support
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
tools/objtool/elf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index bc1ca8e439c9..da20cec49374 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -1351,7 +1351,7 @@ void *elf_add_data(struct elf *elf, struct section *sec, const void *data, size_
memcpy(sec->data->d_buf, data, size);
sec->data->d_size = size;
- sec->data->d_align = 1;
+ sec->data->d_align = sec->sh.sh_addralign;
offset = ALIGN_UP(sec->sh.sh_size, sec->sh.sh_addralign);
sec->sh.sh_size = offset + size;
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 32+ messages in thread* [Devel] [PATCH hci-8.2 04/17] ms/objtool/klp: fix data alignment in __clone_symbol()
2026-11-24 5:00 [Devel] [PATCH hci-8.2 00/17] ms/objtool: fix silently wrong livepatches by klp-build Eva Kurchatova
` (2 preceding siblings ...)
2026-11-24 5:00 ` [Devel] [PATCH hci-8.2 03/17] ms/objtool: Fix data alignment in elf_add_data() Eva Kurchatova
@ 2026-11-24 5:00 ` Eva Kurchatova
2026-11-24 5:11 ` no-reply
2026-11-24 5:00 ` [Devel] [PATCH hci-8.2 05/17] ms/objtool/klp: Fix .data..once static local non-correlation Eva Kurchatova
` (13 subsequent siblings)
17 siblings, 1 reply; 32+ messages in thread
From: Eva Kurchatova @ 2026-11-24 5:00 UTC (permalink / raw)
To: khorenko, vladimir.riabchun; +Cc: devel
From: Joe Lawrence <joe.lawrence@redhat.com>
Commit 356e4b2f5b80 ("objtool: Fix data alignment in elf_add_data()")
corrected the alignment of data within a section (honoring the section's
sh_addralign). Apply the same alignment when klp-diff mode clones a
symbol, adjusting the new symbol's offset for the output section's
sh_addralign.
Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffing object files")
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
Link: https://patch.msgid.link/20260310203751.1479229-2-joe.lawrence@redhat.com
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
(cherry picked from commit 2f2600decb3004938762a3f2d0eba3ea9e01045b)
https://virtuozzo.atlassian.net/browse/VSTOR-128510
Feature: klp-build support
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
tools/objtool/klp-diff.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index 13319ee9d56e..e0c64690c1e0 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -14,6 +14,7 @@
#include <objtool/util.h>
#include <arch/special.h>
+#include <linux/align.h>
#include <linux/objtool_types.h>
#include <linux/livepatch_external.h>
#include <linux/stringify.h>
@@ -531,7 +532,7 @@ static struct symbol *__clone_symbol(struct elf *elf, struct symbol *patched_sym
}
if (!is_sec_sym(patched_sym))
- offset = sec_size(out_sec);
+ offset = ALIGN(sec_size(out_sec), out_sec->sh.sh_addralign);
if (patched_sym->len || is_sec_sym(patched_sym)) {
void *data = NULL;
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 32+ messages in thread* [Devel] [PATCH hci-8.2 05/17] ms/objtool/klp: Fix .data..once static local non-correlation
2026-11-24 5:00 [Devel] [PATCH hci-8.2 00/17] ms/objtool: fix silently wrong livepatches by klp-build Eva Kurchatova
` (3 preceding siblings ...)
2026-11-24 5:00 ` [Devel] [PATCH hci-8.2 04/17] ms/objtool/klp: fix data alignment in __clone_symbol() Eva Kurchatova
@ 2026-11-24 5:00 ` Eva Kurchatova
2026-11-24 5:11 ` no-reply
2026-11-24 5:00 ` [Devel] [PATCH hci-8.2 06/17] ms/objtool/klp: Fix create_fake_symbols() skipping entsize-based sections Eva Kurchatova
` (12 subsequent siblings)
17 siblings, 1 reply; 32+ messages in thread
From: Eva Kurchatova @ 2026-11-24 5:00 UTC (permalink / raw)
To: khorenko, vladimir.riabchun; +Cc: devel
From: Josh Poimboeuf <jpoimboe@kernel.org>
While there was once a section named .data.once, it has since been
renamed to .data..once with commit dbefa1f31a91 ("Rename .data.once to
.data..once to fix resetting WARN*_ONCE"). Fix it.
Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffing object files")
Acked-by: Song Liu <song@kernel.org>
Reviewed-by: Miroslav Benes <mbenes@suse.cz>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
(cherry picked from commit ff529864e738f447ff4c019956319930fc274a23)
https://virtuozzo.atlassian.net/browse/VSTOR-128510
Feature: klp-build support
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
tools/objtool/klp-diff.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index e0c64690c1e0..0f9ce6541e93 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -256,7 +256,8 @@ static bool is_uncorrelated_static_local(struct symbol *sym)
if (!is_object_sym(sym) || !is_local_sym(sym))
return false;
- if (!strcmp(sym->sec->name, ".data.once"))
+ /* WARN_ONCE, etc */
+ if (!strcmp(sym->sec->name, ".data..once"))
return true;
for (int i = 0; i < ARRAY_SIZE(vars); i++) {
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 32+ messages in thread* [Devel] [PATCH hci-8.2 06/17] ms/objtool/klp: Fix create_fake_symbols() skipping entsize-based sections
2026-11-24 5:00 [Devel] [PATCH hci-8.2 00/17] ms/objtool: fix silently wrong livepatches by klp-build Eva Kurchatova
` (4 preceding siblings ...)
2026-11-24 5:00 ` [Devel] [PATCH hci-8.2 05/17] ms/objtool/klp: Fix .data..once static local non-correlation Eva Kurchatova
@ 2026-11-24 5:00 ` Eva Kurchatova
2026-11-24 5:11 ` no-reply
2026-11-24 5:00 ` [Devel] [PATCH hci-8.2 07/17] ms/objtool/klp: Fix handling of zero-length .altinstr_replacement sections Eva Kurchatova
` (11 subsequent siblings)
17 siblings, 1 reply; 32+ messages in thread
From: Eva Kurchatova @ 2026-11-24 5:00 UTC (permalink / raw)
To: khorenko, vladimir.riabchun; +Cc: devel
From: Joe Lawrence <joe.lawrence@redhat.com>
create_fake_symbols() has two phases: creating symbols from
ANNOTATE_DATA_SPECIAL entries, and a fallback that uses sh_entsize for
special sections like .static_call_sites.
When .discard.annotate_data is absent, the function returns early,
skipping the entsize fallback and silently allowing unsupported
module-local static call keys through.
Fix it by jumping to the entsize phase instead of returning early.
Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffing object files")
Assisted-by: Claude:claude-4-opus
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
Acked-by: Song Liu <song@kernel.org>
Reviewed-by: Miroslav Benes <mbenes@suse.cz>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
(cherry picked from commit 3de711fba73ad93b8b3fbe09cf681cefed5d573d)
https://virtuozzo.atlassian.net/browse/VSTOR-128510
Feature: klp-build support
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
tools/objtool/klp-diff.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index 0f9ce6541e93..9dd2224f45aa 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -1219,7 +1219,7 @@ static int create_fake_symbols(struct elf *elf)
sec = find_section_by_name(elf, ".discard.annotate_data");
if (!sec || !sec->rsec)
- return 0;
+ goto entsize;
for_each_reloc(sec->rsec, reloc) {
unsigned long offset, size;
@@ -1251,7 +1251,7 @@ static int create_fake_symbols(struct elf *elf)
/*
* 2) Make symbols for sh_entsize, and simple arrays of pointers:
*/
-
+entsize:
for_each_sec(elf, sec) {
unsigned int entry_size;
unsigned long offset;
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 32+ messages in thread* [Devel] [PATCH hci-8.2 07/17] ms/objtool/klp: Fix handling of zero-length .altinstr_replacement sections
2026-11-24 5:00 [Devel] [PATCH hci-8.2 00/17] ms/objtool: fix silently wrong livepatches by klp-build Eva Kurchatova
` (5 preceding siblings ...)
2026-11-24 5:00 ` [Devel] [PATCH hci-8.2 06/17] ms/objtool/klp: Fix create_fake_symbols() skipping entsize-based sections Eva Kurchatova
@ 2026-11-24 5:00 ` Eva Kurchatova
2026-11-24 5:12 ` no-reply
2026-11-24 5:00 ` [Devel] [PATCH hci-8.2 08/17] ms/objtool/klp: Fix cloning of zero-length section symbols Eva Kurchatova
` (10 subsequent siblings)
17 siblings, 1 reply; 32+ messages in thread
From: Eva Kurchatova @ 2026-11-24 5:00 UTC (permalink / raw)
To: khorenko, vladimir.riabchun; +Cc: devel
From: Josh Poimboeuf <jpoimboe@kernel.org>
When a section is empty (e.g. only zero-length alternative
replacements), there are no symbols to convert a section symbol
reference to. Skip the reloc instead of erroring out.
Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffing object files")
Acked-by: Song Liu <song@kernel.org>
Reviewed-by: Miroslav Benes <mbenes@suse.cz>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
(cherry picked from commit c4c02d4450b5b7e2fbde578252f71a5697180112)
https://virtuozzo.atlassian.net/browse/VSTOR-128510
Feature: klp-build support
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
tools/objtool/klp-diff.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index 9dd2224f45aa..5e39839759bb 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -864,6 +864,13 @@ static int convert_reloc_secsym_to_sym(struct elf *elf, struct reloc *reloc)
/* No dedicated section; find the symbol manually */
sym = find_symbol_containing(sec, arch_adjusted_addend(reloc));
if (!sym) {
+ /*
+ * This is presumably an .altinstr_replacement section which is
+ * empty due to it only having zero-length replacement(s).
+ */
+ if (!sec_size(sec))
+ return 1;
+
/*
* This can happen for special section references to weak code
* whose symbol has been stripped by the linker.
@@ -1124,6 +1131,7 @@ static int clone_sym_relocs(struct elfs *e, struct symbol *patched_sym)
for_each_reloc(patched_rsec, patched_reloc) {
unsigned long offset;
+ int ret;
if (reloc_offset(patched_reloc) < start ||
reloc_offset(patched_reloc) >= end)
@@ -1137,12 +1145,15 @@ static int clone_sym_relocs(struct elfs *e, struct symbol *patched_sym)
!strcmp(patched_reloc->sym->sec->name, ".altinstr_aux"))
continue;
- if (convert_reloc_sym(e->patched, patched_reloc)) {
+ ret = convert_reloc_sym(e->patched, patched_reloc);
+ if (ret < 0) {
ERROR_FUNC(patched_rsec->base, reloc_offset(patched_reloc),
"failed to convert reloc sym '%s' to its proper format",
patched_reloc->sym->name);
return -1;
}
+ if (ret > 0)
+ continue;
offset = out_sym->offset + (reloc_offset(patched_reloc) - patched_sym->offset);
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 32+ messages in thread* [Devel] [PATCH hci-8.2 08/17] ms/objtool/klp: Fix cloning of zero-length section symbols
2026-11-24 5:00 [Devel] [PATCH hci-8.2 00/17] ms/objtool: fix silently wrong livepatches by klp-build Eva Kurchatova
` (6 preceding siblings ...)
2026-11-24 5:00 ` [Devel] [PATCH hci-8.2 07/17] ms/objtool/klp: Fix handling of zero-length .altinstr_replacement sections Eva Kurchatova
@ 2026-11-24 5:00 ` Eva Kurchatova
2026-11-24 5:12 ` no-reply
2026-11-24 5:00 ` [Devel] [PATCH hci-8.2 09/17] ms/objtool/klp: Fix relocation conversion failures for R_X86_64_NONE Eva Kurchatova
` (9 subsequent siblings)
17 siblings, 1 reply; 32+ messages in thread
From: Eva Kurchatova @ 2026-11-24 5:00 UTC (permalink / raw)
To: khorenko, vladimir.riabchun; +Cc: devel
From: Josh Poimboeuf <jpoimboe@kernel.org>
Fix NULL dereference when cloning a symbol from an empty section.
sec->data is only populated for sections with non-zero size.
Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffing object files")
Acked-by: Song Liu <song@kernel.org>
Reviewed-by: Miroslav Benes <mbenes@suse.cz>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
(cherry picked from commit 98377f3ba7c02d6eb34e203c9f9823bc62b0d231)
https://virtuozzo.atlassian.net/browse/VSTOR-128510
Feature: klp-build support
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
tools/objtool/klp-diff.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index 5e39839759bb..817db8540c8b 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -540,7 +540,7 @@ static struct symbol *__clone_symbol(struct elf *elf, struct symbol *patched_sym
size_t size;
/* bss doesn't have data */
- if (patched_sym->sec->data->d_buf)
+ if (patched_sym->sec->data && patched_sym->sec->data->d_buf)
data = patched_sym->sec->data->d_buf + patched_sym->offset;
if (is_sec_sym(patched_sym))
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 32+ messages in thread* [Devel] [PATCH hci-8.2 09/17] ms/objtool/klp: Fix relocation conversion failures for R_X86_64_NONE
2026-11-24 5:00 [Devel] [PATCH hci-8.2 00/17] ms/objtool: fix silently wrong livepatches by klp-build Eva Kurchatova
` (7 preceding siblings ...)
2026-11-24 5:00 ` [Devel] [PATCH hci-8.2 08/17] ms/objtool/klp: Fix cloning of zero-length section symbols Eva Kurchatova
@ 2026-11-24 5:00 ` Eva Kurchatova
2026-11-24 5:12 ` no-reply
2026-11-24 5:00 ` [Devel] [PATCH hci-8.2 10/17] ms/objtool/klp: Fix reloc corruption in convert_reloc_sym_to_secsym() Eva Kurchatova
` (8 subsequent siblings)
17 siblings, 1 reply; 32+ messages in thread
From: Eva Kurchatova @ 2026-11-24 5:00 UTC (permalink / raw)
To: khorenko, vladimir.riabchun; +Cc: devel
From: Josh Poimboeuf <jpoimboe@kernel.org>
Objtool has some hacks which NOP out certain calls/jumps and replace
their relocations with R_X86_64_NONE. The klp-diff relocation
extraction code will error out when trying to copy these relocations due
to their negative addend, which would only makes sense for a PC-relative
branch instruction. Just ignore them.
Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffing object files")
Acked-by: Song Liu <song@kernel.org>
Reviewed-by: Miroslav Benes <mbenes@suse.cz>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
(cherry picked from commit 3787e82a4e3a0a04aeb5543580ee90bed3a36e55)
https://virtuozzo.atlassian.net/browse/VSTOR-128510
Feature: klp-build support
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
tools/objtool/klp-diff.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index 817db8540c8b..941be5829ce7 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -891,6 +891,9 @@ static int convert_reloc_secsym_to_sym(struct elf *elf, struct reloc *reloc)
*/
static int convert_reloc_sym(struct elf *elf, struct reloc *reloc)
{
+ if (reloc_type(reloc) == R_NONE)
+ return 1;
+
if (is_reloc_allowed(reloc))
return 0;
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 32+ messages in thread* [Devel] [PATCH hci-8.2 10/17] ms/objtool/klp: Fix reloc corruption in convert_reloc_sym_to_secsym()
2026-11-24 5:00 [Devel] [PATCH hci-8.2 00/17] ms/objtool: fix silently wrong livepatches by klp-build Eva Kurchatova
` (8 preceding siblings ...)
2026-11-24 5:00 ` [Devel] [PATCH hci-8.2 09/17] ms/objtool/klp: Fix relocation conversion failures for R_X86_64_NONE Eva Kurchatova
@ 2026-11-24 5:00 ` Eva Kurchatova
2026-11-24 5:12 ` no-reply
2026-11-24 5:01 ` [Devel] [PATCH hci-8.2 11/17] ms/objtool/klp: Simplify reloc symbol conversion Eva Kurchatova
` (7 subsequent siblings)
17 siblings, 1 reply; 32+ messages in thread
From: Eva Kurchatova @ 2026-11-24 5:00 UTC (permalink / raw)
To: khorenko, vladimir.riabchun; +Cc: devel
From: Josh Poimboeuf <jpoimboe@kernel.org>
Use the section symbol's index instead of the old symbol's index when
updating the ELF relocation entry in convert_reloc_sym_to_secsym().
Found by Sashiko review.
Acked-by: Song Liu <song@kernel.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
(cherry picked from commit 5f49ec82b9f65507c262a6e3f1b53663f79eedce)
https://virtuozzo.atlassian.net/browse/VSTOR-128510
Feature: klp-build support
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
tools/objtool/klp-diff.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index 941be5829ce7..fa7a5c857b73 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -846,7 +846,7 @@ static int convert_reloc_sym_to_secsym(struct elf *elf, struct reloc *reloc)
return -1;
reloc->sym = sec->sym;
- set_reloc_sym(elf, reloc, sym->idx);
+ set_reloc_sym(elf, reloc, sec->sym->idx);
set_reloc_addend(elf, reloc, sym->offset + reloc_addend(reloc));
return 0;
}
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 32+ messages in thread* [Devel] [PATCH hci-8.2 11/17] ms/objtool/klp: Simplify reloc symbol conversion
2026-11-24 5:00 [Devel] [PATCH hci-8.2 00/17] ms/objtool: fix silently wrong livepatches by klp-build Eva Kurchatova
` (9 preceding siblings ...)
2026-11-24 5:00 ` [Devel] [PATCH hci-8.2 10/17] ms/objtool/klp: Fix reloc corruption in convert_reloc_sym_to_secsym() Eva Kurchatova
@ 2026-11-24 5:01 ` Eva Kurchatova
2026-11-24 5:13 ` no-reply
2026-11-24 5:01 ` [Devel] [PATCH hci-8.2 12/17] ms/objtool: Move mark_rodata() to elf.c Eva Kurchatova
` (6 subsequent siblings)
17 siblings, 1 reply; 32+ messages in thread
From: Eva Kurchatova @ 2026-11-24 5:01 UTC (permalink / raw)
To: khorenko, vladimir.riabchun; +Cc: devel
From: Josh Poimboeuf <jpoimboe@kernel.org>
Inline section_reference_needed() and is_reloc_allowed() into
convert_reloc_sym() and remove the redundant is_reloc_allowed() check in
clone_reloc().
Move the is_sec_sym() checks into the convert callees so they become
no-ops when the reloc is already in the right format. This allows
convert_reloc_sym() to unconditionally dispatch to the right converter
based on section type.
Acked-by: Song Liu <song@kernel.org>
Reviewed-by: Miroslav Benes <mbenes@suse.cz>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
(cherry picked from commit 8fdc3585b3b09f2c55d8573edc6a1dbfeb728f03)
https://virtuozzo.atlassian.net/browse/VSTOR-128510
Feature: klp-build support
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
tools/objtool/klp-diff.c | 76 +++++++++++++++-------------------------
1 file changed, 28 insertions(+), 48 deletions(-)
diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index fa7a5c857b73..55208c6edfc6 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -696,39 +696,6 @@ static int clone_included_functions(struct elfs *e)
return 0;
}
-/*
- * Determine whether a relocation should reference the section rather than the
- * underlying symbol.
- */
-static bool section_reference_needed(struct section *sec)
-{
- /*
- * String symbols are zero-length and uncorrelated. It's easier to
- * deal with them as section symbols.
- */
- if (is_string_sec(sec))
- return true;
-
- /*
- * .rodata has mostly anonymous data so there's no way to determine the
- * length of a needed reference. just copy the whole section if needed.
- */
- if (strstarts(sec->name, ".rodata"))
- return true;
-
- /* UBSAN anonymous data */
- if (strstarts(sec->name, ".data..Lubsan") || /* GCC */
- strstarts(sec->name, ".data..L__unnamed_")) /* Clang */
- return true;
-
- return false;
-}
-
-static bool is_reloc_allowed(struct reloc *reloc)
-{
- return section_reference_needed(reloc->sym->sec) == is_sec_sym(reloc->sym);
-}
-
static struct export *find_export(struct symbol *sym)
{
struct export *export;
@@ -837,11 +804,15 @@ static bool klp_reloc_needed(struct reloc *patched_reloc)
return true;
}
+/* Return -1 error, 0 success, 1 skip */
static int convert_reloc_sym_to_secsym(struct elf *elf, struct reloc *reloc)
{
struct symbol *sym = reloc->sym;
struct section *sec = sym->sec;
+ if (is_sec_sym(sym))
+ return 0;
+
if (!sec->sym && !elf_create_section_symbol(elf, sec))
return -1;
@@ -851,11 +822,15 @@ static int convert_reloc_sym_to_secsym(struct elf *elf, struct reloc *reloc)
return 0;
}
+/* Return -1 error, 0 success, 1 skip */
static int convert_reloc_secsym_to_sym(struct elf *elf, struct reloc *reloc)
{
struct symbol *sym = reloc->sym;
struct section *sec = sym->sec;
+ if (!is_sec_sym(sym))
+ return 0;
+
/* If the symbol has a dedicated section, it's easy to find */
sym = find_symbol_by_offset(sec, 0);
if (sym && sym->len == sec_size(sec))
@@ -885,22 +860,34 @@ static int convert_reloc_secsym_to_sym(struct elf *elf, struct reloc *reloc)
return 0;
}
+/*
+ * Sections with anonymous or uncorrelated data (strings, UBSAN data)
+ * need section symbol references.
+ */
+static bool is_uncorrelated_section(struct section *sec)
+{
+ return is_string_sec(sec) ||
+ strstarts(sec->name, ".rodata") ||
+ strstarts(sec->name, ".data..Lubsan") || /* GCC */
+ strstarts(sec->name, ".data..L__unnamed_"); /* Clang */
+}
+
/*
* Convert a relocation symbol reference to the needed format: either a section
- * symbol or the underlying symbol itself.
+ * symbol or the underlying symbol itself. Return -1 error, 0 success, 1 skip.
*/
static int convert_reloc_sym(struct elf *elf, struct reloc *reloc)
{
+ struct section *sec = reloc->sym->sec;
+
if (reloc_type(reloc) == R_NONE)
return 1;
- if (is_reloc_allowed(reloc))
- return 0;
-
- if (section_reference_needed(reloc->sym->sec))
+ if (is_uncorrelated_section(sec))
return convert_reloc_sym_to_secsym(elf, reloc);
- else
- return convert_reloc_secsym_to_sym(elf, reloc);
+
+ /* Everything else: references should use named symbols. */
+ return convert_reloc_secsym_to_sym(elf, reloc);
}
/*
@@ -1045,13 +1032,6 @@ static int clone_reloc(struct elfs *e, struct reloc *patched_reloc,
struct symbol *out_sym;
bool klp;
- if (!is_reloc_allowed(patched_reloc)) {
- ERROR_FUNC(patched_reloc->sec->base, reloc_offset(patched_reloc),
- "missing symbol for reference to %s+%ld",
- patched_sym->name, addend);
- return -1;
- }
-
klp = klp_reloc_needed(patched_reloc);
dbg_clone_reloc(sec, offset, patched_sym, addend, export, klp);
@@ -1081,7 +1061,7 @@ static int clone_reloc(struct elfs *e, struct reloc *patched_reloc,
/*
* For strings, all references use section symbols, thanks to
- * section_reference_needed(). clone_symbol() has cloned an empty
+ * convert_reloc_sym(). clone_symbol() has cloned an empty
* version of the string section. Now copy the string itself.
*/
if (is_string_sec(patched_sym->sec)) {
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 32+ messages in thread* [Devel] [PATCH hci-8.2 12/17] ms/objtool: Move mark_rodata() to elf.c
2026-11-24 5:00 [Devel] [PATCH hci-8.2 00/17] ms/objtool: fix silently wrong livepatches by klp-build Eva Kurchatova
` (10 preceding siblings ...)
2026-11-24 5:01 ` [Devel] [PATCH hci-8.2 11/17] ms/objtool/klp: Simplify reloc symbol conversion Eva Kurchatova
@ 2026-11-24 5:01 ` Eva Kurchatova
2026-11-24 5:13 ` no-reply
2026-11-24 5:01 ` [Devel] [PATCH hci-8.2 13/17] ms/objtool/klp: Fix pointer comparisons for rodata objects Eva Kurchatova
` (5 subsequent siblings)
17 siblings, 1 reply; 32+ messages in thread
From: Eva Kurchatova @ 2026-11-24 5:01 UTC (permalink / raw)
To: khorenko, vladimir.riabchun; +Cc: devel
From: Josh Poimboeuf <jpoimboe@kernel.org>
Move the sec->rodata marking from check.c to elf.c so it's set during
ELF reading rather than during the check pipeline. This makes the
rodata flag available to all objtool users, including klp-diff which
reads ELF files directly without running check().
Add an is_rodata_sec() helper to elf.h for consistency with
is_text_sec() and is_string_sec().
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Song Liu <song@kernel.org>
Reviewed-by: Miroslav Benes <mbenes@suse.cz>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
(cherry picked from commit 3e01ab44af207a2d8c197653e7278083b039a274)
https://virtuozzo.atlassian.net/browse/VSTOR-128510
Feature: klp-build support
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
tools/objtool/check.c | 11 +++--------
tools/objtool/elf.c | 13 +++++++++++++
tools/objtool/include/objtool/elf.h | 5 +++++
3 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index dc24ceed3c7d..f9539dae294f 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2524,7 +2524,6 @@ static int classify_symbols(struct objtool_file *file)
static void mark_rodata(struct objtool_file *file)
{
struct section *sec;
- bool found = false;
/*
* Search for the following rodata sections, each of which can
@@ -2537,15 +2536,11 @@ static void mark_rodata(struct objtool_file *file)
* .rodata.str1.* sections are ignored; they don't contain jump tables.
*/
for_each_sec(file->elf, sec) {
- if ((!strncmp(sec->name, ".rodata", 7) &&
- !strstr(sec->name, ".str1.")) ||
- !strncmp(sec->name, ".data.rel.ro", 12)) {
- sec->rodata = true;
- found = true;
+ if (is_rodata_sec(sec)) {
+ file->rodata = true;
+ return;
}
}
-
- file->rodata = found;
}
static void mark_holes(struct objtool_file *file)
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index da20cec49374..a1cbaba7e1c1 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -1096,6 +1096,17 @@ static int read_relocs(struct elf *elf)
return 0;
}
+static void mark_rodata(struct elf *elf)
+{
+ struct section *sec;
+
+ for_each_sec(elf, sec) {
+ if ((strstarts(sec->name, ".rodata") && !strstr(sec->name, ".str1.")) ||
+ strstarts(sec->name, ".data.rel.ro"))
+ sec->rodata = true;
+ }
+}
+
struct elf *elf_open_read(const char *name, int flags)
{
struct elf *elf;
@@ -1146,6 +1157,8 @@ struct elf *elf_open_read(const char *name, int flags)
if (read_sections(elf))
goto err;
+ mark_rodata(elf);
+
if (read_symbols(elf))
goto err;
diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h
index a2b3fb97aed9..fd2afbbee903 100644
--- a/tools/objtool/include/objtool/elf.h
+++ b/tools/objtool/include/objtool/elf.h
@@ -292,6 +292,11 @@ static inline bool is_text_sec(struct section *sec)
return sec->sh.sh_flags & SHF_EXECINSTR;
}
+static inline bool is_rodata_sec(struct section *sec)
+{
+ return sec->rodata;
+}
+
static inline bool sec_changed(struct section *sec)
{
return sec->_changed;
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 32+ messages in thread* Re: [Devel] [PATCH hci-8.2 12/17] ms/objtool: Move mark_rodata() to elf.c
2026-11-24 5:01 ` [Devel] [PATCH hci-8.2 12/17] ms/objtool: Move mark_rodata() to elf.c Eva Kurchatova
@ 2026-11-24 5:13 ` no-reply
0 siblings, 0 replies; 32+ messages in thread
From: no-reply @ 2026-11-24 5:13 UTC (permalink / raw)
To: Eva Kurchatova, khorenko, vladimir.riabchun; +Cc: devel
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] objtool: rodata name-matching comment left in check.c, none in
elf.c
--
commit 5aa51a6bbc60594018d39f706683432ad65d44a3
Author: Josh Poimboeuf <jpoimboe@kernel.org>
ms/objtool: Move mark_rodata() to elf.c
The patch moves the per-section rodata marking from check.c into elf.c, so sec->rodata is set while the ELF file is read. It adds an is_rodata_sec() helper, and the check.c mark_rodata() now only sets file->rodata.
> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> index dc24ceed3c7d9..f9539dae294f9 100644
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -2524,7 +2524,6 @@ static int classify_symbols(struct objtool_file *file)
> static void mark_rodata(struct objtool_file *file)
> {
> struct section *sec;
> - bool found = false;
>
> /*
> * Search for the following rodata sections, each of which can
> @@ -2537,15 +2536,11 @@ static void mark_rodata(struct objtool_file *file)
> * .rodata.str1.* sections are ignored; they don't contain jump tables.
> */
> for_each_sec(file->elf, sec) {
> - if ((!strncmp(sec->name, ".rodata", 7) &&
> - !strstr(sec->name, ".str1.")) ||
> - !strncmp(sec->name, ".data.rel.ro", 12)) {
> - sec->rodata = true;
> - found = true;
> + if (is_rodata_sec(sec)) {
> + file->rodata = true;
> + return;
> }
> }
> -
> }
[Severity: Low]
This isn't a bug, but the block comment listing the rodata section name patterns and the .str1. exclusion now sits in a function that no longer matches any names. Should it move to the new mark_rodata() in elf.c, which holds the matching logic and has no comment? Having two static functions named mark_rodata(), in different files and doing different jobs, is also a bit confusing. Renaming the check.c one might help, for example to something that says it only records whether the file has any rodata section.
Carry the trailer below into the next revision and Sashiko will not review this patch again.
Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261124050655.1853940-1-eva.kurchatova@virtuozzo.com?part=12
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 32+ messages in thread
* [Devel] [PATCH hci-8.2 13/17] ms/objtool/klp: Fix pointer comparisons for rodata objects
2026-11-24 5:00 [Devel] [PATCH hci-8.2 00/17] ms/objtool: fix silently wrong livepatches by klp-build Eva Kurchatova
` (11 preceding siblings ...)
2026-11-24 5:01 ` [Devel] [PATCH hci-8.2 12/17] ms/objtool: Move mark_rodata() to elf.c Eva Kurchatova
@ 2026-11-24 5:01 ` Eva Kurchatova
2026-11-24 12:20 ` Konstantin Khorenko
2026-11-24 5:01 ` [Devel] [PATCH hci-8.2 14/17] ms/objtool/klp: Fix module name normalization for paths with dots Eva Kurchatova
` (4 subsequent siblings)
17 siblings, 1 reply; 32+ messages in thread
From: Eva Kurchatova @ 2026-11-24 5:01 UTC (permalink / raw)
To: khorenko, vladimir.riabchun; +Cc: devel
From: Josh Poimboeuf <jpoimboe@kernel.org>
klp-diff treats all rodata as uncorrelated, so any reference to it uses
a duplicated copy rather than using a KLP reloc.
For the contents of the data itself, a duplicated copy is fine.
However, pointer comparisons (e.g., f->f_op == &foo_ops) are broken.
Fix it by correlating non-anonymous rodata objects.
Also, use a new find_symbol_containing_inclusive() helper for matching
the end of a symbol so bounds calculations don't get broken, for the
case where an array or other symbol's ending address is used as part of
a bounds calculation.
While these are really two distinct changes, they need to be done in the
same patch so as to avoid introducing bisection regressions.
Acked-by: Song Liu <song@kernel.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
(cherry picked from commit d5b0f025281f287759820f57b7ba1bac7827b338)
https://virtuozzo.atlassian.net/browse/VSTOR-128510
Feature: klp-build support
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
tools/objtool/elf.c | 14 ++++++++++++++
tools/objtool/include/objtool/elf.h | 1 +
tools/objtool/klp-diff.c | 15 +++++++++++++--
3 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index a1cbaba7e1c1..9f1ebb643686 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -223,6 +223,20 @@ struct symbol *find_symbol_containing(const struct section *sec, unsigned long o
return sym;
}
+/*
+ * Also match the symbol end address which can be used for a bounds comparison.
+ */
+struct symbol *find_symbol_containing_inclusive(const struct section *sec,
+ unsigned long offset)
+{
+ struct symbol *sym = find_symbol_containing(sec, offset);
+
+ if (!sym && offset)
+ sym = find_symbol_containing(sec, offset - 1);
+
+ return sym;
+}
+
/*
* Returns size of hole starting at @offset.
*/
diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h
index fd2afbbee903..bc1f604fc67a 100644
--- a/tools/objtool/include/objtool/elf.h
+++ b/tools/objtool/include/objtool/elf.h
@@ -186,6 +186,7 @@ struct symbol *find_symbol_by_offset(struct section *sec, unsigned long offset);
struct symbol *find_symbol_by_name(const struct elf *elf, const char *name);
struct symbol *find_global_symbol_by_name(const struct elf *elf, const char *name);
struct symbol *find_symbol_containing(const struct section *sec, unsigned long offset);
+struct symbol *find_symbol_containing_inclusive(const struct section *sec, unsigned long offset);
int find_symbol_hole_containing(const struct section *sec, unsigned long offset);
struct reloc *find_reloc_by_dest(const struct elf *elf, struct section *sec, unsigned long offset);
struct reloc *find_reloc_by_dest_range(const struct elf *elf, struct section *sec,
diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index 55208c6edfc6..2f1cedf9632b 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -352,6 +352,7 @@ static bool dont_correlate(struct symbol *sym)
is_uncorrelated_static_local(sym) ||
is_clang_tmp_label(sym) ||
is_string_sec(sym->sec) ||
+ (is_rodata_sec(sym->sec) && !is_object_sym(sym)) ||
is_special_section(sym->sec) ||
is_special_section_aux(sym->sec) ||
strstarts(sym->name, "__initcall__");
@@ -837,7 +838,7 @@ static int convert_reloc_secsym_to_sym(struct elf *elf, struct reloc *reloc)
goto found_sym;
/* No dedicated section; find the symbol manually */
- sym = find_symbol_containing(sec, arch_adjusted_addend(reloc));
+ sym = find_symbol_containing_inclusive(sec, arch_adjusted_addend(reloc));
if (!sym) {
/*
* This is presumably an .altinstr_replacement section which is
@@ -846,6 +847,17 @@ static int convert_reloc_secsym_to_sym(struct elf *elf, struct reloc *reloc)
if (!sec_size(sec))
return 1;
+ /*
+ * .rodata is a mixed bag of named objects and anonymous data.
+ *
+ * Convert section symbol references to named object symbols
+ * when possible, to preserve pointer identity for const
+ * structs like file_operations. Otherwise a section symbol is
+ * fine.
+ */
+ if (is_rodata_sec(sec))
+ return 0;
+
/*
* This can happen for special section references to weak code
* whose symbol has been stripped by the linker.
@@ -867,7 +879,6 @@ static int convert_reloc_secsym_to_sym(struct elf *elf, struct reloc *reloc)
static bool is_uncorrelated_section(struct section *sec)
{
return is_string_sec(sec) ||
- strstarts(sec->name, ".rodata") ||
strstarts(sec->name, ".data..Lubsan") || /* GCC */
strstarts(sec->name, ".data..L__unnamed_"); /* Clang */
}
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 32+ messages in thread* Re: [Devel] [PATCH hci-8.2 13/17] ms/objtool/klp: Fix pointer comparisons for rodata objects
2026-11-24 5:01 ` [Devel] [PATCH hci-8.2 13/17] ms/objtool/klp: Fix pointer comparisons for rodata objects Eva Kurchatova
@ 2026-11-24 12:20 ` Konstantin Khorenko
0 siblings, 0 replies; 32+ messages in thread
From: Konstantin Khorenko @ 2026-11-24 12:20 UTC (permalink / raw)
To: Eva Kurchatova; +Cc: devel
I won't apply this version, please send v2 with the changes below.
On Tue, 24 Nov 2026 07:01:02 +0200, Eva Kurchatova wrote:
> Fix it by correlating non-anonymous rodata objects.
Item 1 of the cover letter reply: a vz patch after this one that fails
klp diff when a correlated .rodata object differs in length, bytes or
relocations, or drop this patch.
The pick matches mainline, but here it brings a new silently wrong
case. Before it, a reference to a static const table from a changed
function cloned the patched .rodata object into the livepatch. Now
convert_reloc_sym() turns it into a reference to the object symbol,
klp_reloc_needed() returns true for a correlated unexported symbol,
and the livepatched function reads the original object.
mark_changed_functions() compares only function checksums, so a
changed object is not noticed.
Example: a fix adds a row to a static const table (an nla_policy, a
file_operations) and changes f() to use it. klp-build succeeds, and
the patched f() works on the old table, or reads past its end when it
loops to ARRAY_SIZE(). The same check also catches the other case
here: same-named function-local static const objects (tbl.1, tbl.2)
are correlated by name in order, so adding one earlier in the file
binds the reloc to another function's table.
In mainline this commit came in v7.2-rc1 together with 6016dd33a10a
("objtool/klp: Rewrite symbol correlation algorithm"), which rejects
such a patch; that rewrite is too large to take here, a small check
after correlate_symbols() is enough.
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 32+ messages in thread
* [Devel] [PATCH hci-8.2 14/17] ms/objtool/klp: Fix module name normalization for paths with dots
2026-11-24 5:00 [Devel] [PATCH hci-8.2 00/17] ms/objtool: fix silently wrong livepatches by klp-build Eva Kurchatova
` (12 preceding siblings ...)
2026-11-24 5:01 ` [Devel] [PATCH hci-8.2 13/17] ms/objtool/klp: Fix pointer comparisons for rodata objects Eva Kurchatova
@ 2026-11-24 5:01 ` Eva Kurchatova
2026-11-24 5:01 ` [Devel] [PATCH hci-8.2 15/17] ms/objtool/klp: Normalize Module.symvers paths to module names Eva Kurchatova
` (3 subsequent siblings)
17 siblings, 0 replies; 32+ messages in thread
From: Eva Kurchatova @ 2026-11-24 5:01 UTC (permalink / raw)
To: khorenko, vladimir.riabchun; +Cc: devel
From: Josh Poimboeuf <jpoimboe@kernel.org>
When .modinfo has no "name=" tag, __find_modname() falls back to
converting the object's build-tree path to a runtime module name by
stripping directory components, converting '-' to '_' and truncating the
file extension.
It does all that in a single pass over the entire path, so the first dot
anywhere in the path ends the name. For an object built in a directory
whose name contains a dot, e.g. "drivers/foo-1.0/bar.o", the result is a
bogus module name.
Strip the directory components up front so only the basename is scanned
for the extension separator.
Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffing object files")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: live-patching@vger.kernel.org
Link: https://patch.msgid.link/9017b4609553bed16674e8f924d34691cbc2b2c1.1785727106.git.jpoimboe@kernel.org
(cherry picked from commit 165affd6f095323d953b0ed5823ec4d0db3b7d0d)
https://virtuozzo.atlassian.net/browse/VSTOR-128510
Feature: klp-build support
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
tools/objtool/klp-diff.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index 2f1cedf9632b..c6f7c810f31a 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -712,7 +712,7 @@ static struct export *find_export(struct symbol *sym)
static const char *__find_modname(struct elfs *e)
{
struct section *sec;
- char *name;
+ char *name, *slash;
sec = find_section_by_name(e->orig, ".modinfo");
if (!sec) {
@@ -730,10 +730,12 @@ static const char *__find_modname(struct elfs *e)
return NULL;
}
+ slash = strrchr(name, '/');
+ if (slash)
+ name = slash + 1;
+
for (char *c = name; *c; c++) {
- if (*c == '/')
- name = c + 1;
- else if (*c == '-')
+ if (*c == '-')
*c = '_';
else if (*c == '.') {
*c = '\0';
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 32+ messages in thread* [Devel] [PATCH hci-8.2 15/17] ms/objtool/klp: Normalize Module.symvers paths to module names
2026-11-24 5:00 [Devel] [PATCH hci-8.2 00/17] ms/objtool: fix silently wrong livepatches by klp-build Eva Kurchatova
` (13 preceding siblings ...)
2026-11-24 5:01 ` [Devel] [PATCH hci-8.2 14/17] ms/objtool/klp: Fix module name normalization for paths with dots Eva Kurchatova
@ 2026-11-24 5:01 ` Eva Kurchatova
2026-11-24 5:01 ` [Devel] [PATCH hci-8.2 16/17] ms/objtool/klp: Fix cross-module klp relocation section naming Eva Kurchatova
` (2 subsequent siblings)
17 siblings, 0 replies; 32+ messages in thread
From: Eva Kurchatova @ 2026-11-24 5:01 UTC (permalink / raw)
To: khorenko, vladimir.riabchun; +Cc: devel
From: Joe Lawrence <joe.lawrence@redhat.com>
Module.symvers contains build-tree object paths as module identifiers
(e.g., "arch/x86/kvm/kvm") rather than runtime module names ("kvm").
Objtool's clone_reloc_klp() uses this field directly for exported
symbols, while unexported symbols correctly go through __find_modname().
This means that exported symbol relocations may land in a .klp.rela
section named with the build path rather than the module name. That is
a crash waiting to happen: the kernel's livepatch loader silently skips
this relocation because it doesn't match the expected klp_object name.
The unresolved relocation sits in the newly activated code, crashing
when executed.
Normalize export->mod at Module.symvers read time using the same logic
as __find_modname() (refactored into a shared normalize_modname()
helper).
Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffing object files")
Reported-by: Ben Procknow <bprockno@redhat.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Miroslav Benes <mbenes@suse.cz>
Cc: live-patching@vger.kernel.org
Link: https://patch.msgid.link/dbe1b72931bd3c31b751fd0729613d9f2226fff6.1785727106.git.jpoimboe@kernel.org
(cherry picked from commit 8668bf91e0508abeb8e98b4edd89032be02228a1)
https://virtuozzo.atlassian.net/browse/VSTOR-128510
Feature: klp-build support
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
tools/objtool/klp-diff.c | 49 ++++++++++++++++++++++++++++------------
1 file changed, 34 insertions(+), 15 deletions(-)
diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index c6f7c810f31a..f8213b03a883 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -83,6 +83,35 @@ static char *escape_str(const char *orig)
return new;
}
+/*
+ * Convert a build-tree object path to a runtime module name: strip
+ * directory components, replace '-' with '_', and remove file
+ * extensions. Examples:
+ *
+ * "arch/x86/kvm/kvm" -> "kvm"
+ * "arch/x86/kvm/kvm-intel" -> "kvm_intel".
+ *
+ * Used by read_exports() to normalize Module.symvers entries and by
+ * __find_modname() as a fallback when .modinfo lacks a "name=" tag.
+ */
+static char *normalize_modname(char *name)
+{
+ char *slash = strrchr(name, '/');
+
+ if (slash)
+ name = slash + 1;
+
+ for (char *c = name; *c; c++) {
+ if (*c == '-')
+ *c = '_';
+ else if (*c == '.') {
+ *c = '\0';
+ break;
+ }
+ }
+ return name;
+}
+
static int read_exports(void)
{
const char *symvers = "Module.symvers";
@@ -150,6 +179,9 @@ static int read_exports(void)
return -1;
}
+ if (strcmp(export->mod, "vmlinux"))
+ export->mod = normalize_modname(export->mod);
+
export->sym = strdup(sym);
if (!export->sym) {
ERROR_GLIBC("strdup");
@@ -712,7 +744,7 @@ static struct export *find_export(struct symbol *sym)
static const char *__find_modname(struct elfs *e)
{
struct section *sec;
- char *name, *slash;
+ char *name;
sec = find_section_by_name(e->orig, ".modinfo");
if (!sec) {
@@ -730,20 +762,7 @@ static const char *__find_modname(struct elfs *e)
return NULL;
}
- slash = strrchr(name, '/');
- if (slash)
- name = slash + 1;
-
- for (char *c = name; *c; c++) {
- if (*c == '-')
- *c = '_';
- else if (*c == '.') {
- *c = '\0';
- break;
- }
- }
-
- return name;
+ return normalize_modname(name);
}
/* Get the object's module name as defined by the kernel (and klp_object) */
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 32+ messages in thread* [Devel] [PATCH hci-8.2 16/17] ms/objtool/klp: Fix cross-module klp relocation section naming
2026-11-24 5:00 [Devel] [PATCH hci-8.2 00/17] ms/objtool: fix silently wrong livepatches by klp-build Eva Kurchatova
` (14 preceding siblings ...)
2026-11-24 5:01 ` [Devel] [PATCH hci-8.2 15/17] ms/objtool/klp: Normalize Module.symvers paths to module names Eva Kurchatova
@ 2026-11-24 5:01 ` Eva Kurchatova
2026-11-24 5:01 ` [Devel] [PATCH hci-8.2 17/17] ms/objtool/klp: Don't match local symbols against exports Eva Kurchatova
2026-11-24 12:20 ` [Devel] [PATCH hci-8.2 00/17] ms/objtool: fix silently wrong livepatches by klp-build Konstantin Khorenko
17 siblings, 0 replies; 32+ messages in thread
From: Eva Kurchatova @ 2026-11-24 5:01 UTC (permalink / raw)
To: khorenko, vladimir.riabchun; +Cc: devel
From: Josh Poimboeuf <jpoimboe@kernel.org>
A klp relocation section is .klp.rela.<objname>.<secname>, where objname
is the object being patched.
klp-build wrongly derives objname from where the referenced symbol
lives, not where it's referenced. For a cross-module reference like
patched can_isotp code calling can.ko's can_rx_unregister(), that gives
.klp.rela.can..text rather than .klp.rela.can_isotp..text. Unless the
patch happens to patch can.ko as well, the relocation never gets applied
and the call goes off into the weeds.
Name the intermediate section __klp_relocs.<objname> so post-link can
read the patched object's name from there.
Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffing object files")
Reported-by: Joe Lawrence <joe.lawrence@redhat.com>
Link: https://lore.kernel.org/20260720145658.1103243-2-joe.lawrence@redhat.com
Acked-by: Song Liu <song@kernel.org>
Acked-by: Joe Lawrence <joe.lawrence@redhat.com>
Link: https://patch.msgid.link/ee93a08f3e55e76ffa67d04e283917ddaa893f09.1786138493.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
(cherry picked from commit 07f14d6af9d7791fdc2b44a3dd0693e42c71d2b8)
https://virtuozzo.atlassian.net/browse/VSTOR-128510
Feature: klp-build support
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
tools/objtool/include/objtool/klp.h | 10 ++++--
tools/objtool/klp-diff.c | 17 +++++++--
tools/objtool/klp-post-link.c | 53 +++++++++++++++++------------
3 files changed, 52 insertions(+), 28 deletions(-)
diff --git a/tools/objtool/include/objtool/klp.h b/tools/objtool/include/objtool/klp.h
index ad830a7ce55b..d9cb594f4924 100644
--- a/tools/objtool/include/objtool/klp.h
+++ b/tools/objtool/include/objtool/klp.h
@@ -14,11 +14,15 @@
#define KLP_FUNCS_SEC "__klp_funcs"
/*
- * __klp_relocs is an intermediate section which are created by klp diff and
- * converted into KLP symbols/relas by "objtool klp post-link". This is needed
- * to work around the linker, which doesn't preserve SHN_LIVEPATCH or
+ * __klp_relocs.<objname> are intermediate sections which are created by klp
+ * diff and converted into KLP symbols/relas by "objtool klp post-link". This
+ * is needed to work around the linker, which doesn't preserve SHN_LIVEPATCH or
* SHF_RELA_LIVEPATCH, nor does it support having two RELA sections for a
* single PROGBITS section.
+ *
+ * "objname" is the name of the object being patched ("vmlinux" or a module
+ * name). post-link uses it to name the resulting
+ * .klp.rela.objname.section_name sections.
*/
#define KLP_RELOCS_SEC "__klp_relocs"
#define KLP_STRINGS_SEC ".rodata.klp.str1.1"
diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index f8213b03a883..99c1184c8caf 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -1003,8 +1003,8 @@ static int clone_reloc_klp(struct elfs *e, struct reloc *patched_reloc,
}
/*
- * Create the __klp_relocs entry. This will be converted to an actual
- * KLP rela by "objtool klp post-link".
+ * Create the __klp_relocs.<objname> entry. This will be converted to
+ * an actual KLP rela by "objtool klp post-link".
*
* This intermediate step is necessary to prevent corruption by the
* linker, which doesn't know how to properly handle two rela sections
@@ -1012,7 +1012,18 @@ static int clone_reloc_klp(struct elfs *e, struct reloc *patched_reloc,
*/
if (!klp_relocs) {
- klp_relocs = elf_create_section(e->out, KLP_RELOCS_SEC, 0,
+ const char *objname = find_modname(e);
+ char sec_name[SEC_NAME_LEN];
+
+ if (!objname)
+ return -1;
+
+ /* section format: __klp_relocs.objname */
+ if (snprintf_check(sec_name, SEC_NAME_LEN,
+ KLP_RELOCS_SEC ".%s", objname))
+ return -1;
+
+ klp_relocs = elf_create_section(e->out, sec_name, 0,
0, SHT_PROGBITS, 8, SHF_ALLOC);
if (!klp_relocs)
return -1;
diff --git a/tools/objtool/klp-post-link.c b/tools/objtool/klp-post-link.c
index c013e39957b1..350d20495897 100644
--- a/tools/objtool/klp-post-link.c
+++ b/tools/objtool/klp-post-link.c
@@ -19,19 +19,11 @@
#include <objtool/util.h>
#include <linux/livepatch_external.h>
-static int fix_klp_relocs(struct elf *elf)
+static int fix_klp_reloc_sec(struct elf *elf, struct section *symtab,
+ struct section *klp_relocs)
{
- struct section *symtab, *klp_relocs;
-
- klp_relocs = find_section_by_name(elf, KLP_RELOCS_SEC);
- if (!klp_relocs)
- return 0;
-
- symtab = find_section_by_name(elf, ".symtab");
- if (!symtab) {
- ERROR("missing .symtab");
- return -1;
- }
+ /* section format: __klp_relocs.sec_objname */
+ const char *sec_objname = klp_relocs->name + strlen(KLP_RELOCS_SEC ".");
for (int i = 0; i < sec_size(klp_relocs) / sizeof(struct klp_reloc); i++) {
struct klp_reloc *klp_reloc;
@@ -39,7 +31,6 @@ static int fix_klp_relocs(struct elf *elf)
struct section *sec, *tmp, *klp_rsec;
unsigned long offset;
struct reloc *reloc;
- char sym_modname[64];
char rsec_name[SEC_NAME_LEN];
u64 addend;
struct symbol *sym, *klp_sym;
@@ -55,7 +46,7 @@ static int fix_klp_relocs(struct elf *elf)
reloc = find_reloc_by_dest(elf, klp_relocs,
klp_reloc_off + offsetof(struct klp_reloc, offset));
if (!reloc) {
- ERROR("malformed " KLP_RELOCS_SEC " section");
+ ERROR("malformed %s section", klp_relocs->name);
return -1;
}
@@ -66,17 +57,13 @@ static int fix_klp_relocs(struct elf *elf)
reloc = find_reloc_by_dest(elf, klp_relocs,
klp_reloc_off + offsetof(struct klp_reloc, sym));
if (!reloc) {
- ERROR("malformed " KLP_RELOCS_SEC " section");
+ ERROR("malformed %s section", klp_relocs->name);
return -1;
}
klp_sym = reloc->sym;
addend = reloc_addend(reloc);
- /* symbol format: .klp.sym.modname.sym_name,sympos */
- if (sscanf(klp_sym->name + strlen(KLP_SYM_PREFIX), "%55[^.]", sym_modname) != 1)
- ERROR("can't find modname in klp symbol '%s'", klp_sym->name);
-
/*
* Create the KLP rela:
*/
@@ -84,7 +71,7 @@ static int fix_klp_relocs(struct elf *elf)
/* section format: .klp.rela.sec_objname.section_name */
if (snprintf_check(rsec_name, SEC_NAME_LEN,
KLP_RELOC_SEC_PREFIX "%s.%s",
- sym_modname, sec->name))
+ sec_objname, sec->name))
return -1;
klp_rsec = find_section_by_name(elf, rsec_name);
@@ -134,10 +121,32 @@ static int fix_klp_relocs(struct elf *elf)
return 0;
}
+static int fix_klp_relocs(struct elf *elf)
+{
+ struct section *symtab, *sec;
+
+ symtab = find_section_by_name(elf, ".symtab");
+ if (!symtab) {
+ ERROR("missing .symtab");
+ return -1;
+ }
+
+ for_each_sec(elf, sec) {
+ if (strncmp(sec->name, KLP_RELOCS_SEC ".",
+ strlen(KLP_RELOCS_SEC ".")))
+ continue;
+
+ if (fix_klp_reloc_sec(elf, symtab, sec))
+ return -1;
+ }
+
+ return 0;
+}
+
/*
* This runs on the livepatch module after all other linking has been done. It
- * converts the intermediate __klp_relocs section into proper KLP relocs to be
- * processed by livepatch. This needs to run last to avoid linker wreckage.
+ * converts the intermediate __klp_relocs.* sections into proper KLP relocs to
+ * be processed by livepatch. This needs to run last to avoid linker wreckage.
* Linkers don't tend to handle the "two rela sections for a single base
* section" case very well, nor do they appreciate SHN_LIVEPATCH.
*/
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 32+ messages in thread* [Devel] [PATCH hci-8.2 17/17] ms/objtool/klp: Don't match local symbols against exports
2026-11-24 5:00 [Devel] [PATCH hci-8.2 00/17] ms/objtool: fix silently wrong livepatches by klp-build Eva Kurchatova
` (15 preceding siblings ...)
2026-11-24 5:01 ` [Devel] [PATCH hci-8.2 16/17] ms/objtool/klp: Fix cross-module klp relocation section naming Eva Kurchatova
@ 2026-11-24 5:01 ` Eva Kurchatova
2026-11-24 12:20 ` [Devel] [PATCH hci-8.2 00/17] ms/objtool: fix silently wrong livepatches by klp-build Konstantin Khorenko
17 siblings, 0 replies; 32+ messages in thread
From: Eva Kurchatova @ 2026-11-24 5:01 UTC (permalink / raw)
To: khorenko, vladimir.riabchun; +Cc: devel
From: Josh Poimboeuf <jpoimboe@kernel.org>
While cloning a reloc, klp diff calls find_export() to determine whether
the referenced symbol is exported. That decides whether the reference
needs a klp reloc, which object the klp symbol belongs to, and whether
the symbol's data needs to be copied into the patch module.
But find_export() matches purely on symbol name, so a static function or
variable which happens to share its name with an export is mistaken for
a reference to that export:
- klp_reloc_needed() creates a klp reloc pointing at the exporting
module's symbol rather than the local one. For a vmlinux export it
skips the klp reloc altogether, leaving a normal reloc which the
module loader resolves to the vmlinux symbol.
- clone_reloc() treats the symbol as external and clones it without
its data, leaving a dangling reference.
- validate_special_section_klp_reloc() attributes a static branch or
call key to the wrong module, and for a vmlinux export skips the
unsupported-key check entirely.
Exports are always global, so ignore local symbols in find_export().
Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffing object files")
Acked-by: Song Liu <song@kernel.org>
Acked-by: Joe Lawrence <joe.lawrence@redhat.com>
Link: https://patch.msgid.link/dafc7c017d1f62e2190a20dc84a52fbfc4c70210.1786138493.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
(cherry picked from commit 86a697572c6271083694025eefa8de518eeef623)
https://virtuozzo.atlassian.net/browse/VSTOR-128510
Feature: klp-build support
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
tools/objtool/klp-diff.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index 99c1184c8caf..4fd9e697adf3 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -733,6 +733,9 @@ static struct export *find_export(struct symbol *sym)
{
struct export *export;
+ if (is_local_sym(sym))
+ return NULL;
+
hash_for_each_possible(exports, export, hash, str_hash(sym->name)) {
if (!strcmp(export->sym, sym->name))
return export;
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 32+ messages in thread* Re: [Devel] [PATCH hci-8.2 00/17] ms/objtool: fix silently wrong livepatches by klp-build
2026-11-24 5:00 [Devel] [PATCH hci-8.2 00/17] ms/objtool: fix silently wrong livepatches by klp-build Eva Kurchatova
` (16 preceding siblings ...)
2026-11-24 5:01 ` [Devel] [PATCH hci-8.2 17/17] ms/objtool/klp: Don't match local symbols against exports Eva Kurchatova
@ 2026-11-24 12:20 ` Konstantin Khorenko
17 siblings, 0 replies; 32+ messages in thread
From: Konstantin Khorenko @ 2026-11-24 12:20 UTC (permalink / raw)
To: Eva Kurchatova; +Cc: devel
I won't apply this version, please send v2 with the changes below.
On Tue, 24 Nov 2026 07:00:49 +0200, Eva Kurchatova wrote:
> Note: Same as before, a patch which changes a const object keeps the
> original object in the .data section; mainline now rejects such patch.
1. Patch 13: add a vz patch after it that makes klp diff fail when a
correlated .rodata object changed (length, bytes or relocations),
or drop 13. Details in the reply to 13.
2. Cover letter: drop or correct the note above.
Patch 13 is what makes this happen for const objects. Before the
series, every .rodata symbol was uncorrelated, so a changed const
object was cloned into the livepatch with its new contents. After 13
a named const object is correlated and referenced through a klp reloc
to the original, and nothing compares the contents. Mainline took the
same correlation together with 873a2208ea31 ("objtool/klp: Calculate
object checksums") and 6016dd33a10a ("objtool/klp: Rewrite symbol
correlation algorithm"), which reject a changed object; this series
gets the correlation without the rejection.
Patches 1-12 and 14-17 are fine as they are.
Separate patches, not needed for this series. I created a task for
them:
1. Mainline klp-build fixes left out that a vz10 x86_64 gcc build can
hit: 15fa203ef91e ("objtool/klp: Fix symbol resolution for duplicate
data symbols", needs 029223d30162; patch 13 makes every named const
object a klp reloc target, so a wrong sympos matters more now),
72d76d0c18eb ("objtool/klp: Allow new references to module
exports"), 636f230ce21e and 1ea786097cd7 (empty x86 alternatives),
2c2acca2eabf (.cold detection for duplicate symbols), 11c2adcd1fa2
(NULL dereference when printing code_sym, from the same mainline
series as patches 1 and 2).
https://virtuozzo.atlassian.net/browse/VSTOR-156924
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 32+ messages in thread