From nobody Mon Apr 6 21:32:33 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36138ECAAD5 for ; Fri, 2 Sep 2022 14:33:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236706AbiIBOdV (ORCPT ); Fri, 2 Sep 2022 10:33:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236366AbiIBO3a (ORCPT ); Fri, 2 Sep 2022 10:29:30 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 485BB10B7 for ; Fri, 2 Sep 2022 06:54:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=9OeUQ8WKvjmDCQa64vw6vBkwEukGFdObNeGXaylenLQ=; b=McjR//5MoPFNSEkoQkl0Uhh4wU TT57WIwusLJBg2g3/TZ3ToxGWMcoQ3bkV50EUoTjEXQO4XQMjZopdCyNncRieMMB6sC885BfEntSB uPxD+bNYNeQWcHgUHvUlbd234CQnCdNBonoTnMrnH+qrHVCwFEavPg2vydzc8D/uHn6DVc6fts8ys w68n/h6yvneGAuO5zdgDnDIxNshWnkizHMZIJGPAf4qT32W2csJID8N+5ijWR33zm6ZIwQ48KaWQk LmM1ddXc+XaH6dEsHuCY1jmPNFg2ocvgP5a/Y8xXiAB1fkhEwqkGs1PGsS5oktyLkcbVQZKMw29/H yXTfPSSA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1oU77M-008g8J-Su; Fri, 02 Sep 2022 13:54:09 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 2FC0E30220F; Fri, 2 Sep 2022 15:53:54 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 0492B2B8EF7F7; Fri, 2 Sep 2022 15:53:53 +0200 (CEST) Message-ID: <20220902130949.893888696@infradead.org> User-Agent: quilt/0.66 Date: Fri, 02 Sep 2022 15:06:59 +0200 From: Peter Zijlstra To: Thomas Gleixner Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, x86@kernel.org, Linus Torvalds , Tim Chen , Josh Poimboeuf , Andrew Cooper , Pawan Gupta , Johannes Wikner , Alyssa Milburn , Jann Horn , "H.J. Lu" , Joao Moreira , Joseph Nuzman , Steven Rostedt , Juergen Gross , Masami Hiramatsu , Alexei Starovoitov , Daniel Borkmann , K Prateek Nayak , Eric Dumazet Subject: [PATCH v2 34/59] objtool: Allow symbol range comparisons for IBT/ENDBR References: <20220902130625.217071627@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Peter Zijlstra A semi common pattern is where code checks if a code address is within a specific range. All text addresses require either ENDBR or ANNOTATE_ENDBR, however the ANNOTATE_NOENDBR past the range is unnatural. Instead, suppress this warning when this is exactly at the end of a symbol that itself starts with either ENDBR/ANNOTATE_ENDBR. Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Thomas Gleixner Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/entry/entry_64_compat.S | 1 - tools/objtool/check.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) --- a/arch/x86/entry/entry_64_compat.S +++ b/arch/x86/entry/entry_64_compat.S @@ -128,7 +128,6 @@ SYM_INNER_LABEL(entry_SYSENTER_compat_af popfq jmp .Lsysenter_flags_fixed SYM_INNER_LABEL(__end_entry_SYSENTER_compat, SYM_L_GLOBAL) - ANNOTATE_NOENDBR // is_sysenter_singlestep SYM_CODE_END(entry_SYSENTER_compat) =20 /* --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4016,6 +4016,24 @@ static void mark_endbr_used(struct instr list_del_init(&insn->call_node); } =20 +static bool noendbr_range(struct objtool_file *file, struct instruction *i= nsn) +{ + struct symbol *sym =3D find_symbol_containing(insn->sec, insn->offset-1); + struct instruction *first; + + if (!sym) + return false; + + first =3D find_insn(file, sym->sec, sym->offset); + if (!first) + return false; + + if (first->type !=3D INSN_ENDBR && !first->noendbr) + return false; + + return insn->offset =3D=3D sym->offset + sym->len; +} + static int validate_ibt_insn(struct objtool_file *file, struct instruction= *insn) { struct instruction *dest; @@ -4088,9 +4106,19 @@ static int validate_ibt_insn(struct objt continue; } =20 + /* + * Accept anything ANNOTATE_NOENDBR. + */ if (dest->noendbr) continue; =20 + /* + * Accept if this is the instruction after a symbol + * that is (no)endbr -- typical code-range usage. + */ + if (noendbr_range(file, dest)) + continue; + WARN_FUNC("relocation to !ENDBR: %s", insn->sec, insn->offset, offstr(dest->sec, dest->offset));