From nobody Tue Sep 29 02:02:55 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E4E4311977; Thu, 13 Aug 2026 11:16:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786619801; cv=none; b=Y27tgx57FqY1UjiQde4Qg2aVIymlAJ3zv5ZC/YRvl+FSP17vrqZivtv9cZLZ4o5XdlPN7lEX6l47LosvfCHBy/AV2fPl4RH70r39LDYv7IpnVJTlLA7+/1hQdtAlwXpaRVZNCZjuNMtzt4oCEww+ql5mPYVKsk0H5GfBw6cYveo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786619801; c=relaxed/simple; bh=7+50RHiiF+4CqDMWZQvE5Y3pY3LLtEGcrD5e7IkYBz0=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=HYWsbjRWfGq1hj7eql8yJg/s8gehF93fnjTqpR+8V9zc/4xFj/71uh6U7c2tbn18LwQf5wycuRsygKUtIrFRfl/sn3qB8jwaBVtCRdpBvCOBxMwaVz0I//T+jwxsMZp01L68FSedgTfwN/0fxbGHjrbzpMur/6xxDTgJ5DAAmX0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=VOmZMNkb; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=uX35zTVl; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="VOmZMNkb"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="uX35zTVl" Date: Thu, 13 Aug 2026 11:16:28 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1786619789; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9DamcQfMtU7KbPR9y+nRAoHRQUNz37gCUnHEgUKeYY8=; b=VOmZMNkbwbB1Ok5Jyvnm3ZO+uwckw9hcQrvwb4U54dVyDI2tVS9mC4JfjJuJIOfXqWEeoq 9mm5CI694p56uZRxI1xpbujwwPQDG66IcHdN1qrvPB5nCOAtP03wptSnmSML1AA8YVXQJ1 bDbGN3VjIPl5DABsGntlG4uBN5esA3GGl10w0aXwbXPH082rKbNU69Wo/eyF8YNhz75oh4 icXX/gGR3GBJcVKz/iB0tRidkptyTQTOhkW5ufQ0oNz6kzFQJ7ScH+VCv1TOhAz6wNLsqt qNS4blx6UtJbLhqo38oLqRvWqPDTQ8U6KPAPUzCMzZHMA0ZL4fcsGgXH+YdMTQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1786619789; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9DamcQfMtU7KbPR9y+nRAoHRQUNz37gCUnHEgUKeYY8=; b=uX35zTVleK2pb/cTbuAJmOS7rJ4oTLeMZcRaR5Me96dnxS4Kd/i/F0nZIvwXClhurniMjn AL2MYJojS1PjIpBw== From: "tip-bot2 for Josh Poimboeuf" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: objtool/core] objtool/klp: Fix cross-module klp relocation section naming Cc: Joe Lawrence , Song Liu , Josh Poimboeuf , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <178661978812.442315.6467514397790766303.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the objtool/core branch of tip: Commit-ID: 07f14d6af9d7791fdc2b44a3dd0693e42c71d2b8 Gitweb: https://git.kernel.org/tip/07f14d6af9d7791fdc2b44a3dd0693e42= c71d2b8 Author: Josh Poimboeuf AuthorDate: Fri, 07 Aug 2026 14:37:50 -07:00 Committer: Josh Poimboeuf CommitterDate: Tue, 11 Aug 2026 16:10:51 -07:00 objtool/klp: Fix cross-module klp relocation section naming A klp relocation section is .klp.rela.., 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. so post-link can read the patched object's name from there. Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffin= g object files") Reported-by: Joe Lawrence Link: https://lore.kernel.org/20260720145658.1103243-2-joe.lawrence@redhat.= com Acked-by: Song Liu Acked-by: Joe Lawrence Link: https://patch.msgid.link/ee93a08f3e55e76ffa67d04e283917ddaa893f09.178= 6138493.git.jpoimboe@kernel.org Signed-off-by: Josh Poimboeuf --- 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/ob= jtool/klp.h index 0118c2c..646d8e1 100644 --- a/tools/objtool/include/objtool/klp.h +++ b/tools/objtool/include/objtool/klp.h @@ -14,11 +14,15 @@ #define KLP_FUNCS_SEC ".init.klp_funcs" =20 /* - * __klp_relocs is an intermediate section which are created by klp diff a= nd - * converted into KLP symbols/relas by "objtool klp post-link". This is n= eeded - * to work around the linker, which doesn't preserve SHN_LIVEPATCH or + * __klp_relocs. are intermediate sections which are created by k= lp + * 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_LIVEPAT= CH 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 df2fe01..e266a54 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -1381,8 +1381,8 @@ static int clone_reloc_klp(struct elfs *e, struct rel= oc *patched_reloc, } =20 /* - * Create the __klp_relocs entry. This will be converted to an actual - * KLP rela by "objtool klp post-link". + * Create the __klp_relocs. 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 @@ -1390,7 +1390,18 @@ static int clone_reloc_klp(struct elfs *e, struct re= loc *patched_reloc, */ =20 if (!klp_relocs) { - klp_relocs =3D elf_create_section(e->out, KLP_RELOCS_SEC, 0, + const char *objname =3D 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 =3D 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 c013e39..350d204 100644 --- a/tools/objtool/klp-post-link.c +++ b/tools/objtool/klp-post-link.c @@ -19,19 +19,11 @@ #include #include =20 -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 =3D find_section_by_name(elf, KLP_RELOCS_SEC); - if (!klp_relocs) - return 0; - - symtab =3D find_section_by_name(elf, ".symtab"); - if (!symtab) { - ERROR("missing .symtab"); - return -1; - } + /* section format: __klp_relocs.sec_objname */ + const char *sec_objname =3D klp_relocs->name + strlen(KLP_RELOCS_SEC "."); =20 for (int i =3D 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 =3D 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; } =20 @@ -66,17 +57,13 @@ static int fix_klp_relocs(struct elf *elf) reloc =3D 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; } =20 klp_sym =3D reloc->sym; addend =3D reloc_addend(reloc); =20 - /* symbol format: .klp.sym.modname.sym_name,sympos */ - if (sscanf(klp_sym->name + strlen(KLP_SYM_PREFIX), "%55[^.]", sym_modnam= e) !=3D 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; =20 klp_rsec =3D find_section_by_name(elf, rsec_name); @@ -134,10 +121,32 @@ static int fix_klp_relocs(struct elf *elf) return 0; } =20 +static int fix_klp_relocs(struct elf *elf) +{ + struct section *symtab, *sec; + + symtab =3D 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 t= o be - * processed by livepatch. This needs to run last to avoid linker wreckag= e. + * converts the intermediate __klp_relocs.* sections into proper KLP reloc= s to + * be processed by livepatch. This needs to run last to avoid linker wrec= kage. * Linkers don't tend to handle the "two rela sections for a single base * section" case very well, nor do they appreciate SHN_LIVEPATCH. */