Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp4457724imc; Mon, 25 Feb 2019 05:22:00 -0800 (PST) X-Google-Smtp-Source: AHgI3IZTBlaW9rSvNwS8Zd7Sxch+cKRtBstc90O+vvU04w0VkPeucFgy1NYLeclKQjA0zc55/BKA X-Received: by 2002:aa7:83c2:: with SMTP id j2mr20240770pfn.119.1551100919973; Mon, 25 Feb 2019 05:21:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551100919; cv=none; d=google.com; s=arc-20160816; b=JMuebN97tSY7DxK/V0pDfF5T844KlpeDfgNHeACnTYQm09LdJsJENjI9s1eYNLoU6a xbwo7wA/K8J6TVOMYJyanlthSU8fD/OnMtMnyCEkFsgzy5SylDS0BXVgIMv9d8hYoAcy Vln7GRAHMdbx33EuHKtiJrwLdqW6ssP0qPLUCby0K3YOXn5uHwobmMpG0wye43S+PffH ii1O2jF5kxj6buWLTm18To9ZJqa8pMPfU5aF6OslkPpBEPDMH8J0bm4oOoY1fs5Ue42w VBu+HlFm8rPo/4P39Rn35SJVFDQe7UugSTaEyJRUAvcnr7F5q0aokIlGVynoBI6uwZvo Kb5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=LSaiudI9zMFRYwqyfTbYs2Hi81Jc0hIhsm+H3pY+7wo=; b=fSlDcIxFMvmmo71NXSXRe20WN6mt0sQYvNjQJlC2Txv2ESyq5VPNwh4MHZlVxRYOv6 EEP8F7OkLxTZ3cVe9XkuhYZOl0M4i4YH95AEJkrA/21JGjG2zFl+01W0jeYqDwJp/l5W 0UyIQfZnKPwDWbF4K4fH4fXNC+5FD7XCbQg1rkuRb4ZYHrzRbw+9kS2GGPmAnDg497/N TAwCNyObsoXzc/Ip/EAt/DZPbQau3Kfkvc9pUES+Zj8Xw3Q3U4atgoYEcCF8XB3AGNVz DPBgTPyTB0lEB8cP9izl252O40KnbXVw28S0N8hpE09n1p3nF3w13LJYXcKWYTdcZvLQ TYLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=qFHtWjQr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r16si9599249pgm.483.2019.02.25.05.21.44; Mon, 25 Feb 2019 05:21:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=qFHtWjQr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727247AbfBYNVP (ORCPT + 99 others); Mon, 25 Feb 2019 08:21:15 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:34782 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726921AbfBYNVP (ORCPT ); Mon, 25 Feb 2019 08:21:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=LSaiudI9zMFRYwqyfTbYs2Hi81Jc0hIhsm+H3pY+7wo=; b=qFHtWjQrZ76I+mb73nV4DaXMpe kpqeHQf6WNXzN2/D1mA6BLaQzvP/e2uZ+fbDeN+He7i5N+ayTQVFjmN5CGFXoWWFmwBWyJ8Ig5d95 qYbKp7Sgzr8LXwo0M8aiex4QNZBCxk3CWk8LL3TMlZ4UqbCx8VdcuTmd/xuRATr7Hr6dqZo2BhJ9x I+23UHAH8kBh247CUF2iLwjSPpnvj7EENTmjstQNTuvRWqQus2CiRNHiFveummIQy7h3AboXBfB5+ de8HsdoictYy/xzC6uZExvp1scl74cemdd2JJbTbAK0/U/+PP+wtNFLxT12AxaBp7n9oJyJpnKeQ8 kYItUXWA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gyGBu-0001wS-DG; Mon, 25 Feb 2019 13:21:06 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id A112F236F9A0D; Mon, 25 Feb 2019 14:21:03 +0100 (CET) Date: Mon, 25 Feb 2019 14:21:03 +0100 From: Peter Zijlstra To: hpa@zytor.com Cc: Thomas Gleixner , Linus Torvalds , Julien Thierry , Will Deacon , Andy Lutomirski , Ingo Molnar , Linux List Kernel Mailing , "linux-alpha@vger.kernel.org" , Ingo Molnar , Catalin Marinas , James Morse , valentin.schneider@arm.com, Brian Gerst , Josh Poimboeuf , Andrew Lutomirski , Borislav Petkov , Denys Vlasenko Subject: Re: [RFC][PATCH] objtool: STAC/CLAC validation Message-ID: <20190225132103.GD32494@hirez.programming.kicks-ass.net> References: <20190219124808.GG8501@fuggles.cambridge.arm.com> <20190222222635.GK14054@worktop.programming.kicks-ass.net> <20190223083942.GF32477@hirez.programming.kicks-ass.net> <15DE0017-9AE5-4E7A-96CD-E5E9F5B72516@zytor.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <15DE0017-9AE5-4E7A-96CD-E5E9F5B72516@zytor.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 25, 2019 at 12:47:00AM -0800, hpa@zytor.com wrote: > It doesn't have to understand the contents of the memop, but it seems > that the presence of a modrm with mode ≠ 3 should be plenty. It needs > to know that much in order to know the length of instructions anyway. > For extra credit, ignore LEA or hinting instructions. A little something like so then? arch/x86/kernel/fpu/signal.o: warning: objtool: .altinstr_replacement+0x9c: UACCESS disable without MEMOPs: copy_fpstate_to_sigframe() 00000000023c 000200000002 R_X86_64_PC32 0000000000000000 .text + 604 000000000240 000700000002 R_X86_64_PC32 0000000000000000 .altinstr_replacement + 99 000000000249 000200000002 R_X86_64_PC32 0000000000000000 .text + 610 00000000024d 000700000002 R_X86_64_PC32 0000000000000000 .altinstr_replacement + 9c .text 604: 90 nop 605: 90 nop 606: 90 nop 607: 83 ce 03 or $0x3,%esi 60a: 89 b3 00 02 00 00 mov %esi,0x200(%rbx) 610: 90 nop 611: 90 nop 612: 90 nop .altinstr_replacement 99: 0f 01 cb stac 9c: 0f 01 ca clac Which looks like the tool failed to recognise that MOV as a memop. --- --- a/tools/objtool/arch.h +++ b/tools/objtool/arch.h @@ -37,7 +37,8 @@ #define INSN_CLAC 12 #define INSN_STD 13 #define INSN_CLD 14 -#define INSN_OTHER 15 +#define INSN_MEMOP 15 +#define INSN_OTHER 16 #define INSN_LAST INSN_OTHER enum op_dest_type { --- a/tools/objtool/arch/x86/decode.c +++ b/tools/objtool/arch/x86/decode.c @@ -123,6 +123,9 @@ int arch_decode_instruction(struct elf * modrm_mod = X86_MODRM_MOD(modrm); modrm_reg = X86_MODRM_REG(modrm); modrm_rm = X86_MODRM_RM(modrm); + + if (modrm_mod != 3) + *type = INSN_MEMOP; } if (insn.sib.nbytes) --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2047,6 +2047,7 @@ static int validate_branch(struct objtoo WARN_FUNC("recursive UACCESS enable", sec, insn->offset); state.uaccess = true; + state.memop = false; break; case INSN_CLAC: @@ -2058,6 +2059,9 @@ static int validate_branch(struct objtoo break; } + if (!state.memop && insn->func) + WARN_FUNC("UACCESS disable without MEMOPs: %s()", sec, insn->offset, insn->func->name); + state.uaccess = false; break; @@ -2075,6 +2079,10 @@ static int validate_branch(struct objtoo state.df = false; break; + case INSN_MEMOP: + state.memop = true; + break; + default: break; } --- a/tools/objtool/check.h +++ b/tools/objtool/check.h @@ -31,7 +31,7 @@ struct insn_state { int stack_size; unsigned char type; bool bp_scratch; - bool drap, end, uaccess, uaccess_safe, df; + bool drap, end, uaccess, uaccess_safe, df, memop; int drap_reg, drap_offset; struct cfi_reg vals[CFI_NUM_REGS]; };