Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1742945pxm; Thu, 24 Feb 2022 08:33:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJwPZfCNpH8fRPq4dn3WLRuVQjt25Q7jCvUad1I/2hiPLK6zMlIrOMIVoFTV4oq9uy1i7bi3 X-Received: by 2002:a62:830e:0:b0:4c9:25cb:e1e with SMTP id h14-20020a62830e000000b004c925cb0e1emr3616003pfe.42.1645720387346; Thu, 24 Feb 2022 08:33:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645720387; cv=none; d=google.com; s=arc-20160816; b=jrNFjXaHVDt2oOspJtlb+Gw0EGH9w8zZOecxTQ4niWX5POEYWKRhXcm3ZSP3vdMlHz 4O+YSiRNR9l/gsCbwS5q7LxCSaSyaec60hL1VOcGSgvkNPEVFjhCtUnU3N9Kq2SIqc2Z 1c78mc882r8fke3D/KRPzTP0ykAYViOn4hL/m7ESHcW0u++4FlR/uBgLqWUAi1su1snq h84aEn6DbsY81riuqA5VK8ist8fDeN+yjYqq0gzuqul/wwESWvt5L1x6/Cbeg0jLk8Yp EV4M9Wz7by7TU9n2YXT+GJ45jRpdYunWQqGzHsoTHUIRbbRksTr6ncBiPC7DvLMMqX1H rJ4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id:dkim-signature; bh=YYTQCCPICco3x1N92pao1rPFe2dbVtaCkYMUBxoVGeY=; b=I6Oqb97gxHRWyPaDjOoyfQJ8AKo4k1PlBP0phHOqvHffDrJvi+fPKP4FNvuKFz2EiU tyV1OujWfleI8dSFJ78RCB9+Rlegm/DQwDvx9VUdDbvK/0vHEv4zVnreV1j5dnTLebtZ 2G3c8IipT0FeDsSN2SLhEAZvk4FtA1jjAc8+YAagJ2IZEYwhbuoG071ZiWsBgRN1Cg3R vjs4X0AR63DgFgGOqwSw7SK/OPGza2+uN0lE9bisl9wUdIT6vpqorZWYgLg4Lr8cvFxX YZbPtPEVqRwNE3whZ0SMnzJaMEPcr7EdiNeo/5F8HMKGiQdUWNwqflw0Th3BGWk5j18K IUEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=l4h3wUlL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s10si2983092pfg.171.2022.02.24.08.33.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 08:33:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=l4h3wUlL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D68B8198D2A; Thu, 24 Feb 2022 08:17:22 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235988AbiBXPUR (ORCPT + 99 others); Thu, 24 Feb 2022 10:20:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235992AbiBXPSh (ORCPT ); Thu, 24 Feb 2022 10:18:37 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5378615B9B7 for ; Thu, 24 Feb 2022 07:17:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=YYTQCCPICco3x1N92pao1rPFe2dbVtaCkYMUBxoVGeY=; b=l4h3wUlLOgMT8r1AyUmo3rYT/X Wwfp+XU2zRXKDm4+Xr6jFfTuO4Pk16lKFyffe51UHD+aRysWJcP+H0xL2mG/zdWUqYCpRHofJq1xb iK7VwiYsweJfbVI8eFY0828YY90kPU1TBWE7V9Z01ushZNTMBRKiFwl9ABWQQjq4If3VMRjaPeAYP BfpL6LBAwaaC/VX7wggNF/eIE12cLfuDKHBqfefRemOH50ZNcIhi/JDQndAuJoKlHXifQDDrsSs/a J4hyM0DE1NfcoBdNhTFKiyPVXDpNEOG2TPF5x98yNohn791c7rlb6iXNvHMkJa1PlmY0Hm9ISoSra 7GX7QmbA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNFs4-004s2F-0X; Thu, 24 Feb 2022 15:17:32 +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 4D363302D66; Thu, 24 Feb 2022 16:17:29 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id A29632B3547A9; Thu, 24 Feb 2022 16:17:28 +0100 (CET) Message-ID: <20220224151323.959862564@infradead.org> User-Agent: quilt/0.66 Date: Thu, 24 Feb 2022 15:52:11 +0100 From: Peter Zijlstra To: x86@kernel.org, joao@overdrivepizza.com, hjl.tools@gmail.com, jpoimboe@redhat.com, andrew.cooper3@citrix.com Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, ndesaulniers@google.com, keescook@chromium.org, samitolvanen@google.com, mark.rutland@arm.com, alyssa.milburn@intel.com, mbenes@suse.cz, rostedt@goodmis.org, mhiramat@kernel.org, alexei.starovoitov@gmail.com Subject: [PATCH v2 33/39] objtool: Add IBT/ENDBR decoding References: <20220224145138.952963315@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Decode ENDBR instructions and WARN about NOTRACK prefixes. Signed-off-by: Peter Zijlstra (Intel) --- tools/objtool/arch/x86/decode.c | 34 +++++++++++++++++++++++++++++----- tools/objtool/include/objtool/arch.h | 1 + 2 files changed, 30 insertions(+), 5 deletions(-) --- a/tools/objtool/arch/x86/decode.c +++ b/tools/objtool/arch/x86/decode.c @@ -103,6 +103,18 @@ unsigned long arch_jump_destination(stru #define rm_is_mem(reg) (mod_is_mem() && !is_RIP() && rm_is(reg)) #define rm_is_reg(reg) (mod_is_reg() && modrm_rm == (reg)) +static bool has_notrack_prefix(struct insn *insn) +{ + int i; + + for (i = 0; i < insn->prefixes.nbytes; i++) { + if (insn->prefixes.bytes[i] == 0x3e) + return true; + } + + return false; +} + int arch_decode_instruction(struct objtool_file *file, const struct section *sec, unsigned long offset, unsigned int maxlen, unsigned int *len, enum insn_type *type, @@ -112,7 +124,7 @@ int arch_decode_instruction(struct objto const struct elf *elf = file->elf; struct insn insn; int x86_64, ret; - unsigned char op1, op2, op3, + unsigned char op1, op2, op3, prefix, rex = 0, rex_b = 0, rex_r = 0, rex_w = 0, rex_x = 0, modrm = 0, modrm_mod = 0, modrm_rm = 0, modrm_reg = 0, sib = 0, /* sib_scale = 0, */ sib_index = 0, sib_base = 0; @@ -137,6 +149,8 @@ int arch_decode_instruction(struct objto if (insn.vex_prefix.nbytes) return 0; + prefix = insn.prefixes.bytes[0]; + op1 = insn.opcode.bytes[0]; op2 = insn.opcode.bytes[1]; op3 = insn.opcode.bytes[2]; @@ -492,6 +506,12 @@ int arch_decode_instruction(struct objto /* nopl/nopw */ *type = INSN_NOP; + } else if (op2 == 0x1e) { + + if (prefix == 0xf3 && (modrm == 0xfa || modrm == 0xfb)) + *type = INSN_ENDBR; + + } else if (op2 == 0x38 && op3 == 0xf8) { if (insn.prefixes.nbytes == 1 && insn.prefixes.bytes[0] == 0xf2) { @@ -636,20 +656,24 @@ int arch_decode_instruction(struct objto break; case 0xff: - if (modrm_reg == 2 || modrm_reg == 3) + if (modrm_reg == 2 || modrm_reg == 3) { *type = INSN_CALL_DYNAMIC; + if (has_notrack_prefix(&insn)) + WARN("notrack prefix found at %s:0x%lx", sec->name, offset); - else if (modrm_reg == 4) + } else if (modrm_reg == 4) { *type = INSN_JUMP_DYNAMIC; + if (has_notrack_prefix(&insn)) + WARN("notrack prefix found at %s:0x%lx", sec->name, offset); - else if (modrm_reg == 5) + } else if (modrm_reg == 5) { /* jmpf */ *type = INSN_CONTEXT_SWITCH; - else if (modrm_reg == 6) { + } else if (modrm_reg == 6) { /* push from mem */ ADD_OP(op) { --- a/tools/objtool/include/objtool/arch.h +++ b/tools/objtool/include/objtool/arch.h @@ -27,6 +27,7 @@ enum insn_type { INSN_STD, INSN_CLD, INSN_TRAP, + INSN_ENDBR, INSN_OTHER, };