Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4703496ybb; Tue, 7 Apr 2020 12:42:37 -0700 (PDT) X-Google-Smtp-Source: APiQypKkXwDCQ0urtwsIRMu3EFuIqpbEISVIBOfau12hJYwrJcvaV+SwpKlbXT1PNdpWVAyjSHbH X-Received: by 2002:aca:a882:: with SMTP id r124mr380947oie.53.1586288557245; Tue, 07 Apr 2020 12:42:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586288557; cv=none; d=google.com; s=arc-20160816; b=xZsYTlKkkTlIwqWby5p9qtbp/N83gmVDdA4qDmUtltT4XBjUQHfXo6i406+hRkSHVa VRE8cN4vDmIbGnE6oLVCnrZRJG8C4262gYwEMbGg+FW8I0t63dycfjst07XyHmDX4jMf 70ZXO/HawkCHVdnCjGF5YsTbzTxtMKzUhz3d2t04UzGBxOMV5+0lvrd09KbBnGVLctgb ZycVe8xThzngzFXJa5M9A0oT5ANfOkrWwOEdN+XY34Sdmodrdi6vuOG4c+ALB6l5AH+q fqK3ZrFoj39dZrCiN3TaBq0n6TyHZM0LUICix1AyVXUW8rjlrEnt/zOyJDEDpYlpoNco LW+g== 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=rg9Zo5WhZ/L+g9noY6cXA3kVA2E3WxWXpgepHp8ztII=; b=Nm90QdESttNpOm+ZS8V5G2xFmobsjylVXOh2RsTinUtiq5NEJsLxK0kveITXDQf7X3 /qfbnxAsKqpVIP2EyK99b2f9G14pHGuoGAGeiGpPrq95AYIk65OKfmtok85W/W7R5ZGO T7KCtTlWTzGF3xLfeEt85kU/c+ubOh/z5DJUstKbMONfwjmCpja2NWhtrbgjwl2MDDT+ Tcsea/Cjy56Wn+ruJUeDMQ6kRi4wWyh6csL98heHBH8/D6MaD/H6L5OnO+otntj28WIt ww7p7nnPKtE1THhFx4nbZ+urAD6zQW+gvkCFgY/FKGGl7/4ozbMdx88cnlKJ94UYEBRl PP/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=3BXaZZxq; 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 j9si954960oif.164.2020.04.07.12.42.22; Tue, 07 Apr 2020 12:42:37 -0700 (PDT) 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=merlin.20170209 header.b=3BXaZZxq; 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 S1726740AbgDGTlp (ORCPT + 99 others); Tue, 7 Apr 2020 15:41:45 -0400 Received: from merlin.infradead.org ([205.233.59.134]:57106 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726712AbgDGTlo (ORCPT ); Tue, 7 Apr 2020 15:41:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.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; bh=rg9Zo5WhZ/L+g9noY6cXA3kVA2E3WxWXpgepHp8ztII=; b=3BXaZZxqSeNXfw7lYzC50SSaKp gBC/wiEU6omWRWUOXz2LqoCNgAH1d0vz8h3dVqHXk4zrl9mGtICZgeXUYvj2csOMLgD8LCexqGsIJ YE1QcAAKqcH+3zrfzEOYXqr8BxQbYDLi/QpnNRgPRSmM7aWwAS7cd6QoVHfawdZTSPHoz4LwvOOuk Qx+srqlN1ydZt0RSWaKpxRpaVWFd1PnWwf6v58wyX8D+lYDCwU5Ugb/FVqU5jw2DLhuQ5Kxp/sTkm Copr7Vowiisz52ko/Q4T5IYECgBqupfJsAS36K3jir3z0bixkP2mBaRBL5wqJZwkBPlUuvvweK8hb kc8MM2yQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=worktop.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jLu5y-0000vz-Di; Tue, 07 Apr 2020 19:41:14 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id 92B9E983507; Tue, 7 Apr 2020 21:41:12 +0200 (CEST) Date: Tue, 7 Apr 2020 21:41:12 +0200 From: Peter Zijlstra To: Andrew Cooper Cc: tglx@linutronix.de, linux-kernel@vger.kernel.org, hch@infradead.org, sean.j.christopherson@intel.com, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org, kenny@panix.com, jeyu@kernel.org, rasmus.villemoes@prevas.dk, pbonzini@redhat.com, fenghua.yu@intel.com, xiaoyao.li@intel.com, nadav.amit@gmail.com, thellstrom@vmware.com, tony.luck@intel.com, rostedt@goodmis.org, gregkh@linuxfoundation.org, jannh@google.com, keescook@chromium.org, David.Laight@aculab.com, dcovelli@vmware.com, mhiramat@kernel.org Subject: Re: [PATCH 0/4] x86/module: Out-of-tree module decode and sanitize Message-ID: <20200407194112.GQ2452@worktop.programming.kicks-ass.net> References: <20200407110236.930134290@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 Tue, Apr 07, 2020 at 06:23:27PM +0100, Andrew Cooper wrote: > On 07/04/2020 12:02, Peter Zijlstra wrote: > > Hi all, > > > > Driven by the SLD vs VMX interaction, here are some patches that provide means > > to analyze the text of out-of-tree modules. > > > > The first user of that is refusing to load modules on VMX-SLD conflicts, but it > > also has a second patch that refulses to load any module that tries to modify > > CRn/DRn. > > > > I'm thinking people will quickly come up with more and more elaborate tests to > > which to subject out-of-tree modules. > > Anything playing with LGDT & friends?? Shouldn't be substantially more > elaborate than CR/DR to check for. More friends? (I wasn't sure on the Sxxx instructions, they appear harmless, but what do I know..) I was also eyeing LSL LTR LSS, none of which I figured a module has any business of using. Are there more? --- a/arch/x86/kernel/module.c +++ b/arch/x86/kernel/module.c @@ -282,6 +282,50 @@ static bool insn_is_mov_DRn(struct insn return false; } +static bool insn_is_LxDT(struct insn *insn) +{ + u8 modrm = insn->modrm.bytes[0]; + u8 modrm_mod = X86_MODRM_MOD(modrm); + u8 modrm_reg = X86_MODRM_REG(modrm); + + if (insn->opcode.bytes[0] != 0x0f) + return false; + + switch (insn->opcode.bytes[1]) { + case 0x00: + if (modrm_mod != 0x03) + break; + + switch (modrm_reg) { + case 0x0: /* SLDT */ + case 0x2: /* LLDT */ + return true; + + default: + break; + } + break; + + case 0x01: + switch (modrm_reg) { + case 0x0: /* SGDT */ + case 0x1: /* SIDT */ + case 0x2: /* LGDT */ + case 0x3: /* LIDT */ + return true; + + default: + break; + } + break; + + default: + break; + } + + return false; +} + static int decode_module(struct module *mod, void *text, void *text_end, bool sld_safe) { bool allow_vmx = sld_safe || !split_lock_enabled();