From nobody Tue Dec 16 23:40:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 60D0C1E8351 for ; Mon, 24 Mar 2025 21:56:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853382; cv=none; b=oo+C1pvKqEjRAbUP9mejD7HHQPosh+mJwzTa9qTzuf0Wy8NSFU2WdKuvMz5U3B+ctTicGSae6OTQpriShJ+jXULP+ekxpk/ZP9fdAdjFBdfgm0ZUc99aAVDL35etot6EQ2HQ8Zzx9AvHRSkQz/mUJDOm11CWuWjNRVlsPTpBhvY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853382; c=relaxed/simple; bh=/n+9+BkPcWQMa+ukZQtgWSkqXbptBcXwS6cgabiGf/c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FJ/jje0LdKwdAupFTSuKuNuo3oehR/0qIt0D0adnW0gAuZJISJHbRSN6ZZUCDZtL+KtwLSJmwebxFE7bwGOAgWavrERTiGuKvzB3OlgEhWP/u3MEMf+Jv14QvYmxtHIqXJ6VEVLxitAx2hP8vIRyj6tN4tAESazqb3HuTolVW9M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tK7+/llM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tK7+/llM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 834EDC4CEF0; Mon, 24 Mar 2025 21:56:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742853381; bh=/n+9+BkPcWQMa+ukZQtgWSkqXbptBcXwS6cgabiGf/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tK7+/llM1V9H5hAwcPrKx1q6JLDqTJu9Ppw1isme8so9wxXRuIirvvHS1pOtV0tLJ OFFv91WWSWgV4ATt82QjCiW+1+t+M6G44QmrJOEWJfJNWXbV4ig6gM7KPayL1tH6vB prUIJTzWfWeWW4INjpoMnDcZ4D838ar8MbCMkOe6IuDDr6b/4SHxJOvFDdaMof7I+q 5ejJmbXnrOluU3Mqj7r//S2oiIjDwbOu/vaHPZdCyEWT56EtsG3niNjwv68kpNdKDl VtHH7g0HRs7qRsosvh5/pjBXUCHYwhsxb8WqO9+CmESOUhgYIePIvVyeaiBr2HiQPK WIrGC2qyrM1cw== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Miroslav Benes , Brendan Jackman , Nathan Chancellor , kernel test robot Subject: [PATCH 01/22] objtool: Fix detection of consecutive jump tables Date: Mon, 24 Mar 2025 14:55:51 -0700 Message-ID: <141752fff614eab962dba6bdfaa54aa67ff03bba.1742852846.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The jump table detection code assumes jump tables are in the same order as their corresponding indirect branches. That's apparently not always true with Clang 20. Fix that by changing how multiple jump tables are detected. In the first detection pass, mark the beginning of each jump table so the second pass can tell where one ends and the next one begins. Fixes the following warnings: vmlinux.o: warning: objtool: SiS_GetCRT2Ptr+0x1ad: stack state mismatch: = cfa1=3D4+8 cfa2=3D5+16 sound/core/seq/snd-seq.o: warning: objtool: cc_ev_to_ump_midi2+0x589: ret= urn with modified stack frame Fixes: be2f0b1e1264 ("objtool: Get rid of reloc->jump_table_start") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202503171547.LlCTJLQL-lkp@int= el.com/ Closes: https://lore.kernel.org/oe-kbuild-all/202503200535.J3hAvcjw-lkp@int= el.com/ Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 26 ++++++++------------------ tools/objtool/elf.c | 6 +++--- tools/objtool/include/objtool/elf.h | 27 ++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 48d7bc5b4736..33beefd459a6 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1949,8 +1949,7 @@ __weak unsigned long arch_jump_table_sym_offset(struc= t reloc *reloc, struct relo return reloc->sym->offset + reloc_addend(reloc); } =20 -static int add_jump_table(struct objtool_file *file, struct instruction *i= nsn, - struct reloc *next_table) +static int add_jump_table(struct objtool_file *file, struct instruction *i= nsn) { unsigned long table_size =3D insn_jump_table_size(insn); struct symbol *pfunc =3D insn_func(insn)->pfunc; @@ -1970,7 +1969,7 @@ static int add_jump_table(struct objtool_file *file, = struct instruction *insn, /* Check for the end of the table: */ if (table_size && reloc_offset(reloc) - reloc_offset(table) >=3D table_s= ize) break; - if (reloc !=3D table && reloc =3D=3D next_table) + if (reloc !=3D table && is_jump_table(reloc)) break; =20 /* Make sure the table entries are consecutive: */ @@ -2061,8 +2060,10 @@ static void find_jump_table(struct objtool_file *fil= e, struct symbol *func, if (!dest_insn || !insn_func(dest_insn) || insn_func(dest_insn)->pfunc != =3D func) continue; =20 + set_jump_table(table_reloc); orig_insn->_jump_table =3D table_reloc; orig_insn->_jump_table_size =3D table_size; + break; } } @@ -2104,31 +2105,20 @@ static void mark_func_jump_tables(struct objtool_fi= le *file, static int add_func_jump_tables(struct objtool_file *file, struct symbol *func) { - struct instruction *insn, *insn_t1 =3D NULL, *insn_t2; - int ret =3D 0; + struct instruction *insn; + int ret; =20 func_for_each_insn(file, func, insn) { if (!insn_jump_table(insn)) continue; =20 - if (!insn_t1) { - insn_t1 =3D insn; - continue; - } =20 - insn_t2 =3D insn; - - ret =3D add_jump_table(file, insn_t1, insn_jump_table(insn_t2)); + ret =3D add_jump_table(file, insn); if (ret) return ret; - - insn_t1 =3D insn_t2; } =20 - if (insn_t1) - ret =3D add_jump_table(file, insn_t1, NULL); - - return ret; + return 0; } =20 /* diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index be4f4b62730c..0f38167bd840 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -583,7 +583,7 @@ static int elf_update_sym_relocs(struct elf *elf, struc= t symbol *sym) { struct reloc *reloc; =20 - for (reloc =3D sym->relocs; reloc; reloc =3D reloc->sym_next_reloc) + for (reloc =3D sym->relocs; reloc; reloc =3D sym_next_reloc(reloc)) set_reloc_sym(elf, reloc, reloc->sym->idx); =20 return 0; @@ -880,7 +880,7 @@ static struct reloc *elf_init_reloc(struct elf *elf, st= ruct section *rsec, set_reloc_addend(elf, reloc, addend); =20 elf_hash_add(reloc, &reloc->hash, reloc_hash(reloc)); - reloc->sym_next_reloc =3D sym->relocs; + set_sym_next_reloc(reloc, sym->relocs); sym->relocs =3D reloc; =20 return reloc; @@ -979,7 +979,7 @@ static int read_relocs(struct elf *elf) } =20 elf_hash_add(reloc, &reloc->hash, reloc_hash(reloc)); - reloc->sym_next_reloc =3D sym->relocs; + set_sym_next_reloc(reloc, sym->relocs); sym->relocs =3D reloc; =20 nr_reloc++; diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/ob= jtool/elf.h index 223ac1c24b90..4edc957a6f6b 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -77,7 +77,7 @@ struct reloc { struct elf_hash_node hash; struct section *sec; struct symbol *sym; - struct reloc *sym_next_reloc; + unsigned long _sym_next_reloc; }; =20 struct elf { @@ -297,6 +297,31 @@ static inline void set_reloc_type(struct elf *elf, str= uct reloc *reloc, unsigned mark_sec_changed(elf, reloc->sec, true); } =20 +#define RELOC_JUMP_TABLE_BIT 1UL + +/* Does reloc mark the beginning of a jump table? */ +static inline bool is_jump_table(struct reloc *reloc) +{ + return reloc->_sym_next_reloc & RELOC_JUMP_TABLE_BIT; +} + +static inline void set_jump_table(struct reloc *reloc) +{ + reloc->_sym_next_reloc |=3D RELOC_JUMP_TABLE_BIT; +} + +static inline struct reloc *sym_next_reloc(struct reloc *reloc) +{ + return (struct reloc *)(reloc->_sym_next_reloc & ~RELOC_JUMP_TABLE_BIT); +} + +static inline void set_sym_next_reloc(struct reloc *reloc, struct reloc *n= ext) +{ + unsigned long bit =3D reloc->_sym_next_reloc & RELOC_JUMP_TABLE_BIT; + + reloc->_sym_next_reloc =3D (unsigned long)next | bit; +} + #define for_each_sec(file, sec) \ list_for_each_entry(sec, &file->elf->sections, list) =20 --=20 2.48.1 From nobody Tue Dec 16 23:40:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C620B1EB5FE for ; Mon, 24 Mar 2025 21:56:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853382; cv=none; b=Xo2KSn4B+XG/ol6kDTaS47DYvKiscOMNzEYtrCO8H/WQL4eazK0if4thgGO4jIR4j5GPr5CP7o9xfaTnhcjx0uMPn0tfX/QNIH/s5MZkTCKOMiCFGUWwqNobmMKXmz8ZObG+/Xi/Z3+ztnNwpuAaeTYiHeutJzDQKHfD3vs2cCY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853382; c=relaxed/simple; bh=6oqZEdmgrvjphSWtepV7HXKe9va29XW99ADSgNxBjfM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dtu6s0vdEWY3kokA9+FlX6suysLIYdVvlEm+D3ihlYzaVvVd1ftV1tctRXC1S0INk5HVbar4uOtlE8Un/hOGyvUasAib2pImENk+e/n87MH5qrM4E+de65Yb5AKJTkFbBgkseX6RuP2plw7iJftEqkdwN5X50o8v2gHZfkq2hQs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uPdg1VWH; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uPdg1VWH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01E84C4CEEE; Mon, 24 Mar 2025 21:56:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742853382; bh=6oqZEdmgrvjphSWtepV7HXKe9va29XW99ADSgNxBjfM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uPdg1VWHpjXTbmbO70/1v9pEQAICdMjen9L+qY3Uy6wpRlS99AqXrfmjBhacOnPkw 1JmHoL37QEAgJGEl204jmNLVPgY5fl451IOy6rFilQVIHX//hcirYouChdQBRzNroJ G1NPkJ+VwPnXbHhX04MCRNEJzESxBDAJm/1zqvamhB8hDcrz9GCcGG7R3bPmld9t0H 8xpUZ7kdy/zuNxFxKcQ8f2NlEwegDG74DYFMpz3G52XCjXTi4xqrSziKSn1sO60a72 aY0Z2LVZKdDOPLIDPKIZb02IJxKnoa0KMbOOBsvMV+/OCO7Hu3jZ5uv8um1HGC17FO KmfBHALhUByXg== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Miroslav Benes , Brendan Jackman , Nathan Chancellor Subject: [PATCH 02/22] objtool: Warn when disabling unreachable warnings Date: Mon, 24 Mar 2025 14:55:52 -0700 Message-ID: X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Print a warning when disabling the unreachable warnings (due to a GCC bug). This will help determine if recent GCCs still have the issue and alert us if any other issues might be silently lurking behind the unreachable disablement. Signed-off-by: Josh Poimboeuf --- tools/objtool/arch/x86/special.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/objtool/arch/x86/special.c b/tools/objtool/arch/x86/spec= ial.c index 9c1c9df09aaa..5f46d4e7f7f8 100644 --- a/tools/objtool/arch/x86/special.c +++ b/tools/objtool/arch/x86/special.c @@ -3,6 +3,7 @@ =20 #include #include +#include =20 #define X86_FEATURE_POPCNT (4 * 32 + 23) #define X86_FEATURE_SMAP (9 * 32 + 20) @@ -156,8 +157,10 @@ struct reloc *arch_find_switch_table(struct objtool_fi= le *file, * indicates a rare GCC quirk/bug which can leave dead * code behind. */ - if (reloc_type(text_reloc) =3D=3D R_X86_64_PC32) + if (reloc_type(text_reloc) =3D=3D R_X86_64_PC32) { + WARN_INSN(insn, "ignoring unreachables due to jump table quirk"); file->ignore_unreachables =3D true; + } =20 *table_size =3D 0; return rodata_reloc; --=20 2.48.1 From nobody Tue Dec 16 23:40:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D538E1EB9EB for ; Mon, 24 Mar 2025 21:56:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853382; cv=none; b=BICKBE8hmSKRaxDFocnwrxwddFzXSQSDZPElswduknd51jiH2B7onrLNFVyQKZ8vr14B6Wlv0SdWBKq9GbGf4ei4PBzrIRR2IeUwEbK/WF7vYTYgHkddQM+rnFyeoNksfz4Z8uzpIzCPe6s+jtc0xVFcTkonsbq9wAFt469ahB4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853382; c=relaxed/simple; bh=fpWm/Nk43t3S1gA82488yS7GvdJhsQzb0TugYk58/dc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IpLvVZUme+0ZPQ83HfKFtu/aHRHpEgpG5h9V8JLJftq9FyqY7Y5dB+664k1R3oGOMFIjzH+SIQmDOI0O3+br7GOwBjcnuNsMfvLLzwwK1fjZVk9e1tkWgg84kjk9YEsXkNnO+qJWJPOmxFDPRu8/nQtzN/r1W08K3Ryw7Vhjt7Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oUwquHef; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oUwquHef" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FC0FC4CEEF; Mon, 24 Mar 2025 21:56:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742853382; bh=fpWm/Nk43t3S1gA82488yS7GvdJhsQzb0TugYk58/dc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oUwquHefWWoIZTUoHru8lrAlvTN1fEKsh7+YHGyIml/xuYyVcEzzc+RDJjPs/NQwa Rr9DoHaFlLJJCF+9V6ocW0Zqai430abMYPzRZW8Gmi9AerTcZJ6jer5/uVk2AQu6vC 55HQTMzVaJAmcqsxVW4Ei5sz7PxIRLLyOqUMxE337+x57E4M+OqcxxJXZQz5OUqIh0 KXFIfi5trX0i8VAz/l2qH3EWy/LBciDu3Pem1GZbdbqJEkmkWzcIIxbMFumXWqBO4l 27c0He77ZTBRREmL7FpBL9q4zcUYTi4jjNZ+pBudHo7jMIf+E7tiFDWm6Sz2zuJ1DA m1K7h0ltL44QQ== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Miroslav Benes , Brendan Jackman , Nathan Chancellor Subject: [PATCH 03/22] objtool: Ignore entire functions rather than instructions Date: Mon, 24 Mar 2025 14:55:53 -0700 Message-ID: <4af13376567f83331a9372ae2bb25e11a3d0f055.1742852846.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" STACK_FRAME_NON_STANDARD applies to functions. Use a function-specific ignore attribute in preparation for getting rid of insn->ignore. Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 35 +++++++++++++++-------------- tools/objtool/include/objtool/elf.h | 1 + 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 33beefd459a6..8e2f3405d78c 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -981,7 +981,6 @@ static int create_direct_call_sections(struct objtool_f= ile *file) */ static void add_ignores(struct objtool_file *file) { - struct instruction *insn; struct section *rsec; struct symbol *func; struct reloc *reloc; @@ -1008,8 +1007,7 @@ static void add_ignores(struct objtool_file *file) continue; } =20 - func_for_each_insn(file, func, insn) - insn->ignore =3D true; + func->ignore =3D true; } } =20 @@ -1620,6 +1618,7 @@ static int add_call_destinations(struct objtool_file = *file) struct reloc *reloc; =20 for_each_insn(file, insn) { + struct symbol *func =3D insn_func(insn); if (insn->type !=3D INSN_CALL) continue; =20 @@ -1630,7 +1629,7 @@ static int add_call_destinations(struct objtool_file = *file) =20 add_call_dest(file, insn, dest, false); =20 - if (insn->ignore) + if (func && func->ignore) continue; =20 if (!insn_call_dest(insn)) { @@ -1638,7 +1637,7 @@ static int add_call_destinations(struct objtool_file = *file) return -1; } =20 - if (insn_func(insn) && insn_call_dest(insn)->type !=3D STT_FUNC) { + if (func && insn_call_dest(insn)->type !=3D STT_FUNC) { WARN_INSN(insn, "unsupported call to non-function"); return -1; } @@ -3478,6 +3477,9 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, u8 visited; int ret; =20 + if (func && func->ignore) + return 0; + sec =3D insn->sec; =20 while (1) { @@ -3723,7 +3725,7 @@ static int validate_unwind_hint(struct objtool_file *= file, struct instruction *insn, struct insn_state *state) { - if (insn->hint && !insn->visited && !insn->ignore) { + if (insn->hint && !insn->visited) { int ret =3D validate_branch(file, insn_func(insn), insn, *state); if (ret) BT_INSN(insn, "<=3D=3D=3D (hint)"); @@ -3937,10 +3939,11 @@ static bool is_ubsan_insn(struct instruction *insn) =20 static bool ignore_unreachable_insn(struct objtool_file *file, struct inst= ruction *insn) { - int i; + struct symbol *func =3D insn_func(insn); struct instruction *prev_insn; + int i; =20 - if (insn->ignore || insn->type =3D=3D INSN_NOP || insn->type =3D=3D INSN_= TRAP) + if (insn->ignore || insn->type =3D=3D INSN_NOP || insn->type =3D=3D INSN_= TRAP || (func && func->ignore)) return true; =20 /* @@ -3959,7 +3962,7 @@ static bool ignore_unreachable_insn(struct objtool_fi= le *file, struct instructio * In this case we'll find a piece of code (whole function) that is not * covered by a !section symbol. Ignore them. */ - if (opts.link && !insn_func(insn)) { + if (opts.link && !func) { int size =3D find_symbol_hole_containing(insn->sec, insn->offset); unsigned long end =3D insn->offset + size; =20 @@ -3985,19 +3988,17 @@ static bool ignore_unreachable_insn(struct objtool_= file *file, struct instructio */ if (insn->jump_dest && insn_func(insn->jump_dest) && strstr(insn_func(insn->jump_dest)->name, ".cold")) { - struct instruction *dest =3D insn->jump_dest; - func_for_each_insn(file, insn_func(dest), dest) - dest->ignore =3D true; + insn_func(insn->jump_dest)->ignore =3D true; } } =20 return false; } =20 - if (!insn_func(insn)) + if (!func) return false; =20 - if (insn_func(insn)->static_call_tramp) + if (func->static_call_tramp) return true; =20 /* @@ -4028,7 +4029,7 @@ static bool ignore_unreachable_insn(struct objtool_fi= le *file, struct instructio =20 if (insn->type =3D=3D INSN_JUMP_UNCONDITIONAL) { if (insn->jump_dest && - insn_func(insn->jump_dest) =3D=3D insn_func(insn)) { + insn_func(insn->jump_dest) =3D=3D func) { insn =3D insn->jump_dest; continue; } @@ -4036,7 +4037,7 @@ static bool ignore_unreachable_insn(struct objtool_fi= le *file, struct instructio break; } =20 - if (insn->offset + insn->len >=3D insn_func(insn)->offset + insn_func(in= sn)->len) + if (insn->offset + insn->len >=3D func->offset + func->len) break; =20 insn =3D next_insn_same_sec(file, insn); @@ -4128,7 +4129,7 @@ static int validate_symbol(struct objtool_file *file,= struct section *sec, return 0; =20 insn =3D find_insn(file, sec, sym->offset); - if (!insn || insn->ignore || insn->visited) + if (!insn || insn->visited) return 0; =20 state->uaccess =3D sym->uaccess_safe; diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/ob= jtool/elf.h index 4edc957a6f6b..eba04392c6fd 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -68,6 +68,7 @@ struct symbol { u8 embedded_insn : 1; u8 local_label : 1; u8 frame_pointer : 1; + u8 ignore : 1; u8 warnings : 2; struct list_head pv_target; struct reloc *relocs; --=20 2.48.1 From nobody Tue Dec 16 23:40:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 B91521EE7AD for ; Mon, 24 Mar 2025 21:56:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853383; cv=none; b=O3FZTvAPJ8ElZ1PIKddfWSflQPt3YoO+FkNOw9K48v86Qjnti1tV4knZcSFhgAgLegPeNu00Sn5g4tBYDeXgtqsqOPPQJVeBxXa1iGg/VKZCscp6OBiOuovcLP0hTCxOeV/0gFtjaJKq8Lo4KYDUQfC2RGBdUnvP1zwsQHI04Tg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853383; c=relaxed/simple; bh=oKg4PMp9YXn1Ng8aPqaH+AE4nP+pk0Yy0+LvRr0vDWY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SQVQiTmgzdtbVxfMM1XkNEFZphJ0rfgRoMdQQP5jC9udPy5/VS5II4ME02fabZjImmPkg89vMZ+Xsl+xKLgpTmdXI12EyIsFytyRsW8RCEu6dJ+MbjUdcBKHSO3pcZqTieW/XFDo79vIs8UjKr/Uk3PzMqsPJ7RTprDN15JPbDA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lZpw+BNu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lZpw+BNu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DAA62C4CEE4; Mon, 24 Mar 2025 21:56:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742853383; bh=oKg4PMp9YXn1Ng8aPqaH+AE4nP+pk0Yy0+LvRr0vDWY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lZpw+BNu+o6hCS8+d1ZnVk76hdtzoZ7P2y6rz+SoLVNJmC1LKQQz0tmfOrzYxRT0r BBBcDb2sn4pvYh+ytPrmLTCnyk6lCjWYPgVa58v9YlY5EJdr5DRYxWXDLxCzcU3s0J wUiw4qDRFHlqNEVnuf6ITY4wir5/v9nTkwj9kz9c6Fv9HLSF3Nai8O4v9kKeSZM0Or WSdzm8MYuGc+XKROcG6LMb3H8VuHyGZA+sJ8YNgA+ytCvUpRzTeuEkfqWv9yTTI92u KeRG8Ym+Mf/0F/u7z0bFAXtjNpMj90K+zIgXCcGTKlaa4Qf6GSS0pG16ZD1qDDxXEZ KLh8te6ihMjeg== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Miroslav Benes , Brendan Jackman , Nathan Chancellor , kernel test robot Subject: [PATCH 04/22] objtool: Fix X86_FEATURE_SMAP alternative handling Date: Mon, 24 Mar 2025 14:55:54 -0700 Message-ID: X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For X86_FEATURE_SMAP alternatives which replace NOP with STAC or CLAC, uaccess validation skips the NOP branch to avoid following impossible code paths, e.g. where a STAC would be patched but a CLAC wouldn't. However, it's not safe to assume an X86_FEATURE_SMAP alternative is patching STAC/CLAC. There can be other alternatives, like static_cpu_has(), where both branches need to be validated. Fix that by repurposing ANNOTATE_IGNORE_ALTERNATIVE for skipping either original instructions or new ones. This is a more generic approach which enables the removal of the feature checking hacks and the insn->ignore bit. Fixes the following warnings: arch/x86/mm/fault.o: warning: objtool: do_user_addr_fault+0x8ec: __stack_= chk_fail() missing __noreturn in .c/.h or NORETURN() in noreturns.h arch/x86/mm/fault.o: warning: objtool: do_user_addr_fault+0x8f1: unreacha= ble instruction Fixes: ea24213d8088 ("objtool: Add UACCESS validation") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202503181736.zkZUBv4N-lkp@int= el.com/ Signed-off-by: Josh Poimboeuf --- arch/x86/include/asm/arch_hweight.h | 8 +++-- arch/x86/include/asm/smap.h | 23 ++++++++++----- arch/x86/include/asm/xen/hypercall.h | 6 ++-- tools/objtool/arch/x86/special.c | 33 +-------------------- tools/objtool/check.c | 39 +++++++------------------ tools/objtool/include/objtool/check.h | 3 +- tools/objtool/include/objtool/special.h | 4 +-- tools/objtool/special.c | 12 ++------ 8 files changed, 39 insertions(+), 89 deletions(-) diff --git a/arch/x86/include/asm/arch_hweight.h b/arch/x86/include/asm/arc= h_hweight.h index ba88edd0d58b..a0eaa8fda55f 100644 --- a/arch/x86/include/asm/arch_hweight.h +++ b/arch/x86/include/asm/arch_hweight.h @@ -16,7 +16,9 @@ static __always_inline unsigned int __arch_hweight32(unsi= gned int w) { unsigned int res; =20 - asm (ALTERNATIVE("call __sw_hweight32", "popcntl %1, %0", X86_FEATURE_POP= CNT) + asm (ALTERNATIVE(ANNOTATE_IGNORE_ALTERNATIVE + "call __sw_hweight32", + "popcntl %1, %0", X86_FEATURE_POPCNT) : "=3D"REG_OUT (res) : REG_IN (w)); =20 @@ -44,7 +46,9 @@ static __always_inline unsigned long __arch_hweight64(__u= 64 w) { unsigned long res; =20 - asm (ALTERNATIVE("call __sw_hweight64", "popcntq %1, %0", X86_FEATURE_POP= CNT) + asm (ALTERNATIVE(ANNOTATE_IGNORE_ALTERNATIVE + "call __sw_hweight64", + "popcntq %1, %0", X86_FEATURE_POPCNT) : "=3D"REG_OUT (res) : REG_IN (w)); =20 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h index 2de1e5a75c57..a984cdd6de30 100644 --- a/arch/x86/include/asm/smap.h +++ b/arch/x86/include/asm/smap.h @@ -16,23 +16,23 @@ #ifdef __ASSEMBLY__ =20 #define ASM_CLAC \ - ALTERNATIVE "", "clac", X86_FEATURE_SMAP + ALTERNATIVE __stringify(ANNOTATE_IGNORE_ALTERNATIVE), "clac", X86_FEATURE= _SMAP =20 #define ASM_STAC \ - ALTERNATIVE "", "stac", X86_FEATURE_SMAP + ALTERNATIVE __stringify(ANNOTATE_IGNORE_ALTERNATIVE), "stac", X86_FEATURE= _SMAP =20 #else /* __ASSEMBLY__ */ =20 static __always_inline void clac(void) { /* Note: a barrier is implicit in alternative() */ - alternative("", "clac", X86_FEATURE_SMAP); + alternative(ANNOTATE_IGNORE_ALTERNATIVE "", "clac", X86_FEATURE_SMAP); } =20 static __always_inline void stac(void) { /* Note: a barrier is implicit in alternative() */ - alternative("", "stac", X86_FEATURE_SMAP); + alternative(ANNOTATE_IGNORE_ALTERNATIVE "", "stac", X86_FEATURE_SMAP); } =20 static __always_inline unsigned long smap_save(void) @@ -40,7 +40,8 @@ static __always_inline unsigned long smap_save(void) unsigned long flags; =20 asm volatile ("# smap_save\n\t" - ALTERNATIVE("", "pushf; pop %0; " "clac" "\n\t", + ALTERNATIVE(ANNOTATE_IGNORE_ALTERNATIVE + "", "pushf; pop %0; clac", X86_FEATURE_SMAP) : "=3Drm" (flags) : : "memory", "cc"); =20 @@ -50,16 +51,22 @@ static __always_inline unsigned long smap_save(void) static __always_inline void smap_restore(unsigned long flags) { asm volatile ("# smap_restore\n\t" - ALTERNATIVE("", "push %0; popf\n\t", + ALTERNATIVE(ANNOTATE_IGNORE_ALTERNATIVE + "", "push %0; popf", X86_FEATURE_SMAP) : : "g" (flags) : "memory", "cc"); } =20 /* These macros can be used in asm() statements */ #define ASM_CLAC \ - ALTERNATIVE("", "clac", X86_FEATURE_SMAP) + ALTERNATIVE(ANNOTATE_IGNORE_ALTERNATIVE "", "clac", X86_FEATURE_SMAP) #define ASM_STAC \ - ALTERNATIVE("", "stac", X86_FEATURE_SMAP) + ALTERNATIVE(ANNOTATE_IGNORE_ALTERNATIVE "", "stac", X86_FEATURE_SMAP) + +#define ASM_CLAC_UNSAFE \ + ALTERNATIVE("", ANNOTATE_IGNORE_ALTERNATIVE "clac", X86_FEATURE_SMAP) +#define ASM_STAC_UNSAFE \ + ALTERNATIVE("", ANNOTATE_IGNORE_ALTERNATIVE "stac", X86_FEATURE_SMAP) =20 #endif /* __ASSEMBLY__ */ =20 diff --git a/arch/x86/include/asm/xen/hypercall.h b/arch/x86/include/asm/xe= n/hypercall.h index 97771b9d33af..59a62c3780a2 100644 --- a/arch/x86/include/asm/xen/hypercall.h +++ b/arch/x86/include/asm/xen/hypercall.h @@ -231,14 +231,12 @@ static __always_inline void __xen_stac(void) * Suppress objtool seeing the STAC/CLAC and getting confused about it * calling random code with AC=3D1. */ - asm volatile(ANNOTATE_IGNORE_ALTERNATIVE - ASM_STAC ::: "memory", "flags"); + asm volatile(ASM_STAC_UNSAFE ::: "memory", "flags"); } =20 static __always_inline void __xen_clac(void) { - asm volatile(ANNOTATE_IGNORE_ALTERNATIVE - ASM_CLAC ::: "memory", "flags"); + asm volatile(ASM_CLAC_UNSAFE ::: "memory", "flags"); } =20 static inline long diff --git a/tools/objtool/arch/x86/special.c b/tools/objtool/arch/x86/spec= ial.c index 5f46d4e7f7f8..403e587676f1 100644 --- a/tools/objtool/arch/x86/special.c +++ b/tools/objtool/arch/x86/special.c @@ -5,10 +5,7 @@ #include #include =20 -#define X86_FEATURE_POPCNT (4 * 32 + 23) -#define X86_FEATURE_SMAP (9 * 32 + 20) - -void arch_handle_alternative(unsigned short feature, struct special_alt *a= lt) +void arch_handle_alternative(struct special_alt *alt) { static struct special_alt *group, *prev; =20 @@ -32,34 +29,6 @@ void arch_handle_alternative(unsigned short feature, str= uct special_alt *alt) } else group =3D alt; =20 prev =3D alt; - - switch (feature) { - case X86_FEATURE_SMAP: - /* - * If UACCESS validation is enabled; force that alternative; - * otherwise force it the other way. - * - * What we want to avoid is having both the original and the - * alternative code flow at the same time, in that case we can - * find paths that see the STAC but take the NOP instead of - * CLAC and the other way around. - */ - if (opts.uaccess) - alt->skip_orig =3D true; - else - alt->skip_alt =3D true; - break; - case X86_FEATURE_POPCNT: - /* - * It has been requested that we don't validate the !POPCNT - * feature path which is a "very very small percentage of - * machines". - */ - alt->skip_orig =3D true; - break; - default: - break; - } } =20 bool arch_support_alt_relocation(struct special_alt *special_alt, diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 8e2f3405d78c..bac88ca82dec 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -25,7 +25,6 @@ struct alternative { struct alternative *next; struct instruction *insn; - bool skip_orig; }; =20 static unsigned long nr_cfi, nr_cfi_reused, nr_cfi_cache; @@ -1704,6 +1703,7 @@ static int handle_group_alt(struct objtool_file *file, orig_alt_group->first_insn =3D orig_insn; orig_alt_group->last_insn =3D last_orig_insn; orig_alt_group->nop =3D NULL; + orig_alt_group->ignore =3D orig_insn->ignore_alts; } else { if (orig_alt_group->last_insn->offset + orig_alt_group->last_insn->len - orig_alt_group->first_insn->offset !=3D special_alt->orig_len) { @@ -1743,7 +1743,6 @@ static int handle_group_alt(struct objtool_file *file, nop->type =3D INSN_NOP; nop->sym =3D orig_insn->sym; nop->alt_group =3D new_alt_group; - nop->ignore =3D orig_insn->ignore_alts; } =20 if (!special_alt->new_len) { @@ -1760,7 +1759,6 @@ static int handle_group_alt(struct objtool_file *file, =20 last_new_insn =3D insn; =20 - insn->ignore =3D orig_insn->ignore_alts; insn->sym =3D orig_insn->sym; insn->alt_group =3D new_alt_group; =20 @@ -1807,6 +1805,7 @@ static int handle_group_alt(struct objtool_file *file, new_alt_group->first_insn =3D *new_insn; new_alt_group->last_insn =3D last_new_insn; new_alt_group->nop =3D nop; + new_alt_group->ignore =3D (*new_insn)->ignore_alts; new_alt_group->cfi =3D orig_alt_group->cfi; return 0; } @@ -1924,8 +1923,6 @@ static int add_special_section_alts(struct objtool_fi= le *file) } =20 alt->insn =3D new_insn; - alt->skip_orig =3D special_alt->skip_orig; - orig_insn->ignore_alts |=3D special_alt->skip_alt; alt->next =3D orig_insn->alts; orig_insn->alts =3D alt; =20 @@ -2303,6 +2300,8 @@ static int read_annotate(struct objtool_file *file, static int __annotate_early(struct objtool_file *file, int type, struct in= struction *insn) { switch (type) { + + /* Must be before add_special_section_alts() */ case ANNOTYPE_IGNORE_ALTS: insn->ignore_alts =3D true; break; @@ -3496,11 +3495,6 @@ static int validate_branch(struct objtool_file *file= , struct symbol *func, return 1; } =20 - if (func && insn->ignore) { - WARN_INSN(insn, "BUG: why am I validating an ignored function?"); - return 1; - } - visited =3D VISITED_BRANCH << state.uaccess; if (insn->visited & VISITED_BRANCH_MASK) { if (!insn->hint && !insn_cfi_match(insn, &state.cfi)) @@ -3572,24 +3566,19 @@ static int validate_branch(struct objtool_file *fil= e, struct symbol *func, if (propagate_alt_cfi(file, insn)) return 1; =20 - if (!insn->ignore_alts && insn->alts) { - bool skip_orig =3D false; - + if (insn->alts) { for (alt =3D insn->alts; alt; alt =3D alt->next) { - if (alt->skip_orig) - skip_orig =3D true; - ret =3D validate_branch(file, func, alt->insn, state); if (ret) { BT_INSN(insn, "(alt)"); return ret; } } - - if (skip_orig) - return 0; } =20 + if (insn->alt_group && insn->alt_group->ignore) + return 0; + if (handle_insn_ops(insn, next_insn, &state)) return 1; =20 @@ -3776,23 +3765,15 @@ static int validate_unret(struct objtool_file *file= , struct instruction *insn) =20 insn->visited |=3D VISITED_UNRET; =20 - if (!insn->ignore_alts && insn->alts) { + if (insn->alts) { struct alternative *alt; - bool skip_orig =3D false; - for (alt =3D insn->alts; alt; alt =3D alt->next) { - if (alt->skip_orig) - skip_orig =3D true; - ret =3D validate_unret(file, alt->insn); if (ret) { BT_INSN(insn, "(alt)"); return ret; } } - - if (skip_orig) - return 0; } =20 switch (insn->type) { @@ -3943,7 +3924,7 @@ static bool ignore_unreachable_insn(struct objtool_fi= le *file, struct instructio struct instruction *prev_insn; int i; =20 - if (insn->ignore || insn->type =3D=3D INSN_NOP || insn->type =3D=3D INSN_= TRAP || (func && func->ignore)) + if (insn->type =3D=3D INSN_NOP || insn->type =3D=3D INSN_TRAP || (func &&= func->ignore)) return true; =20 /* diff --git a/tools/objtool/include/objtool/check.h b/tools/objtool/include/= objtool/check.h index e1cd13cd28a3..00fb745e7233 100644 --- a/tools/objtool/include/objtool/check.h +++ b/tools/objtool/include/objtool/check.h @@ -34,6 +34,8 @@ struct alt_group { * This is shared with the other alt_groups in the same alternative. */ struct cfi_state **cfi; + + bool ignore; }; =20 #define INSN_CHUNK_BITS 8 @@ -54,7 +56,6 @@ struct instruction { =20 u32 idx : INSN_CHUNK_BITS, dead_end : 1, - ignore : 1, ignore_alts : 1, hint : 1, save : 1, diff --git a/tools/objtool/include/objtool/special.h b/tools/objtool/includ= e/objtool/special.h index e049679bb17b..72d09c0adf1a 100644 --- a/tools/objtool/include/objtool/special.h +++ b/tools/objtool/include/objtool/special.h @@ -16,8 +16,6 @@ struct special_alt { struct list_head list; =20 bool group; - bool skip_orig; - bool skip_alt; bool jump_or_nop; u8 key_addend; =20 @@ -32,7 +30,7 @@ struct special_alt { =20 int special_get_alts(struct elf *elf, struct list_head *alts); =20 -void arch_handle_alternative(unsigned short feature, struct special_alt *a= lt); +void arch_handle_alternative(struct special_alt *alt); =20 bool arch_support_alt_relocation(struct special_alt *special_alt, struct instruction *insn, diff --git a/tools/objtool/special.c b/tools/objtool/special.c index 097a69db82a0..6cd7b1be5331 100644 --- a/tools/objtool/special.c +++ b/tools/objtool/special.c @@ -54,7 +54,7 @@ static const struct special_entry entries[] =3D { {}, }; =20 -void __weak arch_handle_alternative(unsigned short feature, struct special= _alt *alt) +void __weak arch_handle_alternative(struct special_alt *alt) { } =20 @@ -92,15 +92,7 @@ static int get_alt_entry(struct elf *elf, const struct s= pecial_entry *entry, =20 reloc_to_sec_off(orig_reloc, &alt->orig_sec, &alt->orig_off); =20 - if (entry->feature) { - unsigned short feature; - - feature =3D bswap_if_needed(elf, - *(unsigned short *)(sec->data->d_buf + - offset + - entry->feature)); - arch_handle_alternative(feature, alt); - } + arch_handle_alternative(alt); =20 if (!entry->group || alt->new_len) { new_reloc =3D find_reloc_by_dest(elf, sec, offset + entry->new); --=20 2.48.1 From nobody Tue Dec 16 23:40:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 3098C1EEA4E for ; Mon, 24 Mar 2025 21:56:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853384; cv=none; b=bZSTKIYHLonbSd3UacnnUT9mvs1foG5PkiT3ygK1Xr+yuIMt0WnLVSRQ/Gf+IRGGiukcdd6V9fOm42YppnDiuglP7ASb6A+d7WvL+8jxCwNcWWBMOcUjuZ93/tByHcKyzIkknZqNvNbxP/YpfqDSA5bjpUjdjLtPMKiAa392lg8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853384; c=relaxed/simple; bh=8Ap9V/RlNIssun8Y8rlPm0xiQ7oHWF3BU3WjU1FXwVk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eQ561sGzZmaDBesWlQF+/bzzJPuqOqAtNZfv5xpH8O8qdotrsj76v/iCJK5WP6EbETMouXhArsCkkCLaT5ivWZE2JjMJRRbqon2bvDdE+uF10iUa2ki5S8YFkgr7gL0lir27OmIjS/Jl7zXm9+3q8JbgVlSb7aisTMXzupkfJ6M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GCQ02pMh; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GCQ02pMh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D374C4CEF0; Mon, 24 Mar 2025 21:56:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742853383; bh=8Ap9V/RlNIssun8Y8rlPm0xiQ7oHWF3BU3WjU1FXwVk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GCQ02pMhH44AtMZMl/GmAjSwhqTcAG8hK2sytOGbAUkOSVY59AZnZwGiqFtXtoPqd 31PpTg693vjeOT7EVXAgpkYeWzXs1gRBG09EnCOgCC9zgNg5Ndi8AonhgRO2JT6p+R 5J8iXJ64aCIckW3HB//m1IyPALm+o90BngoYDD8clUCUnYnxsKsmmjk2ZE/VuG0QBJ XcE2U8h/dPAf0kgQg7nF5HremAz00tZCWBOY8bTVDTWhUFfUgoDl4ePrYmhHGtnZBN fIz2Pf6UkKjDq1Oh4XAOvYuciPSFFygD8GWoktlCca1IGoCuyQ+ieDuIh9lLkumvuC 0YHCWZDz1bF4A== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Miroslav Benes , Brendan Jackman , Nathan Chancellor Subject: [PATCH 05/22] objtool: Fix CONFIG_OBJTOOL_WERROR for vmlinux.o Date: Mon, 24 Mar 2025 14:55:55 -0700 Message-ID: <4f71ab9b947ffc47b6a87dd3b9aff4bb32b36d0a.1742852846.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With (!X86_KERNEL_IBT && !LTO_CLANG && NOINSTR_VALIDATION), objtool runs on both translation units and vmlinux.o. With CONFIG_OBJTOOL_WERROR, the TUs get --Werror but vmlinux.o doesn't. Fix that. Signed-off-by: Josh Poimboeuf --- scripts/Makefile.vmlinux_o | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/scripts/Makefile.vmlinux_o b/scripts/Makefile.vmlinux_o index 0b6e2ebf60dc..f476f5605029 100644 --- a/scripts/Makefile.vmlinux_o +++ b/scripts/Makefile.vmlinux_o @@ -30,12 +30,20 @@ endif # objtool for vmlinux.o # ------------------------------------------------------------------------= --- # -# For LTO and IBT, objtool doesn't run on individual translation units. -# Run everything on vmlinux instead. +# For delay-objtool (IBT or LTO), objtool doesn't run on individual transl= ation +# units. Instead it runs on vmlinux.o. +# +# For !delay-objtool + CONFIG_NOINSTR_VALIDATION, it runs on both translat= ion +# units and vmlinux.o, with the latter only used for noinstr/unret validat= ion. =20 objtool-enabled :=3D $(or $(delay-objtool),$(CONFIG_NOINSTR_VALIDATION)) =20 -vmlinux-objtool-args-$(delay-objtool) +=3D $(objtool-args-y) +ifeq ($(delay-objtool),y) +vmlinux-objtool-args-y +=3D $(objtool-args-y) +else +vmlinux-objtool-args-$(CONFIG_OBJTOOL_WERROR) +=3D --Werror +endif + vmlinux-objtool-args-$(CONFIG_GCOV_KERNEL) +=3D --no-unreachable vmlinux-objtool-args-$(CONFIG_NOINSTR_VALIDATION) +=3D --noinstr \ $(if $(or $(CONFIG_MITIGATION_UNRET_ENTRY),$(CONFIG_MITIGATION_S= RSO)), --unret) --=20 2.48.1 From nobody Tue Dec 16 23:40:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 3A4831EF084 for ; Mon, 24 Mar 2025 21:56:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853384; cv=none; b=SUZTt4OsNIt2dpsJrZHZ1uNWrVxeJHftbn4udHvIsQZkisXIOFN/CARKpyACZ+W5QSuriUOVQsGboX8O6xr1EPOBqtaO18ynk7hDBsIPzkj/lFv7SqzD8ioP0aZqXTUj9qT0iJ76aDotCQ9vQcpx3R0EI2QzpLvBWBxFZDMm0RE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853384; c=relaxed/simple; bh=uc7Pk6gShU8z9EP+FaeNJKnbU7Tk2Rys/5jL1sospsc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nAs+6+RnQd5ov3Z0IkknTYYA4VNAD8FWCGXmDsnNMBPdtqVffhHzukcBOpCwFK2SK1CrbrcHhH1Dc94O0G45hD7qC6PEakpRg7HgIrDsGob5i7HE3w79uArRsbXUm0TlKmfLp5sEqZFKhRxmT3VSnPpockYWI28PnHRJO1O9gL0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ohOrKSOF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ohOrKSOF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA3EAC4CEF2; Mon, 24 Mar 2025 21:56:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742853384; bh=uc7Pk6gShU8z9EP+FaeNJKnbU7Tk2Rys/5jL1sospsc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ohOrKSOFm9abZ+QWHS356IUANj2s4DgA+rXbj7gbNU71B6QYSHjV/WxC+j9CMDEqT LedqdkjnoSv903r77BXkRJpIRrK5Bm/BnkaK7n5VMxzQsEtOG8XCr6yx2+G+pff2b5 LsuGwnWC5tO9QrnTudTLDwRH1wB4dSsu6xsAbJpjwjqy5I6f4I9BmEd8fwn6XU+upa uR7eVzX6XFZ/bOkb1DVPiaq6qCsJFI3pjGLNL5BBY6JO/kM4arr/aoiBQL+lE90XS7 W7k0U2hxI2j8BkcO1yA0VIcF2AMRdsDM/w2w4yb1ftdzq895KF2PTAL9MWWur1JAik jip2bDU8lphOA== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Miroslav Benes , Brendan Jackman , Nathan Chancellor Subject: [PATCH 06/22] objtool: Fix init_module() handling Date: Mon, 24 Mar 2025 14:55:56 -0700 Message-ID: <366bfdbe92736cde9fb01d5d3eb9b98e9070a1ec.1742852846.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If IBT is enabled and a module uses the deprecated init_module() magic function name rather than module_init(fn), its ENDBR will get removed, causing an IBT failure during module load. Objtool does print an obscure warning, but then does nothing to either correct it or return an error. Improve the usefulness of the warning and return an error so it will at least fail the build with CONFIG_OBJTOOL_WERROR. Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index bac88ca82dec..8edb7044f7fc 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -828,8 +828,11 @@ static int create_ibt_endbr_seal_sections(struct objto= ol_file *file) if (opts.module && sym && sym->type =3D=3D STT_FUNC && insn->offset =3D=3D sym->offset && (!strcmp(sym->name, "init_module") || - !strcmp(sym->name, "cleanup_module"))) - WARN("%s(): not an indirect call target", sym->name); + !strcmp(sym->name, "cleanup_module"))) { + WARN("%s(): Magic init_module() function name is deprecated, use module= _init(fn) instead", + sym->name); + return -1; + } =20 if (!elf_init_reloc_text_sym(file->elf, sec, idx * sizeof(int), idx, --=20 2.48.1 From nobody Tue Dec 16 23:40:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 07F111EFFBE for ; Mon, 24 Mar 2025 21:56:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853385; cv=none; b=KDCdNBVF2EJreXg1PuWO8SroHxAXIKi0wDykwD/TUw0DCdknCL/FzxBQgfLDRv9XaiXCqYNuc87qTlIgHhefqvDw+2XOnzGgH2MVPSzDC3N+GUF4/nul3MIiAAN8wiayGq10Y9ghak/8FJK0rEzvJRUJAmnhQ1ZQjNYZWkY8Ghc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853385; c=relaxed/simple; bh=hYjLeGv1GkKqvO/3TQGk13kouupJ6pyWS4PiJFO8iEI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E9w4Neeq/vMHpxKvZXfG8w/YXDqcRbioP2dqjwAZ2XvcmMnt9IxAQQygrTid011pB/1H3kHP5JdzyYderJpx8z9ARzTnr8l7r2BseAlS/tDpK0lV9AuhfWhHVps633rC140x2eDRSp7eunSpVQwLDLLvQKZ5X/1VLsEaKf1NOgg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=F8GiW27+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="F8GiW27+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4282CC4CEED; Mon, 24 Mar 2025 21:56:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742853384; bh=hYjLeGv1GkKqvO/3TQGk13kouupJ6pyWS4PiJFO8iEI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F8GiW27+srWSwFYmW38fSfbLGXe0B6FS61HbUHKWFn3uYg9jHUHoCo3blpcz2GgW+ VJM+3QIkmDqhvMoBdoxtjY9bvm+QWiB+V0bL2/s50ZJ2lGpH6aqukcE+P0xJRpDJOr fFjO4ZQe4V+DQ+EAuqdgzI/cPa3m22YQjP+tNrwgzASNqSYfqOoMcEP+TaTqoDmz15 oisiVqIOe6AONnmzGrC2tK44AkVRpD3pYJ9sawsyYZ3095BPsMu+67+2F6vd9RuMlp ZCUzsjCpWvuSTHQ1SSnDlpF5BOQU6kuxgtZIpl83BGBkL1ipY+BhnFEArfRGqKJhYv B2/HcAUNCv5Mg== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Miroslav Benes , Brendan Jackman , Nathan Chancellor , kernel test robot Subject: [PATCH 07/22] objtool: Silence more KCOV warnings Date: Mon, 24 Mar 2025 14:55:57 -0700 Message-ID: <66a61a0b65d74e072d3dc02384e395edb2adc3c5.1742852846.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In the past there were issues with KCOV triggering unreachable instruction warnings, which is why unreachable warnings are now disabled with CONFIG_KCOV. Now some new KCOV warnings are showing up with GCC 14: vmlinux.o: warning: objtool: cpuset_write_resmask() falls through to next= function cpuset_update_active_cpus.cold() drivers/usb/core/driver.o: error: objtool: usb_deregister() falls through= to next function usb_match_device() sound/soc/codecs/snd-soc-wcd934x.o: warning: objtool: .text.wcd934x_slim_= irq_handler: unexpected end of section All are caused by GCC KCOV not finishing an optimization, leaving behind a never-taken conditional branch to a basic block which falls through to the next function (or end of section). At a high level this is similar to the unreachable warnings mentioned above, in that KCOV isn't fully removing dead code. Treat it the same way by adding these to the list of warnings to ignore with CONFIG_KCOV. Reported-by: Ingo Molnar Closes: https://lore.kernel.org/Z9iTsI09AEBlxlHC@gmail.com Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202503180044.oH9gyPeg-lkp@int= el.com/ Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 8edb7044f7fc..032b3be409f2 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3493,6 +3493,9 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, !strncmp(func->name, "__pfx_", 6)) return 0; =20 + if (file->ignore_unreachables) + return 0; + WARN("%s() falls through to next function %s()", func->name, insn_func(insn)->name); return 1; @@ -3702,6 +3705,9 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, if (!next_insn) { if (state.cfi.cfa.base =3D=3D CFI_UNDEFINED) return 0; + if (file->ignore_unreachables) + return 0; + WARN("%s: unexpected end of section", sec->name); return 1; } --=20 2.48.1 From nobody Tue Dec 16 23:40:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 808EB1F09B4 for ; Mon, 24 Mar 2025 21:56:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853385; cv=none; b=dFZg4vgHBzxLW8L67JqE5BZbX2tDmED5u/dJmq4L8aB04NLLT3eoLy8z6UPJARfkGBtm0Dgd6src6YoLFfCjUQY6nNMkGm1imXB7AcM2mDZnwcWqUQ9bQNIQ3ZdR0YrmmnkYJqrCt+qzgMAYCMjpTF4SdU+z6w7dg6AL78pS0CM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853385; c=relaxed/simple; bh=9KzMx8OrH5KiE28WpHpZyYhsLXyYJsiCVOCb8tcq390=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jztuw6UePEWBd62xfFzn0QOZW6j0+ISuy6SjTDFgBA7mYY0Ar62wdRhidu62jBsnUFsdXv3ZoNgn0CwBRrDa85SKhRrHf/7ecsH4alNPdpu7LA+o1iWqNA0On2tk1a+S04DrcNrArElvuEYoLZxFx2Ie5q24p/AJrW/ALMPE8Ro= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=l34lNBNN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="l34lNBNN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4C52C4CEDD; Mon, 24 Mar 2025 21:56:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742853385; bh=9KzMx8OrH5KiE28WpHpZyYhsLXyYJsiCVOCb8tcq390=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l34lNBNNFttCdH7gl+2VjvFRZVOY+rWDnpDBU5QnfhOUvrfuGGWDNCc3cu95wktpl tV3nvB37cJyz57FZ2bRLZmdqPKIk1ZvMmvn8t2KKoXFEnGevY3NpFbvFbKlY5omHpu qDAV+vXSnTfrZVGil3VXYNNh2hxm6g/lwNtthFYpBP9qfINBB9G1fMcWz3+AYqgXvL sdWu+GgZU13fJsY+xJ2zBtIgVa7BJ8QzZr0SFqrVYcHoofieKYgsFWrKHKiB8v43qv 8SX2CIp85e0/1NT/5tJZefUvYgHPrPsPqr9KITH6p2swGI/YzyBm2hIBL7MceSaGEt lxykG0Lwfh9iw== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Miroslav Benes , Brendan Jackman , Nathan Chancellor Subject: [PATCH 08/22] objtool: Properly disable uaccess validation Date: Mon, 24 Mar 2025 14:55:58 -0700 Message-ID: <0e95581c1d2107fb5f59418edf2b26bba38b0cbb.1742852846.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If opts.uaccess isn't set, the uaccess validation is disabled, but only partially: it doesn't read the uaccess_safe_builtin list but still tries to do the validation. Disable it completely to prevent false warnings. Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 032b3be409f2..3966fc81a77e 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3195,7 +3195,7 @@ static int handle_insn_ops(struct instruction *insn, if (update_cfi_state(insn, next_insn, &state->cfi, op)) return 1; =20 - if (!insn->alt_group) + if (!opts.uaccess || !insn->alt_group) continue; =20 if (op->dest.type =3D=3D OP_DEST_PUSHF) { @@ -3655,6 +3655,9 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, return 0; =20 case INSN_STAC: + if (!opts.uaccess) + break; + if (state.uaccess) { WARN_INSN(insn, "recursive UACCESS enable"); return 1; @@ -3664,6 +3667,9 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, break; =20 case INSN_CLAC: + if (!opts.uaccess) + break; + if (!state.uaccess && func) { WARN_INSN(insn, "redundant UACCESS disable"); return 1; @@ -4122,7 +4128,8 @@ static int validate_symbol(struct objtool_file *file,= struct section *sec, if (!insn || insn->visited) return 0; =20 - state->uaccess =3D sym->uaccess_safe; + if (opts.uaccess) + state->uaccess =3D sym->uaccess_safe; =20 ret =3D validate_branch(file, insn_func(insn), insn, *state); if (ret) --=20 2.48.1 From nobody Tue Dec 16 23:40:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 989141F0E33 for ; Mon, 24 Mar 2025 21:56:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853385; cv=none; b=E9Y+/49q7sYhbskZmbmAmm6QFMve4BqSIakSezOwOFrYLnYyqxFBvPxJLCcaU1/sJYc+D/dFRSg6uO3W2qh5uNOZaNkW2LX+bdrdgnKTIsiI+sDavKFwHspqRlTdQdDweeVFBrV0pKmsn5or6rqqJj8jaE0/wrzy+5OD07cdLw4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853385; c=relaxed/simple; bh=htKuAgBtxznk8XoKZ/fdDpVaxG/T+dMhv3XQNAQjdaY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j4eBpIasRUrW81oVNNPDVjGjjLWptM5WmT2P4/z3TMCzrDSEW6iDREff/mnKxWqWtD6qWoxztKLeCbWqQem/QLCQwaJz8r/B+xJiklMrAw/RWUQMQFQCIwNXIcL/ARxT7Iy5VwQ+nmzkSvGadsdAo+WGoSgShE2uFv/U99oQg8c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OIGBRRpP; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OIGBRRpP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D0B3C4CEED; Mon, 24 Mar 2025 21:56:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742853385; bh=htKuAgBtxznk8XoKZ/fdDpVaxG/T+dMhv3XQNAQjdaY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OIGBRRpPcoSKUudNP1yKTBSw8t5ViV2P4e13+4YbxQOZebUh59d4Bd3O17M+2M3fW l2JopXAAMoLbCCQiUw4P9UbfDnWj5k10OvpFAQN+tgXf6S9iWHvN28TZU+UmaiKBc1 xgXuvOTO+RIiIJaBDMCm6IziKd1qUMrzt3QpPCJWCh+MSJE8cuVScdtJ5Lm7UoHAOX RhhHyLGVPcb9HJ27VZMf+DHqs1o75H2Bt/UGZpO6Yum/iNLpkdbC5v1WUdnQWtEgG5 mDgGAmammvroj1DpHULUYKyrVHStoHHyUnUXh0BZZS4F1sW/dMyjqCyxi9WRNhEjFm Q5Un0WmAt3PeQ== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Miroslav Benes , Brendan Jackman , Nathan Chancellor Subject: [PATCH 09/22] objtool: Improve error handling Date: Mon, 24 Mar 2025 14:55:59 -0700 Message-ID: <3094bb4463dad29b6bd1bea03848d1571ace771c.1742852846.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Fix some error handling issues, improve error messages, properly distinguish betwee errors and warnings, and generally try to make all the error handling more consistent. Signed-off-by: Josh Poimboeuf --- tools/objtool/builtin-check.c | 37 ++- tools/objtool/check.c | 370 ++++++++++++------------ tools/objtool/elf.c | 22 +- tools/objtool/include/objtool/objtool.h | 2 +- tools/objtool/include/objtool/warn.h | 13 +- tools/objtool/objtool.c | 11 +- 6 files changed, 233 insertions(+), 222 deletions(-) diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index 5f761f420b8c..c973a751fb7d 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -8,15 +8,12 @@ #include #include #include +#include #include #include #include #include - -#define ERROR(format, ...) \ - fprintf(stderr, \ - "error: objtool: " format "\n", \ - ##__VA_ARGS__) +#include =20 const char *objname; =20 @@ -139,22 +136,22 @@ int cmd_parse_options(int argc, const char **argv, co= nst char * const usage[]) static bool opts_valid(void) { if (opts.mnop && !opts.mcount) { - ERROR("--mnop requires --mcount"); + WARN("--mnop requires --mcount"); return false; } =20 if (opts.noinstr && !opts.link) { - ERROR("--noinstr requires --link"); + WARN("--noinstr requires --link"); return false; } =20 if (opts.ibt && !opts.link) { - ERROR("--ibt requires --link"); + WARN("--ibt requires --link"); return false; } =20 if (opts.unret && !opts.link) { - ERROR("--unret requires --link"); + WARN("--unret requires --link"); return false; } =20 @@ -171,7 +168,7 @@ static bool opts_valid(void) opts.static_call || opts.uaccess) { if (opts.dump_orc) { - ERROR("--dump can't be combined with other actions"); + WARN("--dump can't be combined with other actions"); return false; } =20 @@ -181,7 +178,7 @@ static bool opts_valid(void) if (opts.dump_orc) return true; =20 - ERROR("At least one action required"); + WARN("At least one action required"); return false; } =20 @@ -194,30 +191,30 @@ static int copy_file(const char *src, const char *dst) =20 src_fd =3D open(src, O_RDONLY); if (src_fd =3D=3D -1) { - ERROR("can't open '%s' for reading", src); + WARN("can't open %s for reading: %s", src, strerror(errno)); return 1; } =20 dst_fd =3D open(dst, O_WRONLY | O_CREAT | O_TRUNC, 0400); if (dst_fd =3D=3D -1) { - ERROR("can't open '%s' for writing", dst); + WARN("can't open %s for writing: %s", dst, strerror(errno)); return 1; } =20 if (fstat(src_fd, &stat) =3D=3D -1) { - perror("fstat"); + WARN_GLIBC("fstat"); return 1; } =20 if (fchmod(dst_fd, stat.st_mode) =3D=3D -1) { - perror("fchmod"); + WARN_GLIBC("fchmod"); return 1; } =20 for (to_copy =3D stat.st_size; to_copy > 0; to_copy -=3D copied) { copied =3D sendfile(dst_fd, src_fd, &offset, to_copy); if (copied =3D=3D -1) { - perror("sendfile"); + WARN_GLIBC("sendfile"); return 1; } } @@ -233,14 +230,14 @@ static char **save_argv(int argc, const char **argv) =20 orig_argv =3D calloc(argc, sizeof(char *)); if (!orig_argv) { - perror("calloc"); + WARN_GLIBC("calloc"); return NULL; } =20 for (int i =3D 0; i < argc; i++) { orig_argv[i] =3D strdup(argv[i]); if (!orig_argv[i]) { - perror("strdup"); + WARN_GLIBC("strdup(%s)", orig_argv[i]); return NULL; } }; @@ -285,7 +282,7 @@ int objtool_run(int argc, const char **argv) goto err; =20 if (!opts.link && has_multiple_files(file->elf)) { - ERROR("Linked object requires --link"); + WARN("Linked object requires --link"); goto err; } =20 @@ -313,7 +310,7 @@ int objtool_run(int argc, const char **argv) */ backup =3D malloc(strlen(objname) + strlen(ORIG_SUFFIX) + 1); if (!backup) { - perror("malloc"); + WARN_GLIBC("malloc"); return 1; } =20 diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 3966fc81a77e..fbe2a5ef2c40 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -353,7 +353,7 @@ static struct cfi_state *cfi_alloc(void) { struct cfi_state *cfi =3D calloc(1, sizeof(struct cfi_state)); if (!cfi) { - WARN("calloc failed"); + WARN_GLIBC("calloc"); exit(1); } nr_cfi++; @@ -409,7 +409,7 @@ static void *cfi_hash_alloc(unsigned long size) PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0); if (cfi_hash =3D=3D (void *)-1L) { - WARN("mmap fail cfi_hash"); + WARN_GLIBC("mmap fail cfi_hash"); cfi_hash =3D NULL; } else if (opts.stats) { printf("cfi_bits: %d\n", cfi_bits); @@ -465,7 +465,7 @@ static int decode_instructions(struct objtool_file *fil= e) if (!insns || idx =3D=3D INSN_CHUNK_MAX) { insns =3D calloc(sizeof(*insn), INSN_CHUNK_SIZE); if (!insns) { - WARN("malloc failed"); + WARN_GLIBC("calloc"); return -1; } idx =3D 0; @@ -567,14 +567,21 @@ static int add_pv_ops(struct objtool_file *file, cons= t char *symname) if (!reloc) break; =20 + idx =3D (reloc_offset(reloc) - sym->offset) / sizeof(unsigned long); + func =3D reloc->sym; if (func->type =3D=3D STT_SECTION) func =3D find_symbol_by_offset(reloc->sym->sec, reloc_addend(reloc)); + if (!func) { + WARN_FUNC("can't find func at %s[%d]", + reloc->sym->sec, reloc_addend(reloc), + symname, idx); + return -1; + } =20 - idx =3D (reloc_offset(reloc) - sym->offset) / sizeof(unsigned long); - - objtool_pv_add(file, idx, func); + if (objtool_pv_add(file, idx, func)) + return -1; =20 off =3D reloc_offset(reloc) + 1; if (off > end) @@ -598,7 +605,7 @@ static int init_pv_ops(struct objtool_file *file) }; const char *pv_ops; struct symbol *sym; - int idx, nr; + int idx, nr, ret; =20 if (!opts.noinstr) return 0; @@ -611,14 +618,19 @@ static int init_pv_ops(struct objtool_file *file) =20 nr =3D sym->len / sizeof(unsigned long); file->pv_ops =3D calloc(sizeof(struct pv_state), nr); - if (!file->pv_ops) + if (!file->pv_ops) { + WARN_GLIBC("calloc"); return -1; + } =20 for (idx =3D 0; idx < nr; idx++) INIT_LIST_HEAD(&file->pv_ops[idx].targets); =20 - for (idx =3D 0; (pv_ops =3D pv_ops_tables[idx]); idx++) - add_pv_ops(file, pv_ops); + for (idx =3D 0; (pv_ops =3D pv_ops_tables[idx]); idx++) { + ret =3D add_pv_ops(file, pv_ops); + if (ret) + return ret; + } =20 return 0; } @@ -666,13 +678,12 @@ static int create_static_call_sections(struct objtool= _file *file) /* find key symbol */ key_name =3D strdup(insn_call_dest(insn)->name); if (!key_name) { - perror("strdup"); + WARN_GLIBC("strdup"); return -1; } if (strncmp(key_name, STATIC_CALL_TRAMP_PREFIX_STR, STATIC_CALL_TRAMP_PREFIX_LEN)) { WARN("static_call: trampoline name malformed: %s", key_name); - free(key_name); return -1; } tmp =3D key_name + STATIC_CALL_TRAMP_PREFIX_LEN - STATIC_CALL_KEY_PREFIX= _LEN; @@ -682,7 +693,6 @@ static int create_static_call_sections(struct objtool_f= ile *file) if (!key_sym) { if (!opts.module) { WARN("static_call: can't find static_call_key symbol: %s", tmp); - free(key_name); return -1; } =20 @@ -697,7 +707,6 @@ static int create_static_call_sections(struct objtool_f= ile *file) */ key_sym =3D insn_call_dest(insn); } - free(key_name); =20 /* populate reloc for 'key' */ if (!elf_init_reloc_data_sym(file->elf, sec, @@ -981,7 +990,7 @@ static int create_direct_call_sections(struct objtool_f= ile *file) /* * Warnings shouldn't be reported for ignored functions. */ -static void add_ignores(struct objtool_file *file) +static int add_ignores(struct objtool_file *file) { struct section *rsec; struct symbol *func; @@ -989,7 +998,7 @@ static void add_ignores(struct objtool_file *file) =20 rsec =3D find_section_by_name(file->elf, ".rela.discard.func_stack_frame_= non_standard"); if (!rsec) - return; + return 0; =20 for_each_reloc(rsec, reloc) { switch (reloc->sym->type) { @@ -1006,11 +1015,13 @@ static void add_ignores(struct objtool_file *file) default: WARN("unexpected relocation symbol type in %s: %d", rsec->name, reloc->sym->type); - continue; + return -1; } =20 func->ignore =3D true; } + + return 0; } =20 /* @@ -1275,7 +1286,7 @@ static void remove_insn_ops(struct instruction *insn) insn->stack_ops =3D NULL; } =20 -static void annotate_call_site(struct objtool_file *file, +static int annotate_call_site(struct objtool_file *file, struct instruction *insn, bool sibling) { struct reloc *reloc =3D insn_reloc(file, insn); @@ -1291,16 +1302,16 @@ static void annotate_call_site(struct objtool_file = *file, * original instruction if/when it ever makes sense to do so.) */ if (!strcmp(insn->sec->name, ".altinstr_replacement")) - return; + return 0; =20 if (sym->static_call_tramp) { list_add_tail(&insn->call_node, &file->static_call_list); - return; + return 0; } =20 if (sym->retpoline_thunk) { list_add_tail(&insn->call_node, &file->retpoline_call_list); - return; + return 0; } =20 /* @@ -1312,10 +1323,12 @@ static void annotate_call_site(struct objtool_file = *file, if (reloc) set_reloc_type(file->elf, reloc, R_NONE); =20 - elf_write_insn(file->elf, insn->sec, - insn->offset, insn->len, - sibling ? arch_ret_insn(insn->len) - : arch_nop_insn(insn->len)); + if (elf_write_insn(file->elf, insn->sec, + insn->offset, insn->len, + sibling ? arch_ret_insn(insn->len) + : arch_nop_insn(insn->len))) { + return -1; + } =20 insn->type =3D sibling ? INSN_RETURN : INSN_NOP; =20 @@ -1329,7 +1342,7 @@ static void annotate_call_site(struct objtool_file *f= ile, insn->retpoline_safe =3D true; } =20 - return; + return 0; } =20 if (opts.mcount && sym->fentry) { @@ -1339,15 +1352,17 @@ static void annotate_call_site(struct objtool_file = *file, if (reloc) set_reloc_type(file->elf, reloc, R_NONE); =20 - elf_write_insn(file->elf, insn->sec, - insn->offset, insn->len, - arch_nop_insn(insn->len)); + if (elf_write_insn(file->elf, insn->sec, + insn->offset, insn->len, + arch_nop_insn(insn->len))) { + return -1; + } =20 insn->type =3D INSN_NOP; } =20 list_add_tail(&insn->call_node, &file->mcount_loc_list); - return; + return 0; } =20 if (insn->type =3D=3D INSN_CALL && !insn->sec->init) @@ -1355,14 +1370,16 @@ static void annotate_call_site(struct objtool_file = *file, =20 if (!sibling && dead_end_function(file, sym)) insn->dead_end =3D true; + + return 0; } =20 -static void add_call_dest(struct objtool_file *file, struct instruction *i= nsn, +static int add_call_dest(struct objtool_file *file, struct instruction *in= sn, struct symbol *dest, bool sibling) { insn->_call_dest =3D dest; if (!dest) - return; + return 0; =20 /* * Whatever stack impact regular CALLs have, should be undone @@ -1373,10 +1390,10 @@ static void add_call_dest(struct objtool_file *file= , struct instruction *insn, */ remove_insn_ops(insn); =20 - annotate_call_site(file, insn, sibling); + return annotate_call_site(file, insn, sibling); } =20 -static void add_retpoline_call(struct objtool_file *file, struct instructi= on *insn) +static int add_retpoline_call(struct objtool_file *file, struct instructio= n *insn) { /* * Retpoline calls/jumps are really dynamic calls/jumps in disguise, @@ -1393,7 +1410,7 @@ static void add_retpoline_call(struct objtool_file *f= ile, struct instruction *in insn->type =3D INSN_JUMP_DYNAMIC_CONDITIONAL; break; default: - return; + return 0; } =20 insn->retpoline_safe =3D true; @@ -1407,7 +1424,7 @@ static void add_retpoline_call(struct objtool_file *f= ile, struct instruction *in */ remove_insn_ops(insn); =20 - annotate_call_site(file, insn, false); + return annotate_call_site(file, insn, false); } =20 static void add_return_call(struct objtool_file *file, struct instruction = *insn, bool add) @@ -1476,6 +1493,7 @@ static int add_jump_destinations(struct objtool_file = *file) struct reloc *reloc; struct section *dest_sec; unsigned long dest_off; + int ret; =20 for_each_insn(file, insn) { if (insn->jump_dest) { @@ -1496,7 +1514,9 @@ static int add_jump_destinations(struct objtool_file = *file) dest_sec =3D reloc->sym->sec; dest_off =3D arch_dest_reloc_offset(reloc_addend(reloc)); } else if (reloc->sym->retpoline_thunk) { - add_retpoline_call(file, insn); + ret =3D add_retpoline_call(file, insn); + if (ret) + return ret; continue; } else if (reloc->sym->return_thunk) { add_return_call(file, insn, true); @@ -1506,7 +1526,9 @@ static int add_jump_destinations(struct objtool_file = *file) * External sibling call or internal sibling call with * STT_FUNC reloc. */ - add_call_dest(file, insn, reloc->sym, true); + ret =3D add_call_dest(file, insn, reloc->sym, true); + if (ret) + return ret; continue; } else if (reloc->sym->sec->idx) { dest_sec =3D reloc->sym->sec; @@ -1546,7 +1568,9 @@ static int add_jump_destinations(struct objtool_file = *file) */ if (jump_dest->sym && jump_dest->offset =3D=3D jump_dest->sym->offset) { if (jump_dest->sym->retpoline_thunk) { - add_retpoline_call(file, insn); + ret =3D add_retpoline_call(file, insn); + if (ret) + return ret; continue; } if (jump_dest->sym->return_thunk) { @@ -1588,7 +1612,9 @@ static int add_jump_destinations(struct objtool_file = *file) * Internal sibling call without reloc or with * STT_SECTION reloc. */ - add_call_dest(file, insn, insn_func(jump_dest), true); + ret =3D add_call_dest(file, insn, insn_func(jump_dest), true); + if (ret) + return ret; continue; } =20 @@ -1618,6 +1644,7 @@ static int add_call_destinations(struct objtool_file = *file) unsigned long dest_off; struct symbol *dest; struct reloc *reloc; + int ret; =20 for_each_insn(file, insn) { struct symbol *func =3D insn_func(insn); @@ -1629,7 +1656,9 @@ static int add_call_destinations(struct objtool_file = *file) dest_off =3D arch_jump_destination(insn); dest =3D find_call_destination(insn->sec, dest_off); =20 - add_call_dest(file, insn, dest, false); + ret =3D add_call_dest(file, insn, dest, false); + if (ret) + return ret; =20 if (func && func->ignore) continue; @@ -1653,13 +1682,20 @@ static int add_call_destinations(struct objtool_fil= e *file) return -1; } =20 - add_call_dest(file, insn, dest, false); + ret =3D add_call_dest(file, insn, dest, false); + if (ret) + return ret; =20 } else if (reloc->sym->retpoline_thunk) { - add_retpoline_call(file, insn); + ret =3D add_retpoline_call(file, insn); + if (ret) + return ret; =20 - } else - add_call_dest(file, insn, reloc->sym, false); + } else { + ret =3D add_call_dest(file, insn, reloc->sym, false); + if (ret) + return ret; + } } =20 return 0; @@ -1682,15 +1718,15 @@ static int handle_group_alt(struct objtool_file *fi= le, if (!orig_alt_group) { struct instruction *last_orig_insn =3D NULL; =20 - orig_alt_group =3D malloc(sizeof(*orig_alt_group)); + orig_alt_group =3D calloc(1, sizeof(*orig_alt_group)); if (!orig_alt_group) { - WARN("malloc failed"); + WARN_GLIBC("calloc"); return -1; } orig_alt_group->cfi =3D calloc(special_alt->orig_len, sizeof(struct cfi_state *)); if (!orig_alt_group->cfi) { - WARN("calloc failed"); + WARN_GLIBC("calloc"); return -1; } =20 @@ -1719,9 +1755,9 @@ static int handle_group_alt(struct objtool_file *file, } } =20 - new_alt_group =3D malloc(sizeof(*new_alt_group)); + new_alt_group =3D calloc(1, sizeof(*new_alt_group)); if (!new_alt_group) { - WARN("malloc failed"); + WARN_GLIBC("calloc"); return -1; } =20 @@ -1733,9 +1769,9 @@ static int handle_group_alt(struct objtool_file *file, * instruction affects the stack, the instruction after it (the * nop) will propagate the new state to the shared CFI array. */ - nop =3D malloc(sizeof(*nop)); + nop =3D calloc(1, sizeof(*nop)); if (!nop) { - WARN("malloc failed"); + WARN_GLIBC("calloc"); return -1; } memset(nop, 0, sizeof(*nop)); @@ -1835,9 +1871,13 @@ static int handle_jump_alt(struct objtool_file *file, =20 if (reloc) set_reloc_type(file->elf, reloc, R_NONE); - elf_write_insn(file->elf, orig_insn->sec, - orig_insn->offset, orig_insn->len, - arch_nop_insn(orig_insn->len)); + + if (elf_write_insn(file->elf, orig_insn->sec, + orig_insn->offset, orig_insn->len, + arch_nop_insn(orig_insn->len))) { + return -1; + } + orig_insn->type =3D INSN_NOP; } =20 @@ -1873,9 +1913,8 @@ static int add_special_section_alts(struct objtool_fi= le *file) struct alternative *alt; int ret; =20 - ret =3D special_get_alts(file->elf, &special_alts); - if (ret) - return ret; + if (special_get_alts(file->elf, &special_alts)) + return -1; =20 list_for_each_entry_safe(special_alt, tmp, &special_alts, list) { =20 @@ -1884,8 +1923,7 @@ static int add_special_section_alts(struct objtool_fi= le *file) if (!orig_insn) { WARN_FUNC("special: can't find orig instruction", special_alt->orig_sec, special_alt->orig_off); - ret =3D -1; - goto out; + return -1; } =20 new_insn =3D NULL; @@ -1896,8 +1934,7 @@ static int add_special_section_alts(struct objtool_fi= le *file) WARN_FUNC("special: can't find new instruction", special_alt->new_sec, special_alt->new_off); - ret =3D -1; - goto out; + return -1; } } =20 @@ -1910,19 +1947,19 @@ static int add_special_section_alts(struct objtool_= file *file) ret =3D handle_group_alt(file, special_alt, orig_insn, &new_insn); if (ret) - goto out; + return ret; + } else if (special_alt->jump_or_nop) { ret =3D handle_jump_alt(file, special_alt, orig_insn, &new_insn); if (ret) - goto out; + return ret; } =20 - alt =3D malloc(sizeof(*alt)); + alt =3D calloc(1, sizeof(*alt)); if (!alt) { - WARN("malloc failed"); - ret =3D -1; - goto out; + WARN_GLIBC("calloc"); + return -1; } =20 alt->insn =3D new_insn; @@ -1939,8 +1976,7 @@ static int add_special_section_alts(struct objtool_fi= le *file) printf("long:\t%ld\t%ld\n", file->jl_nop_long, file->jl_long); } =20 -out: - return ret; + return 0; } =20 __weak unsigned long arch_jump_table_sym_offset(struct reloc *reloc, struc= t reloc *table) @@ -1997,9 +2033,9 @@ static int add_jump_table(struct objtool_file *file, = struct instruction *insn) if (!insn_func(dest_insn) || insn_func(dest_insn)->pfunc !=3D pfunc) break; =20 - alt =3D malloc(sizeof(*alt)); + alt =3D calloc(1, sizeof(*alt)); if (!alt) { - WARN("malloc failed"); + WARN_GLIBC("calloc"); return -1; } =20 @@ -2047,7 +2083,7 @@ static void find_jump_table(struct objtool_file *file= , struct symbol *func, insn->jump_dest && (insn->jump_dest->offset <=3D insn->offset || insn->jump_dest->offset > orig_insn->offset)) - break; + break; =20 table_reloc =3D arch_find_switch_table(file, insn, &table_size); if (!table_reloc) @@ -2111,7 +2147,6 @@ static int add_func_jump_tables(struct objtool_file *= file, if (!insn_jump_table(insn)) continue; =20 - ret =3D add_jump_table(file, insn); if (ret) return ret; @@ -2229,6 +2264,7 @@ static int read_unwind_hints(struct objtool_file *fil= e) if (sym && sym->bind =3D=3D STB_GLOBAL) { if (opts.ibt && insn->type !=3D INSN_ENDBR && !insn->noendbr) { WARN_INSN(insn, "UNWIND_HINT_IRET_REGS without ENDBR"); + return -1; } } } @@ -2398,7 +2434,7 @@ static int __annotate_late(struct objtool_file *file,= int type, struct instructi =20 default: WARN_INSN(insn, "Unknown annotation type: %d", type); - break; + return -1; } =20 return 0; @@ -2511,7 +2547,10 @@ static int decode_sections(struct objtool_file *file) if (ret) return ret; =20 - add_ignores(file); + ret =3D add_ignores(file); + if (ret) + return ret; + add_uaccess_safe(file); =20 ret =3D read_annotate(file, __annotate_early); @@ -2731,7 +2770,7 @@ static int update_cfi_state(struct instruction *insn, if (cfa->base =3D=3D CFI_UNDEFINED) { if (insn_func(insn)) { WARN_INSN(insn, "undefined stack state"); - return -1; + return 1; } return 0; } @@ -3174,9 +3213,8 @@ static int propagate_alt_cfi(struct objtool_file *fil= e, struct instruction *insn if (cficmp(alt_cfi[group_off], insn->cfi)) { struct alt_group *orig_group =3D insn->alt_group->orig_group ?: insn->a= lt_group; struct instruction *orig =3D orig_group->first_insn; - char *where =3D offstr(insn->sec, insn->offset); - WARN_INSN(orig, "stack layout conflict in alternatives: %s", where); - free(where); + WARN_INSN(orig, "stack layout conflict in alternatives: %s", + offstr(insn->sec, insn->offset)); return -1; } } @@ -3189,11 +3227,13 @@ static int handle_insn_ops(struct instruction *insn, struct insn_state *state) { struct stack_op *op; + int ret; =20 for (op =3D insn->stack_ops; op; op =3D op->next) { =20 - if (update_cfi_state(insn, next_insn, &state->cfi, op)) - return 1; + ret =3D update_cfi_state(insn, next_insn, &state->cfi, op); + if (ret) + return ret; =20 if (!opts.uaccess || !insn->alt_group) continue; @@ -3237,36 +3277,41 @@ static bool insn_cfi_match(struct instruction *insn= , struct cfi_state *cfi2) WARN_INSN(insn, "stack state mismatch: cfa1=3D%d%+d cfa2=3D%d%+d", cfi1->cfa.base, cfi1->cfa.offset, cfi2->cfa.base, cfi2->cfa.offset); + return false; =20 - } else if (memcmp(&cfi1->regs, &cfi2->regs, sizeof(cfi1->regs))) { + } + + if (memcmp(&cfi1->regs, &cfi2->regs, sizeof(cfi1->regs))) { for (i =3D 0; i < CFI_NUM_REGS; i++) { - if (!memcmp(&cfi1->regs[i], &cfi2->regs[i], - sizeof(struct cfi_reg))) + + if (!memcmp(&cfi1->regs[i], &cfi2->regs[i], sizeof(struct cfi_reg))) continue; =20 WARN_INSN(insn, "stack state mismatch: reg1[%d]=3D%d%+d reg2[%d]=3D%d%+= d", i, cfi1->regs[i].base, cfi1->regs[i].offset, i, cfi2->regs[i].base, cfi2->regs[i].offset); - break; } + return false; + } =20 - } else if (cfi1->type !=3D cfi2->type) { + if (cfi1->type !=3D cfi2->type) { =20 WARN_INSN(insn, "stack state mismatch: type1=3D%d type2=3D%d", cfi1->type, cfi2->type); + return false; + } =20 - } else if (cfi1->drap !=3D cfi2->drap || + if (cfi1->drap !=3D cfi2->drap || (cfi1->drap && cfi1->drap_reg !=3D cfi2->drap_reg) || (cfi1->drap && cfi1->drap_offset !=3D cfi2->drap_offset)) { =20 WARN_INSN(insn, "stack state mismatch: drap1=3D%d(%d,%d) drap2=3D%d(%d,%= d)", cfi1->drap, cfi1->drap_reg, cfi1->drap_offset, cfi2->drap, cfi2->drap_reg, cfi2->drap_offset); + return false; + } =20 - } else - return true; - - return false; + return true; } =20 static inline bool func_uaccess_safe(struct symbol *func) @@ -3498,6 +3543,8 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, =20 WARN("%s() falls through to next function %s()", func->name, insn_func(insn)->name); + func->warnings++; + return 1; } =20 @@ -3605,9 +3652,6 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, return 1; } =20 - if (insn->dead_end) - return 0; - break; =20 case INSN_JUMP_CONDITIONAL: @@ -3714,7 +3758,9 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, if (file->ignore_unreachables) return 0; =20 - WARN("%s: unexpected end of section", sec->name); + WARN("%s%sunexpected end of section %s", + func ? func->name : "", func ? ": " : "", + sec->name); return 1; } =20 @@ -3804,7 +3850,7 @@ static int validate_unret(struct objtool_file *file, = struct instruction *insn) if (!is_sibling_call(insn)) { if (!insn->jump_dest) { WARN_INSN(insn, "unresolved jump target after linking?!?"); - return -1; + return 1; } ret =3D validate_unret(file, insn->jump_dest); if (ret) { @@ -3826,7 +3872,7 @@ static int validate_unret(struct objtool_file *file, = struct instruction *insn) if (!dest) { WARN("Unresolved function after linking!?: %s", insn_call_dest(insn)->name); - return -1; + return 1; } =20 ret =3D validate_unret(file, dest); @@ -3855,7 +3901,7 @@ static int validate_unret(struct objtool_file *file, = struct instruction *insn) =20 if (!next) { WARN_INSN(insn, "teh end!"); - return -1; + return 1; } insn =3D next; } @@ -3870,18 +3916,13 @@ static int validate_unret(struct objtool_file *file= , struct instruction *insn) static int validate_unrets(struct objtool_file *file) { struct instruction *insn; - int ret, warnings =3D 0; + int warnings =3D 0; =20 for_each_insn(file, insn) { if (!insn->unret) continue; =20 - ret =3D validate_unret(file, insn); - if (ret < 0) { - WARN_INSN(insn, "Failed UNRET validation"); - return ret; - } - warnings +=3D ret; + warnings +=3D validate_unret(file, insn); } =20 return warnings; @@ -3907,13 +3948,13 @@ static int validate_retpoline(struct objtool_file *= file) if (insn->type =3D=3D INSN_RETURN) { if (opts.rethunk) { WARN_INSN(insn, "'naked' return found in MITIGATION_RETHUNK build"); - } else - continue; - } else { - WARN_INSN(insn, "indirect %s found in MITIGATION_RETPOLINE build", - insn->type =3D=3D INSN_JUMP_DYNAMIC ? "jump" : "call"); + warnings++; + } + continue; } =20 + WARN_INSN(insn, "indirect %s found in MITIGATION_RETPOLINE build", + insn->type =3D=3D INSN_JUMP_DYNAMIC ? "jump" : "call"); warnings++; } =20 @@ -4480,7 +4521,7 @@ static int validate_reachable_instructions(struct obj= tool_file *file) } =20 /* 'funcs' is a space-separated list of function names */ -static int disas_funcs(const char *funcs) +static void disas_funcs(const char *funcs) { const char *objdump_str, *cross_compile; int size, ret; @@ -4513,7 +4554,7 @@ static int disas_funcs(const char *funcs) size =3D snprintf(NULL, 0, objdump_str, cross_compile, objname, funcs) + = 1; if (size <=3D 0) { WARN("objdump string size calculation failed"); - return -1; + return; } =20 cmd =3D malloc(size); @@ -4523,13 +4564,11 @@ static int disas_funcs(const char *funcs) ret =3D system(cmd); if (ret) { WARN("disassembly failed: %d", ret); - return -1; + return; } - - return 0; } =20 -static int disas_warned_funcs(struct objtool_file *file) +static void disas_warned_funcs(struct objtool_file *file) { struct symbol *sym; char *funcs =3D NULL, *tmp; @@ -4538,9 +4577,17 @@ static int disas_warned_funcs(struct objtool_file *f= ile) if (sym->warnings) { if (!funcs) { funcs =3D malloc(strlen(sym->name) + 1); + if (!funcs) { + WARN_GLIBC("malloc"); + return; + } strcpy(funcs, sym->name); } else { tmp =3D malloc(strlen(funcs) + strlen(sym->name) + 2); + if (!tmp) { + WARN_GLIBC("malloc"); + return; + } sprintf(tmp, "%s %s", funcs, sym->name); free(funcs); funcs =3D tmp; @@ -4550,8 +4597,6 @@ static int disas_warned_funcs(struct objtool_file *fi= le) =20 if (funcs) disas_funcs(funcs); - - return 0; } =20 struct insn_chunk { @@ -4584,7 +4629,7 @@ static void free_insns(struct objtool_file *file) =20 int check(struct objtool_file *file) { - int ret, warnings =3D 0; + int ret =3D 0, warnings =3D 0; =20 arch_initial_func_cfi_state(&initial_func_cfi); init_cfi_state(&init_cfi); @@ -4602,44 +4647,27 @@ int check(struct objtool_file *file) cfi_hash_add(&func_cfi); =20 ret =3D decode_sections(file); - if (ret < 0) + if (ret) goto out; =20 - warnings +=3D ret; - if (!nr_insns) goto out; =20 - if (opts.retpoline) { - ret =3D validate_retpoline(file); - if (ret < 0) - goto out; - warnings +=3D ret; - } + if (opts.retpoline) + warnings +=3D validate_retpoline(file); =20 if (opts.stackval || opts.orc || opts.uaccess) { - ret =3D validate_functions(file); - if (ret < 0) - goto out; - warnings +=3D ret; + int w =3D 0; =20 - ret =3D validate_unwind_hints(file, NULL); - if (ret < 0) - goto out; - warnings +=3D ret; + w +=3D validate_functions(file); + w +=3D validate_unwind_hints(file, NULL); + if (!w) + w +=3D validate_reachable_instructions(file); =20 - if (!warnings) { - ret =3D validate_reachable_instructions(file); - if (ret < 0) - goto out; - warnings +=3D ret; - } + warnings +=3D w; =20 } else if (opts.noinstr) { - ret =3D validate_noinstr_sections(file); - if (ret < 0) - goto out; - warnings +=3D ret; + warnings +=3D validate_noinstr_sections(file); } =20 if (opts.unret) { @@ -4647,87 +4675,67 @@ int check(struct objtool_file *file) * Must be after validate_branch() and friends, it plays * further games with insn->visited. */ - ret =3D validate_unrets(file); - if (ret < 0) - goto out; - warnings +=3D ret; + warnings +=3D validate_unrets(file); } =20 - if (opts.ibt) { - ret =3D validate_ibt(file); - if (ret < 0) - goto out; - warnings +=3D ret; - } + if (opts.ibt) + warnings +=3D validate_ibt(file); =20 - if (opts.sls) { - ret =3D validate_sls(file); - if (ret < 0) - goto out; - warnings +=3D ret; - } + if (opts.sls) + warnings +=3D validate_sls(file); =20 if (opts.static_call) { ret =3D create_static_call_sections(file); - if (ret < 0) + if (ret) goto out; - warnings +=3D ret; } =20 if (opts.retpoline) { ret =3D create_retpoline_sites_sections(file); - if (ret < 0) + if (ret) goto out; - warnings +=3D ret; } =20 if (opts.cfi) { ret =3D create_cfi_sections(file); - if (ret < 0) + if (ret) goto out; - warnings +=3D ret; } =20 if (opts.rethunk) { ret =3D create_return_sites_sections(file); - if (ret < 0) + if (ret) goto out; - warnings +=3D ret; =20 if (opts.hack_skylake) { ret =3D create_direct_call_sections(file); - if (ret < 0) + if (ret) goto out; - warnings +=3D ret; } } =20 if (opts.mcount) { ret =3D create_mcount_loc_sections(file); - if (ret < 0) + if (ret) goto out; - warnings +=3D ret; } =20 if (opts.prefix) { ret =3D add_prefix_symbols(file); - if (ret < 0) + if (ret) goto out; - warnings +=3D ret; } =20 if (opts.ibt) { ret =3D create_ibt_endbr_seal_sections(file); - if (ret < 0) + if (ret) goto out; - warnings +=3D ret; } =20 if (opts.orc && nr_insns) { ret =3D orc_create(file); - if (ret < 0) + if (ret) goto out; - warnings +=3D ret; } =20 free_insns(file); diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 0f38167bd840..b352a78b596c 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -331,7 +331,7 @@ static int read_sections(struct elf *elf) =20 elf->section_data =3D calloc(sections_nr, sizeof(*sec)); if (!elf->section_data) { - perror("calloc"); + WARN_GLIBC("calloc"); return -1; } for (i =3D 0; i < sections_nr; i++) { @@ -467,7 +467,7 @@ static int read_symbols(struct elf *elf) =20 elf->symbol_data =3D calloc(symbols_nr, sizeof(*sym)); if (!elf->symbol_data) { - perror("calloc"); + WARN_GLIBC("calloc"); return -1; } for (i =3D 0; i < symbols_nr; i++) { @@ -799,7 +799,7 @@ elf_create_section_symbol(struct elf *elf, struct secti= on *sec) struct symbol *sym =3D calloc(1, sizeof(*sym)); =20 if (!sym) { - perror("malloc"); + WARN_GLIBC("malloc"); return NULL; } =20 @@ -829,7 +829,7 @@ elf_create_prefix_symbol(struct elf *elf, struct symbol= *orig, long size) char *name =3D malloc(namelen); =20 if (!sym || !name) { - perror("malloc"); + WARN_GLIBC("malloc"); return NULL; } =20 @@ -963,7 +963,7 @@ static int read_relocs(struct elf *elf) nr_reloc =3D 0; rsec->relocs =3D calloc(sec_num_entries(rsec), sizeof(*reloc)); if (!rsec->relocs) { - perror("calloc"); + WARN_GLIBC("calloc"); return -1; } for (i =3D 0; i < sec_num_entries(rsec); i++) { @@ -1005,7 +1005,7 @@ struct elf *elf_open_read(const char *name, int flags) =20 elf =3D malloc(sizeof(*elf)); if (!elf) { - perror("malloc"); + WARN_GLIBC("malloc"); return NULL; } memset(elf, 0, sizeof(*elf)); @@ -1099,7 +1099,7 @@ struct section *elf_create_section(struct elf *elf, c= onst char *name, =20 sec =3D malloc(sizeof(*sec)); if (!sec) { - perror("malloc"); + WARN_GLIBC("malloc"); return NULL; } memset(sec, 0, sizeof(*sec)); @@ -1114,7 +1114,7 @@ struct section *elf_create_section(struct elf *elf, c= onst char *name, =20 sec->name =3D strdup(name); if (!sec->name) { - perror("strdup"); + WARN_GLIBC("strdup"); return NULL; } =20 @@ -1132,7 +1132,7 @@ struct section *elf_create_section(struct elf *elf, c= onst char *name, if (size) { sec->data->d_buf =3D malloc(size); if (!sec->data->d_buf) { - perror("malloc"); + WARN_GLIBC("malloc"); return NULL; } memset(sec->data->d_buf, 0, size); @@ -1179,7 +1179,7 @@ static struct section *elf_create_rela_section(struct= elf *elf, =20 rsec_name =3D malloc(strlen(sec->name) + strlen(".rela") + 1); if (!rsec_name) { - perror("malloc"); + WARN_GLIBC("malloc"); return NULL; } strcpy(rsec_name, ".rela"); @@ -1199,7 +1199,7 @@ static struct section *elf_create_rela_section(struct= elf *elf, =20 rsec->relocs =3D calloc(sec_num_entries(rsec), sizeof(struct reloc)); if (!rsec->relocs) { - perror("calloc"); + WARN_GLIBC("calloc"); return NULL; } =20 diff --git a/tools/objtool/include/objtool/objtool.h b/tools/objtool/includ= e/objtool/objtool.h index 94a33ee7b363..c0dc86a78ff6 100644 --- a/tools/objtool/include/objtool/objtool.h +++ b/tools/objtool/include/objtool/objtool.h @@ -41,7 +41,7 @@ struct objtool_file { =20 struct objtool_file *objtool_open_read(const char *_objname); =20 -void objtool_pv_add(struct objtool_file *file, int idx, struct symbol *fun= c); +int objtool_pv_add(struct objtool_file *file, int idx, struct symbol *func= ); =20 int check(struct objtool_file *file); int orc_dump(const char *objname); diff --git a/tools/objtool/include/objtool/warn.h b/tools/objtool/include/o= bjtool/warn.h index e72b9d630551..b29ac144e4f5 100644 --- a/tools/objtool/include/objtool/warn.h +++ b/tools/objtool/include/objtool/warn.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include =20 @@ -43,8 +44,9 @@ static inline char *offstr(struct section *sec, unsigned = long offset) =20 #define WARN(format, ...) \ fprintf(stderr, \ - "%s: %s: objtool: " format "\n", \ - objname, \ + "%s%s%s: objtool: " format "\n", \ + objname ?: "", \ + objname ? ": " : "", \ opts.werror ? "error" : "warning", \ ##__VA_ARGS__) =20 @@ -83,7 +85,10 @@ static inline char *offstr(struct section *sec, unsigned= long offset) } \ }) =20 -#define WARN_ELF(format, ...) \ - WARN(format ": %s", ##__VA_ARGS__, elf_errmsg(-1)) +#define WARN_ELF(format, ...) \ + WARN("%s: " format " failed: %s", __func__, ##__VA_ARGS__, elf_errmsg(-1)) + +#define WARN_GLIBC(format, ...) \ + WARN("%s: " format " failed: %s", __func__, ##__VA_ARGS__, strerror(errno= )) =20 #endif /* _WARN_H */ diff --git a/tools/objtool/objtool.c b/tools/objtool/objtool.c index 1c73fb62fd57..e4b49c534e4d 100644 --- a/tools/objtool/objtool.c +++ b/tools/objtool/objtool.c @@ -44,14 +44,14 @@ struct objtool_file *objtool_open_read(const char *file= name) return &file; } =20 -void objtool_pv_add(struct objtool_file *f, int idx, struct symbol *func) +int objtool_pv_add(struct objtool_file *f, int idx, struct symbol *func) { if (!opts.noinstr) - return; + return 0; =20 if (!f->pv_ops) { WARN("paravirt confusion"); - return; + return -1; } =20 /* @@ -60,14 +60,15 @@ void objtool_pv_add(struct objtool_file *f, int idx, st= ruct symbol *func) */ if (!strcmp(func->name, "_paravirt_nop") || !strcmp(func->name, "_paravirt_ident_64")) - return; + return 0; =20 /* already added this function */ if (!list_empty(&func->pv_target)) - return; + return 0; =20 list_add(&func->pv_target, &f->pv_ops[idx].targets); f->pv_ops[idx].clean =3D false; + return 0; } =20 int main(int argc, const char **argv) --=20 2.48.1 From nobody Tue Dec 16 23:40:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 7E7E41F1518 for ; Mon, 24 Mar 2025 21:56:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853386; cv=none; b=nG3q/fIs4oMNscKTgQs+5gDmJr7LTcnzJIgWqxOFqj2ZDQwR2X0Vpj3y58HjSLxlZHYbxcB+i69OSYSUqTEdFDhm4vlIs1S1bL0D/vtPQAqiehfNft9nswQ9PrxrO2vpoV3sRwfvu6Xe04c/9wF8UWML1sJVYkLvPrInwm0jp7Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853386; c=relaxed/simple; bh=vX8fmL90uhis5ZiSpKhMTL7v+LsPpwSsXhWLzlVfMuk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fQWzcN7hd1PbUVfjONJ69EuUVoyN8eRXn5Ja7zRUjRaIMQa3d6fzXo/CBwhv5Z/NvIij8ouBq17o0Rr5sW3d53f4Jaw2a5cbfBjP5lQ1BgU6Dc4ue5dsTCj8ey6F4d35nKxDLGKaQzXp9+RFm7wjQ71C4aRYDEaivnWTT8499dI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XbyfRpV7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XbyfRpV7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1CE0C4CEEE; Mon, 24 Mar 2025 21:56:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742853386; bh=vX8fmL90uhis5ZiSpKhMTL7v+LsPpwSsXhWLzlVfMuk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XbyfRpV78sLeFgsWrYWxVBxxoPB0MKLPFQPePh7S7EpaeWVP1tf1tHhErH87JFfw7 E7UQj4f8J3Er9Mx3Kjg44C2pgeyLoCScBlDrCDsG5p5PwQkG43Mw1/uPYkJBxg+9Ml bEeOZA6nHNNchmqoVN1o6bee7oO3rA1ZC+O89YREk2sn9WbLjtlDJM6SRSZKBc0/v6 e3qAi1QY/TTC3hz3XuC13+g3RtOHlbZnkH1ts3vUBjVa57OsUn/bZJNLHpFvEgahx2 bseeaJ4lbARDyPpA3pR9Psk6W4yo+aDG1lPd8hI0WCddvpTxSp1W4RQjZMf/qvKQ8y pKLCJcb4RPwKw== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Miroslav Benes , Brendan Jackman , Nathan Chancellor Subject: [PATCH 10/22] objtool: Reduce CONFIG_OBJTOOL_WERROR verbosity Date: Mon, 24 Mar 2025 14:56:00 -0700 Message-ID: X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove the following from CONFIG_OBJTOOL_WERROR: * backtrace * "upgraded warnings to errors" message * cmdline args This makes the default output less cluttered and makes it easier to spot the actual warnings. Note the above options are still are available with --verbose or OBJTOOL_VERBOSE=3D1. Also, do the cmdline arg printing on all warnings, regardless of werror. Signed-off-by: Josh Poimboeuf --- scripts/Makefile.lib | 2 +- tools/objtool/builtin-check.c | 113 ++++++++++++------------ tools/objtool/check.c | 23 ++--- tools/objtool/include/objtool/builtin.h | 6 +- 4 files changed, 73 insertions(+), 71 deletions(-) diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 99e281966ba3..cdf45722626c 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -277,7 +277,7 @@ objtool-args-$(CONFIG_HAVE_STATIC_CALL_INLINE) +=3D --= static-call objtool-args-$(CONFIG_HAVE_UACCESS_VALIDATION) +=3D --uaccess objtool-args-$(CONFIG_GCOV_KERNEL) +=3D --no-unreachable objtool-args-$(CONFIG_PREFIX_SYMBOLS) +=3D --prefix=3D$(CONFIG_FUNCTION_= PADDING_BYTES) -objtool-args-$(CONFIG_OBJTOOL_WERROR) +=3D --Werror --backtrace +objtool-args-$(CONFIG_OBJTOOL_WERROR) +=3D --Werror =20 objtool-args =3D $(objtool-args-y) \ $(if $(delay-objtool), --link) \ diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index c973a751fb7d..2bdff910430e 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -15,8 +15,11 @@ #include #include =20 -const char *objname; +#define ORIG_SUFFIX ".orig" =20 +int orig_argc; +static char **orig_argv; +const char *objname; struct opts opts; =20 static const char * const check_usage[] =3D { @@ -224,39 +227,73 @@ static int copy_file(const char *src, const char *dst) return 0; } =20 -static char **save_argv(int argc, const char **argv) +static void save_argv(int argc, const char **argv) { - char **orig_argv; - orig_argv =3D calloc(argc, sizeof(char *)); if (!orig_argv) { WARN_GLIBC("calloc"); - return NULL; + exit(1); } =20 for (int i =3D 0; i < argc; i++) { orig_argv[i] =3D strdup(argv[i]); if (!orig_argv[i]) { WARN_GLIBC("strdup(%s)", orig_argv[i]); - return NULL; + exit(1); } }; - - return orig_argv; } =20 -#define ORIG_SUFFIX ".orig" +void print_args(void) +{ + char *backup =3D NULL; + + if (opts.output || opts.dryrun) + goto print; + + /* + * Make a backup before kbuild deletes the file so the error + * can be recreated without recompiling or relinking. + */ + backup =3D malloc(strlen(objname) + strlen(ORIG_SUFFIX) + 1); + if (!backup) { + WARN_GLIBC("malloc"); + goto print; + } + + strcpy(backup, objname); + strcat(backup, ORIG_SUFFIX); + if (copy_file(objname, backup)) { + backup =3D NULL; + goto print; + } + +print: + /* + * Print the cmdline args to make it easier to recreate. If '--output' + * wasn't used, add it to the printed args with the backup as input. + */ + fprintf(stderr, "%s", orig_argv[0]); + + for (int i =3D 1; i < orig_argc; i++) { + char *arg =3D orig_argv[i]; + + if (backup && !strcmp(arg, objname)) + fprintf(stderr, " %s -o %s", backup, objname); + else + fprintf(stderr, " %s", arg); + } + + fprintf(stderr, "\n"); +} =20 int objtool_run(int argc, const char **argv) { struct objtool_file *file; - char *backup =3D NULL; - char **orig_argv; int ret =3D 0; =20 - orig_argv =3D save_argv(argc, argv); - if (!orig_argv) - return 1; + orig_argc =3D argc; + save_argv(argc, argv); =20 cmd_parse_options(argc, argv, check_usage); =20 @@ -279,59 +316,19 @@ int objtool_run(int argc, const char **argv) =20 file =3D objtool_open_read(objname); if (!file) - goto err; + return 1; =20 if (!opts.link && has_multiple_files(file->elf)) { WARN("Linked object requires --link"); - goto err; + return 1; } =20 ret =3D check(file); if (ret) - goto err; + return ret; =20 if (!opts.dryrun && file->elf->changed && elf_write(file->elf)) - goto err; + return 1; =20 return 0; - -err: - if (opts.dryrun) - goto err_msg; - - if (opts.output) { - unlink(opts.output); - goto err_msg; - } - - /* - * Make a backup before kbuild deletes the file so the error - * can be recreated without recompiling or relinking. - */ - backup =3D malloc(strlen(objname) + strlen(ORIG_SUFFIX) + 1); - if (!backup) { - WARN_GLIBC("malloc"); - return 1; - } - - strcpy(backup, objname); - strcat(backup, ORIG_SUFFIX); - if (copy_file(objname, backup)) - return 1; - -err_msg: - fprintf(stderr, "%s", orig_argv[0]); - - for (int i =3D 1; i < argc; i++) { - char *arg =3D orig_argv[i]; - - if (backup && !strcmp(arg, objname)) - fprintf(stderr, " %s -o %s", backup, objname); - else - fprintf(stderr, " %s", arg); - } - - fprintf(stderr, "\n"); - - return 1; } diff --git a/tools/objtool/check.c b/tools/objtool/check.c index fbe2a5ef2c40..03ec485a376a 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4740,9 +4740,6 @@ int check(struct objtool_file *file) =20 free_insns(file); =20 - if (opts.verbose) - disas_warned_funcs(file); - if (opts.stats) { printf("nr_insns_visited: %ld\n", nr_insns_visited); printf("nr_cfi: %ld\n", nr_cfi); @@ -4751,19 +4748,25 @@ int check(struct objtool_file *file) } =20 out: + if (!ret && !warnings) + return 0; + + if (opts.verbose) { + if (opts.werror && warnings) + WARN("%d warning(s) upgraded to errors", warnings); + print_args(); + disas_warned_funcs(file); + } + /* * CONFIG_OBJTOOL_WERROR upgrades all warnings (and errors) to actual * errors. * - * Note that even "fatal" type errors don't actually return an error - * without CONFIG_OBJTOOL_WERROR. That probably needs improved at some - * point. + * Note that even fatal errors don't yet actually return an error + * without CONFIG_OBJTOOL_WERROR. That will be fixed soon-ish. */ - if (opts.werror && (ret || warnings)) { - if (warnings) - WARN("%d warning(s) upgraded to errors", warnings); + if (opts.werror) return 1; - } =20 return 0; } diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/includ= e/objtool/builtin.h index 0fafd0f7a209..6b08666fa69d 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -43,8 +43,10 @@ struct opts { =20 extern struct opts opts; =20 -extern int cmd_parse_options(int argc, const char **argv, const char * con= st usage[]); +int cmd_parse_options(int argc, const char **argv, const char * const usag= e[]); =20 -extern int objtool_run(int argc, const char **argv); +int objtool_run(int argc, const char **argv); + +void print_args(void); =20 #endif /* _BUILTIN_H */ --=20 2.48.1 From nobody Tue Dec 16 23:40:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 83CCF1F151B for ; Mon, 24 Mar 2025 21:56:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853386; cv=none; b=YTF/fIt5v2UDTHGQYuI4LyiarPhYVf1EhNRYuE/64+l72SjZvlSphJ7ly1xobyvm7qUoJJwfTNL3UcAGTuCnvp90bvV2gkplgS+MJz7vVDu8VRWI0oMDH3z4NRXy5EhaZpOkQBhm3OX5ScK6g6bUlo+TrsnZJHHYIhE709kAxCU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853386; c=relaxed/simple; bh=aBDMNLcDU6h6g4YKrzDky3LA6LD1n2gyF+z9f/hf9Ps=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WWKas4985W/OvWou3YvX6XjrY46aDZuGFEMuB43Kuf+Nu01QRkUi9hqJmr2bVFk45aHI35UfIlRkMG1bRXLKnqQa2QOPr7Ka0tc8pG85x9p+L5UXWRXgDNbO3BG916WdfmerCPLDEQY6CgRiTJKOCarDN6y+8frfk2sCt0igPb8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NFqBHEgb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NFqBHEgb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C12FC4CEE4; Mon, 24 Mar 2025 21:56:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742853386; bh=aBDMNLcDU6h6g4YKrzDky3LA6LD1n2gyF+z9f/hf9Ps=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NFqBHEgbWNOfHb44J9n1c0fGq6REmLXE+XyJMLl3pnL5eEwiO1cTX/XxCvy76ZRXg yelXrlgtiSNUFN3PmPnnLF/e3UdiPDmiigw/h7BcFHW96ig0l99sAGZkp2zCnrvqj6 XNgCQyNAviNiqmGvaPTekToFgkLZomK/pqs1mOjsmHwJvS/yQrloE8zJcmz6pJmWpW FaQ28RsKzVRx3a9phWO5fMg/J//nrv3nH0HPkfbnwLmAqZ5lY31RLNT8ijHt4fbMsw K+T3E7NGE5k1YmRDyQ/J4lg0gK2iVoxjvLAVGnhmETy6b+zClr2AzYl+C78f1eZ9FQ o8DL4ChMPSmpg== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Miroslav Benes , Brendan Jackman , Nathan Chancellor Subject: [PATCH 11/22] objtool: Fix up some outdated references to ENTRY/ENDPROC Date: Mon, 24 Mar 2025 14:56:01 -0700 Message-ID: <5eb7e06e1a0e87aaeda8d583ab060e7638a6ea8e.1742852846.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" ENTRY and ENDPROC were deprecated years ago and replaced with SYM_FUNC_{START,END}. Fix up a few outdated references in the objtool documentation and comments. Also fix a few typos. Suggested-by: Brendan Jackman Suggested-by: Miroslav Benes Signed-off-by: Josh Poimboeuf --- include/linux/linkage.h | 4 ---- include/linux/objtool.h | 2 +- tools/objtool/Documentation/objtool.txt | 10 +++++----- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/include/linux/linkage.h b/include/linux/linkage.h index 5c8865bb59d9..b11660b706c5 100644 --- a/include/linux/linkage.h +++ b/include/linux/linkage.h @@ -134,10 +134,6 @@ .size name, .-name #endif =20 -/* If symbol 'name' is treated as a subroutine (gets called, and returns) - * then please use ENDPROC to mark 'name' as STT_FUNC for the benefit of - * static analysis tools such as stack depth analyzer. - */ #ifndef ENDPROC /* deprecated, use SYM_FUNC_END */ #define ENDPROC(name) \ diff --git a/include/linux/objtool.h b/include/linux/objtool.h index c722a921165b..248d9363ca85 100644 --- a/include/linux/objtool.h +++ b/include/linux/objtool.h @@ -69,7 +69,7 @@ * In asm, there are two kinds of code: normal C-type callable functions a= nd * the rest. The normal callable functions can be called by other code, a= nd * don't do anything unusual with the stack. Such normal callable functio= ns - * are annotated with the ENTRY/ENDPROC macros. Most asm code falls in th= is + * are annotated with SYM_FUNC_{START,END}. Most asm code falls in this * category. In this case, no special debugging annotations are needed be= cause * objtool can automatically generate the ORC data for the ORC unwinder to= read * at runtime. diff --git a/tools/objtool/Documentation/objtool.txt b/tools/objtool/Docume= ntation/objtool.txt index 28ac57b9e102..9e97fc25b2d8 100644 --- a/tools/objtool/Documentation/objtool.txt +++ b/tools/objtool/Documentation/objtool.txt @@ -34,7 +34,7 @@ Objtool has the following features: - Return thunk annotation -- annotates all return thunk sites so kernel can patch them inline, depending on enabled mitigations =20 -- Return thunk training valiation -- validate that all entry paths +- Return thunk untraining validation -- validate that all entry paths untrain a "safe return" before the first return (or call) =20 - Non-instrumentation validation -- validates non-instrumentable @@ -281,8 +281,8 @@ the objtool maintainers. If the error is for an asm file, and func() is indeed a callable function, add proper frame pointer logic using the FRAME_BEGIN and FRAME_END macros. Otherwise, if it's not a callable function, remove - its ELF function annotation by changing ENDPROC to END, and instead - use the manual unwind hint macros in asm/unwind_hints.h. + its ELF function annotation by using SYM_CODE_{START,END} and use the + manual unwind hint macros in asm/unwind_hints.h. =20 If it's a GCC-compiled .c file, the error may be because the function uses an inline asm() statement which has a "call" instruction. An @@ -352,7 +352,7 @@ the objtool maintainers. This is a kernel entry/exit instruction like sysenter or iret. Such instructions aren't allowed in a callable function, and are most likely part of the kernel entry code. Such code should probably be - placed in a SYM_FUNC_CODE block with unwind hints. + placed in a SYM_CODE_{START,END} block with unwind hints. =20 =20 6. file.o: warning: objtool: func()+0x26: sibling call from callable instr= uction with modified stack frame @@ -381,7 +381,7 @@ the objtool maintainers. =20 Another possibility is that the code has some asm or inline asm which does some unusual things to the stack or the frame pointer. In such - cases it's probably appropriate to use SYM_FUNC_CODE with unwind + cases it's probably appropriate to use SYM_CODE_{START,END} with unwind hints. =20 =20 --=20 2.48.1 From nobody Tue Dec 16 23:40:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 70AD11F2BB8 for ; Mon, 24 Mar 2025 21:56:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853387; cv=none; b=YnPUerxmXzp3zRSqgDDH09tCfgN/HMtCuvRv+gl+n+M5ZRlkpjagKfIEYw9bz5fjVOo9o6JLfRZymmJX/nvE4vQqeV66TB9X1gq47UzSqhhVc7NIsTOkU+LF5Bh/ChRY3hPjfMF04q/+L1Vu2MlSMduQ+MjDYsa6zpKaV6/H9BY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853387; c=relaxed/simple; bh=yo6sJXtvHZ+k/r0fmuhOzf3cJa4+JAvS2CiqyT/PhfY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hq4wFebeFmo4C2SGtU8vnkSagV4Ks3wyHcjvFSGLT94P14BoUFSY1cs3XU6GA31j6iaOMVNCPkeXcRhfc+g7/ZJ91zc4hBUQVTlnrGpbi/MtplgOhY1SM7R6WwaYzViR5PuS4qZPFUBhZwECmK8AkArFIHEWkluJM1JlvRY0z0c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cvPo1+Al; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cvPo1+Al" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 872FFC4CEDD; Mon, 24 Mar 2025 21:56:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742853386; bh=yo6sJXtvHZ+k/r0fmuhOzf3cJa4+JAvS2CiqyT/PhfY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cvPo1+AldjWeMVEGkGQmnEIxKS8WdWad6kjTCpfePpNzN90sl1EF56sg1bDsIV6qW TNU0Hnz/6MFpWUI19sAcjYsTaa1TyMecxelaaHBww4tZnOEgf8GjOKBRIjSnkEht81 AK0Z1Gfl0i+pDWWgpk4QBOGUZ2VaHOsLTvm/+D/IKvJCL+BTF9pJ4ME/8OgidvYJGb 9IjSoKhbc4SdgDbiCwXZOhDKcuC1w5mtKqjZIEW9GwROmDh6m2NScUMPYmDf4AtTgz +NLXy5SIgYrMp/Gnmv1agOPY1jfEKq/E09rcJrWm2pUym/9jxfvUJL5+wT+NO/duPR g3vdS8rMEYduQ== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Miroslav Benes , Brendan Jackman , Nathan Chancellor Subject: [PATCH 12/22] objtool: Remove --no-unreachable for noinstr-only vmlinux.o runs Date: Mon, 24 Mar 2025 14:56:02 -0700 Message-ID: <05414246a0124db2f21b0d071b652aa9043d039d.1742852847.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For (!X86_KERNEL_IBT && !LTO_CLANG && NOINSTR_VALIDATION), objtool runs on both translation units and vmlinux.o. The vmlinux.o run only does noinstr/noret validation. In that case --no-unreachable has no effect. Remove it. Note that for ((X86_KERNEL_IBT || LTO_CLANG) && KCOV), --no-unreachable still gets set in objtool-args-y by scripts/Makefile.lib. Signed-off-by: Josh Poimboeuf --- scripts/Makefile.vmlinux_o | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/Makefile.vmlinux_o b/scripts/Makefile.vmlinux_o index f476f5605029..938c7457717e 100644 --- a/scripts/Makefile.vmlinux_o +++ b/scripts/Makefile.vmlinux_o @@ -44,7 +44,6 @@ else vmlinux-objtool-args-$(CONFIG_OBJTOOL_WERROR) +=3D --Werror endif =20 -vmlinux-objtool-args-$(CONFIG_GCOV_KERNEL) +=3D --no-unreachable vmlinux-objtool-args-$(CONFIG_NOINSTR_VALIDATION) +=3D --noinstr \ $(if $(or $(CONFIG_MITIGATION_UNRET_ENTRY),$(CONFIG_MITIGATION_S= RSO)), --unret) =20 --=20 2.48.1 From nobody Tue Dec 16 23:40:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 ABC531F30D1 for ; Mon, 24 Mar 2025 21:56:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853387; cv=none; b=o0DlHoLHnr9zyLLzSFdnoRKTxSCadk5Epj75nSk+LNIUBDQ63PEAI+qCV2SME/NNT78j3XTfqGv7tHsawExlTZzrdtnpdOZfbjaM9cyDJZMklqPB9Bou0kkeM82HZf0wHn1A++DBEuyolqguFiWAMUtfGtum9vfXo/Jm9sUoiNU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853387; c=relaxed/simple; bh=dUwaxkgMT9R5Wn3IYDUsEuC6EQW97fKgnW3SaT+Ibmg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sbCxWLvWjgCH3kcGCGtjPW4w6PVg7EyjpCeRO4KdAIc98gq711KxUeSkKpAuv1Vmw6sdlol7Gz5YshvOJy0Lnuu0TM6N+6DtiEL6bAXnDucuVRAYKcq1A0E8VsBKN6CakdWESnpFBpoujsWVTLxCTbevqaNbW/9mk9wSh6QVT94= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KkWnhlAC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KkWnhlAC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01A0AC4CEED; Mon, 24 Mar 2025 21:56:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742853387; bh=dUwaxkgMT9R5Wn3IYDUsEuC6EQW97fKgnW3SaT+Ibmg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KkWnhlACiT0b8G2Avl+J2nV9dPXN87lYjbXPsvrsVWYTo1yGI89m7juUB3rz7AvyH N/YwQB7qGxyG8lVObsBUcN4+ECk+3srZsk5ojoOmg4KmNZrTuHVHjQfVMllLz5ljwo p+HGeAw5mrNqLd0UzIJTx6lEqDS/EJfr6RiNccwEgY+eQSlWWRi+zgX2cCXPMwoRBJ 1YkjSjDR6jVYsdiFtD3fRUh5gJqgIdHliP4N1MJFcFL9rsYs1OANQzcEShC4gl1oRs 45q0H44FKrzjvJ/h2W3+gOVHSKbnW95XM5HJzpxdnGMZyHCz3wBkPqmIZbNlPRB/lN Ova3sCTZvxCmA== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Miroslav Benes , Brendan Jackman , Nathan Chancellor Subject: [PATCH 13/22] objtool: Remove redundant opts.noinstr dependency Date: Mon, 24 Mar 2025 14:56:03 -0700 Message-ID: <0ead7ffa0f5be2e81aebbcc585e07b2c98702b44.1742852847.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The --noinstr dependecy on --link is already enforced in the cmdline arg parsing code. Remove the redundant check. Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 03ec485a376a..f4b9fcc395eb 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -340,12 +340,7 @@ static void init_insn_state(struct objtool_file *file,= struct insn_state *state, memset(state, 0, sizeof(*state)); init_cfi_state(&state->cfi); =20 - /* - * We need the full vmlinux for noinstr validation, otherwise we can - * not correctly determine insn_call_dest(insn)->sec (external symbols - * do not have a section). - */ - if (opts.link && opts.noinstr && sec) + if (opts.noinstr && sec) state->noinstr =3D sec->noinstr; } =20 --=20 2.48.1 From nobody Tue Dec 16 23:40:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 554231F3BB2 for ; Mon, 24 Mar 2025 21:56:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853388; cv=none; b=MPV4037355fw9qqlFBHXgrqZUZaQE6afHC4JlqdjIaz0YkYwjyZrYE7+Os9cfRf2jDe3CTJyr/L2CbSlki59yabNTU3vsC8bzX+l07Z46H2AWGUgjULc/LH98GFcom60qVsIxdLMWOUSVVDjsC+gh2YEFm64wEG/fk76GB5vPnQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853388; c=relaxed/simple; bh=9LaUKcsJYxwa9715jUtaKqGsyMaRbvFl48Eo6fa7xDg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dKhPuGCRT+tS1CV3qSF6itSAX4Xb0PiRvkaYTKhj6ad1Hz6RuIaeFp/VrUjGy5h5SwfvhCRcLaHdMV2JYgdCF3bv7d+A23pquA6f0mBBy5SYMuN9Of/8pNtrOyCisIQoHHcUgsPunuWxSx2eHM2MWHiD1596i6JZBaKIkZOyZLs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=N5l5S5+k; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="N5l5S5+k" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FB5EC4CEEE; Mon, 24 Mar 2025 21:56:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742853387; bh=9LaUKcsJYxwa9715jUtaKqGsyMaRbvFl48Eo6fa7xDg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N5l5S5+k17TQugmd/qBSepmqaPKieLSprKxotZAOVvbvWqJ6NzowfpTF3YH7AW0ko WSZgweHUjW9DpeSJ0bykWhkxrDRDVEDz4WaZCXYDE7Uf33wOJYW6rnf2eelis31QnF 5CKyCRZtifC69TOglxNQtV1Xz129XzOtajutMUYveUeiFzLp6x9J5F79tU35vxniid BYYkV0wiuYKoxhcglyDkq28FZnvcdrg+duNw0gLpjwzQgZw8757j244sg5PM5Q/FIu b6bD36K7O0J8H/P4leifLYI7GA9BMaQIXhEDrGWeWgdj3XgNgZvYoxVoVoJlE95YGZ rowGbEA9hOcCQ== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Miroslav Benes , Brendan Jackman , Nathan Chancellor , Raju Rangoju , Mark Brown , kernel test robot Subject: [PATCH 14/22] spi: amd: Fix out-of-bounds stack access in amd_set_spi_freq() Date: Mon, 24 Mar 2025 14:56:04 -0700 Message-ID: <78fef0f2434f35be9095bcc9ffa23dd8cab667b9.1742852847.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If speed_hz < AMD_SPI_MIN_HZ, amd_set_spi_freq() iterates over the entire amd_spi_freq array without breaking out early, causing 'i' to go beyond the array bounds. Fix that by stopping the loop when it gets to the last entry, so the low speed_hz value gets clamped up to AMD_SPI_MIN_HZ. Fixes the following warning with an UBSAN kernel: drivers/spi/spi-amd.o: error: objtool: amd_set_spi_freq() falls through t= o next function amd_spi_set_opcode() Cc: Raju Rangoju CC: Mark Brown Fixes: 3fe26121dc3a ("spi: amd: Configure device speed") Reported-by: kernel test robot Closes: https://lore.kernel.org/r/202503161828.RUk9EhWx-lkp@intel.com/ Signed-off-by: Josh Poimboeuf --- drivers/spi/spi-amd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/spi/spi-amd.c b/drivers/spi/spi-amd.c index c85997478b81..17fc0b17e756 100644 --- a/drivers/spi/spi-amd.c +++ b/drivers/spi/spi-amd.c @@ -302,7 +302,7 @@ static void amd_set_spi_freq(struct amd_spi *amd_spi, u= 32 speed_hz) { unsigned int i, spd7_val, alt_spd; =20 - for (i =3D 0; i < ARRAY_SIZE(amd_spi_freq); i++) + for (i =3D 0; i < ARRAY_SIZE(amd_spi_freq)-1; i++) if (speed_hz >=3D amd_spi_freq[i].speed_hz) break; =20 --=20 2.48.1 From nobody Tue Dec 16 23:40:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 82EB71F3D31 for ; Mon, 24 Mar 2025 21:56:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853388; cv=none; b=UAbUgBOk5pj4oYWAr/tebs4HE7saVjlB22kXhIWBJlLQZAWs9qTa5TW39l0aKzSciBpku5NNtBtW6VyXjj3auzO7Btgzu65ybOL/v6Q/neh6xp1sQOFitbOlasHEQct46T1S53/0Rn+m/mmW6qn2kuG/yG76ZqOy3fN3T67Y+i0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853388; c=relaxed/simple; bh=eR7/QObM3jTZYr0HPhlYeu90wXJiFEcy1CoDJ5gLsqM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u8FoujO3oNRgMkqYEqu5X7K8IMu5YdqYiC0GUl29QWpc2LMduNEqfA8ytbBGuFfZa4eh5Jnvy/AbUmUb6JFowOVZ3REWvZ6oG5qwsx3ihfWbg06hEtR2MDPcGgJtS7NGwTKfXMHB1ONSM/GjqoySVlfBBsDGZ5UF/iC4McQUoz8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Y3ogsvDr; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Y3ogsvDr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1DD3C4CEDD; Mon, 24 Mar 2025 21:56:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742853388; bh=eR7/QObM3jTZYr0HPhlYeu90wXJiFEcy1CoDJ5gLsqM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y3ogsvDrD+H4FnJ051NMhJZsEcDl+n8psooSbTSCzIvh4X6WH0u5HCWIu3G+NKWQA icIjsHuq2PqzOilR++sf3oHMQ0UIxLYmQRPAPonf555qDXh6Vnb37ZCBqHt7yd0LSw ITB/rC5KLyMQumZB7WgPNsFqjOSMOHDVR88NnZB92wpUvUsOjncRPKfIo8Y3PoecqX 9k+e+HqJ0oiMyR9uMf97xrRzcq3qNY5Us/b9HxY/Xgj9z/Johk7v3zxZF1GVG2Xbf9 3fuVTrhtMsY+KmeHfz2lZjyU3xOf07oSadYd+KGDArNqeeA6GxaggfgRK0y86CT3U1 Vd0F1Cw82TPiA== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Miroslav Benes , Brendan Jackman , Nathan Chancellor , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni , kernel test robot Subject: [PATCH 15/22] nvmet: Fix out-of-bounds stack access in nvmet_ctrl_state_show() Date: Mon, 24 Mar 2025 14:56:05 -0700 Message-ID: X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The csts_state_names array only has six sparse entries, but the iteration code in nvmet_ctrl_state_show() iterates seven, resulting in a potential out-of-bounds stack read. Fix that. Fixes the following warning with an UBSAN kernel: vmlinux.o: warning: objtool: .text.nvmet_ctrl_state_show: unexpected end = of section Cc: Christoph Hellwig Cc: Sagi Grimberg Cc: Chaitanya Kulkarni Fixes: 649fd41420a8 ("nvmet: add debugfs support") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202503171547.LlCTJLQL-lkp@int= el.com/ Signed-off-by: Josh Poimboeuf --- drivers/nvme/target/debugfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/nvme/target/debugfs.c b/drivers/nvme/target/debugfs.c index 220c7391fc19..c6571fbd35e3 100644 --- a/drivers/nvme/target/debugfs.c +++ b/drivers/nvme/target/debugfs.c @@ -78,7 +78,7 @@ static int nvmet_ctrl_state_show(struct seq_file *m, void= *p) bool sep =3D false; int i; =20 - for (i =3D 0; i < 7; i++) { + for (i =3D 0; i < ARRAY_SIZE(csts_state_names); i++) { int state =3D BIT(i); =20 if (!(ctrl->csts & state)) --=20 2.48.1 From nobody Tue Dec 16 23:40:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 08F151F3FEE for ; Mon, 24 Mar 2025 21:56:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853389; cv=none; b=hk5oYsbqjWKBdQh71muEIxbDSaQwf18W4yG057Nj7RvRkkp5TX1He6F/ldn/FWdBP5Xx78j/QqBWGPdLKBnjcZPzVSv7aZ3upT769ZVvecsstBSl7ve9Qg/5BI+lP0fgRi0yy4sc45AiuYqJBr/Xr07lYHXn7s5lMnxT+2teI6k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853389; c=relaxed/simple; bh=SMqJ/mdxDUlaT7sCHuMQcldNMFe2OQbR1k57sPHhsYw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sUGIGPS8CPJU0TKT7KJvisIJDBxW+fk8Yur04o9G9KOR8czC/N++M1Lk15JN+i8ApICtZqzptTA6nu04kwwG9IS/n6RQnSzEwSTwJ7MNFGcnFTAjm8YIAW8gJ+OMjDKMfel/v899uPX04kO0PElQVoyY2Xicd7MABirr9CSPhww= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=T5J3o8rG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="T5J3o8rG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88179C4CEE4; Mon, 24 Mar 2025 21:56:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742853388; bh=SMqJ/mdxDUlaT7sCHuMQcldNMFe2OQbR1k57sPHhsYw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T5J3o8rGqRFbhzpVB+HSQSUCd+LB8+GKgriCJ76BHS8VJyVHtfzRGlmom1lo+Cv3q RYVvKq/Pm5hBYgYRyIYna+qnuxgXbVVL5+5/mVXWvnesZdHRAxOMxuv+Au8js02H3f u2AVOoWIsvEugOE1Lt4Nd4zH8jL06Xvi5kD87dHbCHlrskBZhinxkhxUBPSMmLHqn3 +9Lnp1xAeX1nD01n83RFuNR4VBkcicqPlvLA62EYaEflmT1f0FdcTfN06kC6LoFqDg 0RA1r7PYP+Xqg00hYtBavMcWVM0vAmyAUG+h+AgXEKa5CHj5TUtUqx32FUCjtF9i4+ biNIBhtBFYmmQ== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Miroslav Benes , Brendan Jackman , Nathan Chancellor , Mauro Carvalho Chehab , kernel test robot Subject: [PATCH 16/22] media: dib8000: Prevent divide-by-zero in dib8000_set_dds() Date: Mon, 24 Mar 2025 14:56:06 -0700 Message-ID: X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If dib8000_set_dds()'s call to dib8000_read32() returns zero, the result is a divide-by-zero. Prevent that from happening. Fixes the following warning with an UBSAN kernel: drivers/media/dvb-frontends/dib8000.o: warning: objtool: dib8000_tune() f= alls through to next function dib8096p_cfg_DibRx() Cc: Mauro Carvalho Chehab Fixes: 173a64cb3fcf ("[media] dib8000: enhancement") Reported-by: kernel test robot Closes: https://lore.kernel.org/r/202503210602.fvH5DO1i-lkp@intel.com/ Signed-off-by: Josh Poimboeuf --- drivers/media/dvb-frontends/dib8000.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/media/dvb-frontends/dib8000.c b/drivers/media/dvb-fron= tends/dib8000.c index 2f5165918163..cfe59c3255f7 100644 --- a/drivers/media/dvb-frontends/dib8000.c +++ b/drivers/media/dvb-frontends/dib8000.c @@ -2701,8 +2701,11 @@ static void dib8000_set_dds(struct dib8000_state *st= ate, s32 offset_khz) u8 ratio; =20 if (state->revision =3D=3D 0x8090) { + u32 internal =3D dib8000_read32(state, 23) / 1000; + ratio =3D 4; - unit_khz_dds_val =3D (1<<26) / (dib8000_read32(state, 23) / 1000); + + unit_khz_dds_val =3D (1<<26) / (internal ?: 1); if (offset_khz < 0) dds =3D (1 << 26) - (abs_offset_khz * unit_khz_dds_val); else --=20 2.48.1 From nobody Tue Dec 16 23:40:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D56721EB5F4 for ; Mon, 24 Mar 2025 21:56:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853389; cv=none; b=Nyo8rcVejVBIDyem0r9+yeOq6haWgIOQ/Lex0qa3IoHgrAFNAlxsL6IucOuUJjATiAPvOndmyxfsLAdp8FqnkBuKq4Q24e5fYHy6M0rb723g/0hMUMUp2AxkaURC/GXNCTwPS6d60KAKjCvx/x8f7EO+61VTP3P32ZilF/hWS4Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853389; c=relaxed/simple; bh=Q0e+jxUlQcnZIxhwPBuE5JgMeJO9eNl4R7CNugxR5gw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rUGVAcSi5NKKqsQMCqot8OeUD1hoHa2Lxy12oMhyaGg9bWBUk5slXXxEC8YRc4xAxy9rF0yuavJsnbHcC4vCAtlnse0ecGMuxfRjzw5o15Smhm9VeY+sY3+X5mULz6V/FMR0rMoRgffEnW0EmNwbI8w+R9O5fFAvU2ODz9vh7Kk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Qn6UzrqT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Qn6UzrqT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F108C4CEDD; Mon, 24 Mar 2025 21:56:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742853389; bh=Q0e+jxUlQcnZIxhwPBuE5JgMeJO9eNl4R7CNugxR5gw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qn6UzrqT6xep3HeIv1eyz62P3PLrDOL9PCilW8yIqIHmKPQfYECAgQc1cFF3qoSQx NAMfQ9h04qofOjJjiVNT8fCkuPaeRP2wKJZ7nLaY6EU9A2Xt3HrrKljAFgA0sQame5 jl1ofpYxCapvRdiqOWo//06/CUA3/allCC9EL2zWKcvdOi1ilEwUXKCCI3IxSVQecM +O02Q49BL5WBBrSpyEXXHimVCjDAd+GLRhY+nyjy7HWbcToxgPrAdRHe73mANV/311 fgC6/C7TrQYsd49KbVjVhiwVxcZnzMYapGnUdGu4F3zYJbZDWi0HRKDsHQoNRKsKET pMs5llV5rfmfg== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Miroslav Benes , Brendan Jackman , Nathan Chancellor Subject: [PATCH 17/22] panic: Disable SMAP in __stack_chk_fail() Date: Mon, 24 Mar 2025 14:56:07 -0700 Message-ID: X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" __stack_chk_fail() can be called from uaccess-enabled code. Make sure uaccess gets disabled before calling panic(). Fixes the following warning: kernel/trace/trace_branch.o: error: objtool: ftrace_likely_update+0x1ea: = call to __stack_chk_fail() with UACCESS enabled Signed-off-by: Josh Poimboeuf --- kernel/panic.c | 6 ++++++ tools/objtool/check.c | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/kernel/panic.c b/kernel/panic.c index d8635d5cecb2..f9f0c5148f6a 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -832,9 +832,15 @@ device_initcall(register_warn_debugfs); */ __visible noinstr void __stack_chk_fail(void) { + unsigned long flags; + instrumentation_begin(); + flags =3D user_access_save(); + panic("stack-protector: Kernel stack is corrupted in: %pB", __builtin_return_address(0)); + + user_access_restore(flags); instrumentation_end(); } EXPORT_SYMBOL(__stack_chk_fail); diff --git a/tools/objtool/check.c b/tools/objtool/check.c index f4b9fcc395eb..a953ce5fe395 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1194,12 +1194,15 @@ static const char *uaccess_safe_builtin[] =3D { "__ubsan_handle_load_invalid_value", /* STACKLEAK */ "stackleak_track_stack", + /* TRACE_BRANCH_PROFILING */ + "ftrace_likely_update", + /* STACKPROTECTOR */ + "__stack_chk_fail", /* misc */ "csum_partial_copy_generic", "copy_mc_fragile", "copy_mc_fragile_handle_tail", "copy_mc_enhanced_fast_string", - "ftrace_likely_update", /* CONFIG_TRACE_BRANCH_PROFILING */ "rep_stos_alternative", "rep_movs_alternative", "__copy_user_nocache", --=20 2.48.1 From nobody Tue Dec 16 23:40:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 F04BB1EFFBE for ; Mon, 24 Mar 2025 21:56:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853390; cv=none; b=iqmvEi2CLwO5w6weHayu3pxVAhgSxcDEc0aimv9DuxdGF1OYzl34mr2n49R4a7J4n3uHFpDuXzl6hTN/ZfwMjnjuHuPGR7x0CWBG+XkVhX4BTAJvo6KJ/HDb1hphRswCAhEFha32ugBmhsMRjiVKUhPHpDKLwBeMuR/lhWUc3s0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853390; c=relaxed/simple; bh=Q+oJTrzDRTBEawN/MRBhV9wQOgT+O+sJjJHoqlU0wrw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k/UxirjXHYK90qxMRvKHSeiZzdvCujnbYIo1eFYsjQvAI4kGU6cg8qCzxJfm6Ul3XSk7HLmcup/fwLJHumID/BVNw7edSsk9E1H1kgspj7JFrj22y7TwXcCorVkehutdj4T0/I8LctBVCbEgsHY/gCpDT3H7QD8bosxmznjFq0A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JdlJUBGC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JdlJUBGC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79C7DC4CEE4; Mon, 24 Mar 2025 21:56:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742853389; bh=Q+oJTrzDRTBEawN/MRBhV9wQOgT+O+sJjJHoqlU0wrw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JdlJUBGC7nJY13FX8KAoHeCJzDqXlWMfA1arSy34IJVcDfKlg4I2DWugoHUgPNLX4 Nbe1koZexCG4oYN0Vls8wJdyWL0JMHzkpMCKmkFYAeEV68K/IbQ4zpYtIL+2uL16mZ EtIExeCLzVNAnf7YlZCf+aIOWdhu9zhZp4ZoI3An4nRbFwEEWNyMk+trkS1hq4RWPf hQBgnye80opoAkCQRsOlNykXRhtydVaYWXeaCMvtRd137ORbVYqZK3p1n/enXW4sLc 5knYyL1ttM6CGGVkG6Jgzwlpu6r93YnkyMpuxUVkDgAiZcgGmvbx57fhiDIHkFFlbM /xamqj8TeA8ZQ== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Miroslav Benes , Brendan Jackman , Nathan Chancellor , Dmitry Torokhov , kernel test robot Subject: [PATCH 18/22] Input: cyapa - remove undefined behavior in cyapa_update_fw_store() Date: Mon, 24 Mar 2025 14:56:08 -0700 Message-ID: <73ae0bb3c656735890d914b74c9d6bb40c25d3cd.1742852847.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In cyapa_update_fw_store(), if count is zero, the write to fw_name[count-1] underflows the array. Presumably that's not possible in normal operation, as its caller sysfs_kf_write() already checks for zero. Regardless it's a good idea to check for the error explicitly and avoid undefined behavior. Fixes the following warning with an UBSAN kernel: vmlinux.o: warning: objtool: .text.cyapa_update_fw_store: unexpected end = of section Cc: Dmitry Torokhov Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202503171547.LlCTJLQL-lkp@int= el.com/ Signed-off-by: Josh Poimboeuf --- drivers/input/mouse/cyapa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c index 2f2d925a55d7..00c87c0532a6 100644 --- a/drivers/input/mouse/cyapa.c +++ b/drivers/input/mouse/cyapa.c @@ -1080,8 +1080,8 @@ static ssize_t cyapa_update_fw_store(struct device *d= ev, char fw_name[NAME_MAX]; int ret, error; =20 - if (count >=3D NAME_MAX) { - dev_err(dev, "File name too long\n"); + if (!count || count >=3D NAME_MAX) { + dev_err(dev, "Bad file name size\n"); return -EINVAL; } =20 --=20 2.48.1 From nobody Tue Dec 16 23:40:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 D14711F2BB8 for ; Mon, 24 Mar 2025 21:56:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853390; cv=none; b=USi3AsECaYMYQkDBtxU7B00g08eSzbTu8IW7S5HvZNnU+2aVdjTxJG4wTxRTXbSAfzwjTO4CVDpgknGfEzaY552mHXPhui4IwBvasy7g3vE8f/MspUSgdXWkSFVef5ezePP8LtCm8jbOlbl/MlVH9L/6Ri7OCqYGdWVHHOzDSPs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853390; c=relaxed/simple; bh=xVODsZWMExesxu8RVLgFgw7b8qaLdHIil2gMTtc+l8M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=asYUVdHCy+xkIzZGYDVPzPvFNYqsin0w1k1FTzIc+nJ9MU2Xj7N5/GErXV6IflS404YdD3Tl5abK0TGt03qj2fVVTn12EGJEEB+g/hGsklkuuM8Comk5t1uFVLu/eQKhIGvUBqdp3cQnbfNi3nc6aEQXFI5qrs4jxaY1GFbrnF8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=T1TnlNEy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="T1TnlNEy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01449C4CEEF; Mon, 24 Mar 2025 21:56:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742853390; bh=xVODsZWMExesxu8RVLgFgw7b8qaLdHIil2gMTtc+l8M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T1TnlNEyBvXpwEYZbbxtCYnVtDWS0hJVuMIdqYmVL3S+1/yIozkLl6KqRHpHRu1IL WXXJ2DBk0UwE5GBxDLYEA5rAllJWMxhjZD8688HPech0MYqp0YweS0FVRGwvWZ6Ao/ /FHaiRlh+WY7XiGe3qmOIsYox5x+hkL/qF9NLrMFoS0CejSfd3qR3gFDHDx6sgTcDx NhBuRkv0teIPpKqdK0jGxy3A0I8CsP1Sa8SSRmSC/AjYDKTU8A3ST+xy/04yblqhCD tiEmSYRhwCn3HjbTHZ0RRySXKCSJ/mShRhKHL7+AAhfYjW4hW2NAaQNFrKfgnsLdzL YF+cTRXWD6Pxw== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Miroslav Benes , Brendan Jackman , Nathan Chancellor , Srinivas Kandagatla , kernel test robot Subject: [PATCH 19/22] ASoC: codecs: wcd934x: Remove undefined behavior in wcd934x_slim_irq_handler() Date: Mon, 24 Mar 2025 14:56:09 -0700 Message-ID: <7e863839ec7301bf9c0f429a03873d44e484c31c.1742852847.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If port_id is negative, the shift counts in wcd934x_slim_irq_handler() also become negative, resulting in undefined behavior due to shift out of bounds. If I'm reading the code correctly, that appears to be not possible, but with KCOV enabled, Clang's range analysis isn't always able to determine that and generates undefined behavior. As a result the code generation isn't optimal, and undefined behavior should be avoided regardless. Improve code generation and remove the undefined behavior by converting the signed variables to unsigned. Fixes the following warning with UBSAN: sound/soc/codecs/snd-soc-wcd934x.o: warning: objtool: .text.wcd934x_slim_= irq_handler: unexpected end of section Cc: Srinivas Kandagatla Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202503180044.oH9gyPeg-lkp@int= el.com/ Signed-off-by: Josh Poimboeuf --- sound/soc/codecs/wcd934x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/soc/codecs/wcd934x.c b/sound/soc/codecs/wcd934x.c index 910852eb9698..c7f1b28f3b23 100644 --- a/sound/soc/codecs/wcd934x.c +++ b/sound/soc/codecs/wcd934x.c @@ -2273,7 +2273,7 @@ static irqreturn_t wcd934x_slim_irq_handler(int irq, = void *data) { struct wcd934x_codec *wcd =3D data; unsigned long status =3D 0; - int i, j, port_id; + unsigned int i, j, port_id; unsigned int val, int_val =3D 0; irqreturn_t ret =3D IRQ_NONE; bool tx; --=20 2.48.1 From nobody Tue Dec 16 23:40:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0DF7B1F463F for ; Mon, 24 Mar 2025 21:56:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853391; cv=none; b=VGWIJ1o9tpHdn/2HEIPDJwTRb8LN9K74vhJBVSoH8JXQtGQsQDPQ3P15ItZGXhX8AQVtOeu5rMbm/IpLkHAB/97RwBLmpdwA93f6Cd0PkvpMa8eR/tkExLfvzIfrQFhKvT+I0L+YanQVs8UlltSIihHaqEsagAh6ajxSfcMxWIU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853391; c=relaxed/simple; bh=VuFv/fY2c3UlfJj7TY8YR+/Rbs1bTh9wtoJHKV3Knvo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hFrpDytYFeyo4GXf///gJ1ONmTv430d6JIrPj4cljmTVQHKAWvFbac2QLPFwZslhmiuDyLBGpxk5CWuXbW4BYyEg2a6UzZoTODUeR9t8Q05RIGtV2C8Ajs3wzZm+Tmn5idfZ2b0ftKU/XwUus4zE/bzPDBN/DImJOAQhT2ExJrk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UzHRw7h9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UzHRw7h9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7DA98C4CEDD; Mon, 24 Mar 2025 21:56:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742853390; bh=VuFv/fY2c3UlfJj7TY8YR+/Rbs1bTh9wtoJHKV3Knvo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UzHRw7h9DEffgGb2+gjZPoAsWfRzuI7qW4TckHNnIevjvI63ZaGceqKv+usxAFgyR tQtiT6tJkdsl4HmaM7h4CEdhgsCMzqVlIgrqbUq1YRM5gEdbGZqhZiQuiC4e1smqkv s655MCWZd/we2fpHsjRg9t1QsFqyeTJQGge6EXjU12iirFmWFq01klEKMcBMyQI6iA R/nWAfROnD4IVlGCI6WLxyH5O9cwf5c9Q3CEnyU4erCI7RgDddx0QO7vJnxgWmcKBU LKBbsoCKgvt5cUWz19zrYGHvnkS5AdiLn3OZj67IFAEqOF5YsJMXMnK9yQUFVD7Gci om+l9XcvXA0og== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Miroslav Benes , Brendan Jackman , Nathan Chancellor , Liam Girdwood , Mark Brown , kernel test robot Subject: [PATCH 20/22] regulator: rk808: Remove undefined behavior in rk806_set_mode_dcdc() Date: Mon, 24 Mar 2025 14:56:10 -0700 Message-ID: <2023abcddf3f524ba478d64339996f25dc4097d2.1742852847.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If ctr_bit is negative, the shift counts become negative, causing a shift of bounds and undefined behavior. Presumably that's not possible in normal operation, but the code generation isn't optimal. And undefined behavior should be avoided regardless. Improve code generation and remove the undefined behavior by converting the signed variables to unsigned. Fixes the following warning with an UBSAN kernel: vmlinux.o: warning: objtool: rk806_set_mode_dcdc() falls through to next = function rk806_get_mode_dcdc() vmlinux.o: warning: objtool: .text.rk806_set_mode_dcdc: unexpected end of= section Cc: Liam Girdwood Cc: Mark Brown Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202503182350.52KeHGD4-lkp@int= el.com/ Signed-off-by: Josh Poimboeuf --- drivers/regulator/rk808-regulator.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/regulator/rk808-regulator.c b/drivers/regulator/rk808-= regulator.c index 7d82bd1b36df..1e8142479656 100644 --- a/drivers/regulator/rk808-regulator.c +++ b/drivers/regulator/rk808-regulator.c @@ -270,8 +270,8 @@ static const unsigned int rk817_buck1_4_ramp_table[] = =3D { =20 static int rk806_set_mode_dcdc(struct regulator_dev *rdev, unsigned int mo= de) { - int rid =3D rdev_get_id(rdev); - int ctr_bit, reg; + unsigned int rid =3D rdev_get_id(rdev); + unsigned int ctr_bit, reg; =20 reg =3D RK806_POWER_FPWM_EN0 + rid / 8; ctr_bit =3D rid % 8; --=20 2.48.1 From nobody Tue Dec 16 23:40:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 78CC71F4C8E for ; Mon, 24 Mar 2025 21:56:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853391; cv=none; b=Wv9UQsKcuTlMzTVzBI4QaODksYAOPb2+6VNAlvFWH5afCHWvTcPpxq9aJbvjzxc8krpOrLFtEZ3vW443Y256Of08B3Em111/143z3c8xjIEksYZLqLnZ5f+hL7fUbSn+TMDurgeFOlRBU8fi5L7oniJQ+OyePH9aSw/FmsQfVlg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853391; c=relaxed/simple; bh=n8tygGcCBvI5bEr58ByQaC/880pDiVAdBJyD9A6bB2g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AkvOepL7Qbf/ywzOzyPYS4KxsJnY6x0M/kDDJuJeZxy8gghD9ndychltaFmC4Fu6SMbIiY3iOnZPk2jnHRfqibogu5PV9UgOx9B9ptS7bNWfVDK6XrsyRWkx1ultCcYldATev4T6l8DKR2arpbK7qMxXwABFLZzgp1wV0C3I6Xk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oAj5QSgi; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oAj5QSgi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0CA6BC4CEF3; Mon, 24 Mar 2025 21:56:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742853391; bh=n8tygGcCBvI5bEr58ByQaC/880pDiVAdBJyD9A6bB2g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oAj5QSgi6ipkeUkyLvHs7mM3W/U9ZMS+2UuduZddIyNdLgp3hlxxugSsBYPTaq2B/ 2JysdxbE3/YqCL6bkoh2SzrnUgXhYdgYV644dL+E0wXGd1/oL2dC9JeNlsot81Hzkp UNB0uYr/B8ZHKmOuC3oZKZhVLCj5wEp5SwCniPCa3aoxql1B6BOR7gp9DOHthhWweh iHylK1C8DdTeG7s55ivVFxZ7CguP0GbDTjxD+76bU85H5cUKqb1qEZKXlZTNPW78bA E4GBvecLaQqyiyohkEoCb21UbjmMdFxVwYPPvC2vGrfqGOVehPxzW9zVX3wDyRez4y 97x7ozTp+PClQ== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Miroslav Benes , Brendan Jackman , Nathan Chancellor , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Subject: [PATCH 21/22] pwm: mediatek: Prevent divide-by-zero in pwm_mediatek_config() Date: Mon, 24 Mar 2025 14:56:11 -0700 Message-ID: X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable With CONFIG_COMPILE_TEST && !CONFIG_CLK, pwm_mediatek_config() has a divide-by-zero in the following line: do_div(resolution, clk_get_rate(pc->clk_pwms[pwm->hwpwm])); due to the fact that the !CONFIG_CLK version of clk_get_rate() returns zero. This is presumably just a theoretical problem: COMPILE_TEST overrides the dependency on RALINK which would select COMMON_CLK. Regardless it's a good idea to check for the error explicitly to avoid divide-by-zero. Fixes the following warning: drivers/pwm/pwm-mediatek.o: warning: objtool: .text: unexpected end of se= ction Cc: Uwe Kleine-K=C3=B6nig Signed-off-by: Josh Poimboeuf --- drivers/pwm/pwm-mediatek.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/pwm/pwm-mediatek.c b/drivers/pwm/pwm-mediatek.c index 01dfa0fab80a..7eaab5831499 100644 --- a/drivers/pwm/pwm-mediatek.c +++ b/drivers/pwm/pwm-mediatek.c @@ -121,21 +121,25 @@ static int pwm_mediatek_config(struct pwm_chip *chip,= struct pwm_device *pwm, struct pwm_mediatek_chip *pc =3D to_pwm_mediatek_chip(chip); u32 clkdiv =3D 0, cnt_period, cnt_duty, reg_width =3D PWMDWIDTH, reg_thres =3D PWMTHRES; + unsigned long clk_rate; u64 resolution; int ret; =20 ret =3D pwm_mediatek_clk_enable(chip, pwm); - if (ret < 0) return ret; =20 + clk_rate =3D clk_get_rate(pc->clk_pwms[pwm->hwpwm]); + if (!clk_rate) + return -EINVAL; + /* Make sure we use the bus clock and not the 26MHz clock */ if (pc->soc->has_ck_26m_sel) writel(0, pc->regs + PWM_CK_26M_SEL); =20 /* Using resolution in picosecond gets accuracy higher */ resolution =3D (u64)NSEC_PER_SEC * 1000; - do_div(resolution, clk_get_rate(pc->clk_pwms[pwm->hwpwm])); + do_div(resolution, clk_rate); =20 cnt_period =3D DIV_ROUND_CLOSEST_ULL((u64)period_ns * 1000, resolution); while (cnt_period > 8191) { --=20 2.48.1 From nobody Tue Dec 16 23:40:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0E44F1F5408 for ; Mon, 24 Mar 2025 21:56:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853392; cv=none; b=o4pWR3P+2o2YTOpA5hudbJBF0GSkkr7rykwobWXJ1DUK/vzzOsgFcXPSZxRHJtzeiqsMyvEmDog2wKnlBMiLJh4KSW5mZY5D9qjUM0bXcBEVDY+XRkhgZV2c4QVpX8UUUQ/i6WUHk5/sbH03Fa2LLF+DgxhKmtyxTbIs41iUkmc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742853392; c=relaxed/simple; bh=DnvNW34wKVbDzGcEkkl8RsUUyZnTIp8TkKvklbn36Ws=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=quYNBpOT4nyZ0i2G4nhAf/+ydr0jCVQkLooc/2vbj6ppJA4fHOmApniO8g+PlpQaL08WlHnlfMK6TeyZ1mAFfscpOIIWa85UR4rB6Rgk4XwndDq8azYQZehBG/wfG/BpustzYEERK55glwmnYgjAp27jOMo7CXB/E6He2VvK6wU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hdKhrnUO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hdKhrnUO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FA49C4CEDD; Mon, 24 Mar 2025 21:56:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742853391; bh=DnvNW34wKVbDzGcEkkl8RsUUyZnTIp8TkKvklbn36Ws=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hdKhrnUO+9H86+tZGJaHp/2LarDqHaeG9fNcqinkm42y336x0n73DZRG6h/MI3w9I ZUC0JfG4PtB5LVDcCEatGlu0MRsQVGC6wRGm4pmmcd4tnraw1pTfuuD8XGNaTuI/d5 mC+z/bmARiEbZBzsqvFSEAbJGYEWbh52PoKARwI8b5oZl3GcUScUKpLjorQ6RjlQOn NQ9aAvuOfo/RVzheRo0PdDnR3DxrvQX+bLebizC5RsLWWifnLFx7j1Q6kRO2fpYhME gEdGcDrzyF136v7KZWXSp46LJcZeitCCqF2UhuLJWOJaERl7kVdtThqV2GnwMang4l CVuckExGFOnFw== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Miroslav Benes , Brendan Jackman , Nathan Chancellor , Kees Cook , kernel test robot Subject: [PATCH 22/22] lkdtm: Obfuscate do_nothing() pointer Date: Mon, 24 Mar 2025 14:56:12 -0700 Message-ID: <30b9abffbddeb43c4f6320b1270fa9b4d74c54ed.1742852847.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If execute_location()'s memcpy of do_nothing() gets inlined and unrolled by the compiler, it copies one word at a time: mov 0x0(%rip),%rax R_X86_64_PC32 .text+0x1374 mov %rax,0x38(%rbx) mov 0x0(%rip),%rax R_X86_64_PC32 .text+0x136c mov %rax,0x30(%rbx) ... Those .text references point to the middle of the function, causing objtool to complain about their lack of ENDBR. Prevent that by resolving the function pointer at runtime rather than build time. This fixes the following warning: drivers/misc/lkdtm/lkdtm.o: warning: objtool: execute_location+0x23: relo= cation to !ENDBR: .text+0x1378 Cc: Kees Cook Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202503191453.uFfxQy5R-lkp@int= el.com/ Signed-off-by: Josh Poimboeuf Reviewed-by: Kees Cook --- drivers/misc/lkdtm/perms.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/misc/lkdtm/perms.c b/drivers/misc/lkdtm/perms.c index 5b861dbff27e..6c24426104ba 100644 --- a/drivers/misc/lkdtm/perms.c +++ b/drivers/misc/lkdtm/perms.c @@ -28,6 +28,13 @@ static const unsigned long rodata =3D 0xAA55AA55; /* This is marked __ro_after_init, so it should ultimately be .rodata. */ static unsigned long ro_after_init __ro_after_init =3D 0x55AA5500; =20 +/* + * This is a pointer to do_nothing() which is initialized at runtime rather + * than build time to avoid objtool IBT validation warnings caused by an + * inlined unrolled memcpy() in execute_location(). + */ +static void __ro_after_init *do_nothing_ptr; + /* * This just returns to the caller. It is designed to be copied into * non-executable memory regions. @@ -65,13 +72,12 @@ static noinline __nocfi void execute_location(void *dst= , bool write) { void (*func)(void); func_desc_t fdesc; - void *do_nothing_text =3D dereference_function_descriptor(do_nothing); =20 - pr_info("attempting ok execution at %px\n", do_nothing_text); + pr_info("attempting ok execution at %px\n", do_nothing_ptr); do_nothing(); =20 if (write =3D=3D CODE_WRITE) { - memcpy(dst, do_nothing_text, EXEC_SIZE); + memcpy(dst, do_nothing_ptr, EXEC_SIZE); flush_icache_range((unsigned long)dst, (unsigned long)dst + EXEC_SIZE); } @@ -267,6 +273,8 @@ static void lkdtm_ACCESS_NULL(void) =20 void __init lkdtm_perms_init(void) { + do_nothing_ptr =3D dereference_function_descriptor(do_nothing); + /* Make sure we can write to __ro_after_init values during __init */ ro_after_init |=3D 0xAA; } --=20 2.48.1