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 EE01F463B88; Thu, 13 Aug 2026 11:16:35 +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=1786619799; cv=none; b=qcA26ncbz/iyJyGOIULXryPoYB5e0ZnOsLXT33bt13W6SO+Evn3RL+6sN4zqm9pro4XLzakMCcf5zeqUXySzlCWgFF/Ndlu5/MxBrMo6y6dKsyk5lqbXHQiHDLwr5eHSCYwX64GBllEK/lljQbiIJM5KtQyZP7uNqsxZH99PBSM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786619799; c=relaxed/simple; bh=UJrM4U3ePqenboNBrxL1fad4gkO7yv63tbDn3Xat9Mc=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=a8UQqBlcE9ye0E9HiqeXY5LVvybXx1FcloO5RSTmXTXlSSVOWiGwP9slqk6BmZ5rmqJR24HDLbmXsFP4J2dUB/3Jdqn50CGwi37hREtgkzAuM4LkMehlnEJmWCobguzW7ehNs5JKos9SO3wwKoz+HUOTJQldsDfQtnr8SLGm1vA= 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=MKZtlIeE; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=HLYhLD/P; 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="MKZtlIeE"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="HLYhLD/P" Date: Thu, 13 Aug 2026 11:16:31 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1786619792; 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=zCZZP426F2Ct+koEcCx2wa60EaSs2WKfGic61OCLvGo=; b=MKZtlIeEZv6GnvQeg+fzQId9fR1tHXsRnkvUEEJdHcI38hcOU/MmrOQvXp+Ujrn1IK/2sE WSSb8mGOLq0x5zOhbPpW3kl1l2uxtYNO9Btxo8jAOfREOS7X2o+id3hrezSEO7dhxw+6Vj IiCxYP4wQvhEyoDfZsJPB33sPCD/4CAVvhpZyTVX++uLvXXoDFzXryGOpdexkJQiYqsTw9 BStc6iu4tYq8en4V3TgQm/5tS5MMKlbYJuy8BA1UEmQayvHfJQAxE9ANyfGNQrJyGnP5Jr So8uYYGWnXARW8jBT5qYtbpc3pgN738uD65vXPk1xkPcqexYcf38oopsCnha+Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1786619792; 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=zCZZP426F2Ct+koEcCx2wa60EaSs2WKfGic61OCLvGo=; b=HLYhLD/Pw/mO1gy27dM0dYwdnr1VDz6tLYvP453Zb7V0w7ObKVvIEn3A1r5bJhLshsc/9W R2DEDCqDfq3lo6Ag== 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: Ignore replacement offset of empty x86 alternatives Cc: Song Liu , Joe Lawrence , Josh Poimboeuf , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <7a885b70974795c3417f3358869e62aafd4ef783.1786138493.git.jpoimboe@kernel.org> References: <7a885b70974795c3417f3358869e62aafd4ef783.1786138493.git.jpoimboe@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <178661979111.442315.10542911909795580862.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: 636f230ce21e2730072c58280f1fa0bed4a00eed Gitweb: https://git.kernel.org/tip/636f230ce21e2730072c58280f1fa0bed= 4a00eed Author: Josh Poimboeuf AuthorDate: Fri, 07 Aug 2026 14:37:48 -07:00 Committer: Josh Poimboeuf CommitterDate: Tue, 11 Aug 2026 15:04:57 -07:00 objtool/klp: Ignore replacement offset of empty x86 alternatives An x86 alternative with an empty replacement, e.g. the second entry of ALTERNATIVE_2("orig", "repl", ft1, "", ft2) has a replacementlen of zero. Its replacement offset still gets a relocation, but the label it points at is the end of the previous replacement, which is also the beginning of the *next* alternative's replacement. The value is meaningless; get_alt_entry() already ignores it for that reason. klp diff doesn't ignore it. When such an alternative belongs to a changed function, cloning its relocations drags in the unrelated neighboring replacement, along with everything that replacement references. On an x86 clang/lto build an empty alternative in meminfo_proc_show() pulled in the replacement of an alternative in proc_kcore_init(), silently emitting a klp relocation against init text which has long since been freed by the time the patch is applied. Add arch_alt_ignore_new_reloc() and skip such relocations when cloning. This has to be arch specific: on arm64 a zero-length replacement instead identifies an alternative callback, whose replacement offset points at the callback function and must be preserved. Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffin= g object files") Acked-by: Song Liu Acked-by: Joe Lawrence Link: https://patch.msgid.link/7a885b70974795c3417f3358869e62aafd4ef783.178= 6138493.git.jpoimboe@kernel.org Signed-off-by: Josh Poimboeuf --- tools/objtool/arch/x86/special.c | 27 ++++++++++++++++++++++++- tools/objtool/include/objtool/special.h | 7 ++++++- tools/objtool/klp-diff.c | 6 ++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/tools/objtool/arch/x86/special.c b/tools/objtool/arch/x86/spec= ial.c index e817a3f..1e84c81 100644 --- a/tools/objtool/arch/x86/special.c +++ b/tools/objtool/arch/x86/special.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include =20 +#include #include #include #include @@ -9,6 +10,32 @@ /* cpu feature name array generated from cpufeatures.h */ #include "cpu-feature-names.c" =20 +/* + * An alternative with an empty replacement, e.g. the second entry of + * + * ALTERNATIVE_2("orig", "repl", ft1, "", ft2) + * + * still gets a relocation for its replacement offset. But the label it p= oints + * at is the end of the previous entry's replacement, which is also the + * beginning of the *next* entry's replacement. The value is meaningless:= it's + * only ever used with a length of zero. + */ +bool arch_alt_ignore_new_reloc(struct section *sec, unsigned long offset) +{ + unsigned long entry_off; + + if (strcmp(sec->name, ".altinstructions")) + return false; + + entry_off =3D offset - (offset % ALT_ENTRY_SIZE); + + if (offset - entry_off !=3D ALT_NEW_OFFSET) + return false; + + return !*(unsigned char *)(sec->data->d_buf + entry_off + + ALT_NEW_LEN_OFFSET); +} + void arch_handle_alternative(struct special_alt *alt) { static struct special_alt *group, *prev; diff --git a/tools/objtool/include/objtool/special.h b/tools/objtool/includ= e/objtool/special.h index 121c376..620dbf6 100644 --- a/tools/objtool/include/objtool/special.h +++ b/tools/objtool/include/objtool/special.h @@ -32,6 +32,13 @@ int special_get_alts(struct elf *elf, struct list_head *= alts); =20 void arch_handle_alternative(struct special_alt *alt); =20 +/* + * Should the reloc at @offset -- the "new" (replacement) field of a speci= al + * section group entry -- be ignored? The meaning of a zero-length replac= ement + * is arch specific, so the arch decides. + */ +bool arch_alt_ignore_new_reloc(struct section *sec, unsigned long offset); + bool arch_support_alt_relocation(struct special_alt *special_alt, struct instruction *insn, struct reloc *reloc); diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index b4220e1..df2fe01 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include =20 #include #include @@ -1538,6 +1538,10 @@ static int clone_sym_relocs(struct elfs *e, struct s= ymbol *patched_sym) !strcmp(patched_reloc->sym->sec->name, ".altinstr_aux")) continue; =20 + if (arch_alt_ignore_new_reloc(patched_sym->sec, + reloc_offset(patched_reloc))) + continue; + ret =3D convert_reloc_sym(e->patched, patched_reloc); if (ret < 0) { ERROR_FUNC(patched_rsec->base, reloc_offset(patched_reloc),