Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4733985ybb; Tue, 7 Apr 2020 13:23:05 -0700 (PDT) X-Google-Smtp-Source: APiQypIU401xXF8mN1zPB214s2kRzEJLo98m1KlGY2t1HOPLTkc2A4CRTRWEIVifRyiKuZoBNkfn X-Received: by 2002:a05:6830:1d98:: with SMTP id y24mr3110935oti.76.1586290985756; Tue, 07 Apr 2020 13:23:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586290985; cv=none; d=google.com; s=arc-20160816; b=verP4YRH4I3gDg8v6qnrkQNLy97ssosOB5sX15Z1GMcZRCrVHqsH0ZhyRWjuaQPr/R 9CYdMZ7Auor1dJsuZ3ObnyXEfBKaca20E/P4fPjtvGx6HKPzdz+m0tVxa20DUCRtXPLS FuN2qfANT1MV6S1xGmI7u1wrS6WsTA1joJwRwaQ7aBII9FBExI3cTz/0mg11h0DpmQmF SKeW1x6MovKJ4yDWmxeRdaPSHfWkgdKqYQiY1yoJfKNXumLkHYuu90bYRcrdGm+sMRJw OMjmZg9zxd6QVvHg81W92IK16PRE+GLa3H3iFYhd1DJIyC8Rk7FCBXN9+1D3GxsN5S5a 57Vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:ironport-sdr :dkim-signature; bh=BLF1MTCLarqCdo+KrKfcsuqnySU+kXRQSXh0txa1Q6o=; b=KEBED3JOmEumFmErolKsG7cJuoRVR83QBJikRcL3layQVjx5mjsK4EwoZPUKxJ9jJC fEQKIjA5XJhjqNKs3HjS02Cff7KG0+p738nYy1sxnXpk3pvDVDm6sEUElRL1DppNBwi6 2by8AYXS5M20LU7Xam72kGsiA/XL9hIOr3kwP12Mfboos0k1C2cDu9hm85cxS0x513sq wFGIQ/S8LsLvMS0yoVxiGbZMRkSkooHtfPQCgl8Nd7F6l4evCKhPMWHHcL/y4euQQ1te Y3jNME178Ri4z6JS4g4Wlioe3n43u29u6Az7kgYwGuMFBfe1II8oTpAkA7B46xx535Bf hI3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@citrix.com header.s=securemail header.b=XjIsjt7K; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=citrix.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b16si1504640oop.83.2020.04.07.13.22.51; Tue, 07 Apr 2020 13:23:05 -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=@citrix.com header.s=securemail header.b=XjIsjt7K; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=citrix.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727611AbgDGUVj (ORCPT + 99 others); Tue, 7 Apr 2020 16:21:39 -0400 Received: from esa4.hc3370-68.iphmx.com ([216.71.155.144]:34173 "EHLO esa4.hc3370-68.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726719AbgDGUVi (ORCPT ); Tue, 7 Apr 2020 16:21:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1586290897; h=subject:to:cc:references:from:message-id:date: mime-version:in-reply-to:content-transfer-encoding; bh=WtVl2Tqlgobs3aTGznDkxrp2IRy/nD6GLGW1APrqHHY=; b=XjIsjt7KYWpO3BMgvTOK/FxHB7NIiwyCAfS8YBn9qKsSAXAZD3tU3/YZ sCIp6TGBw/yUrNHCNPgaivTDWEFEKWveTfLIKh6NUsux94leIfprxWXRz bCeayo1B0ThHOu25FoKOfURVJW520ZV6LoJl8S2mSzMVLMxf3pK93C1xB k=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=andrew.cooper3@citrix.com; spf=Pass smtp.mailfrom=Andrew.Cooper3@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="Andrew.Cooper3@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 1eDelT3dZ0888ZvXjwp6+FAhyRUH3fRbOibIZI8yY9Gxmy9iGmv1WSxTdw9nmc6e3y8ppZdh7j M6jN4Rq1bsoMYcSNTSTyM2YV801o4rJh8FrLoKgLi7mbuZvUT1PkYMcOTzXwQMlKy46eg+pZJB CaFLEQEpjXzN09jZMHVjCCF7pPdE0Hq4RsQ2u87YxXzGg5cTBOUrv89QeFaLdvye6DUPljvxlw DFX1eMatkkhImuuD/qwrjBRyCLK6/gWyn+X3MHTVJo6oMlBAyH57OsYmrbin5EWbEXKHP2cGBO Qv4= X-SBRS: 2.7 X-MesageID: 15994726 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.72,356,1580792400"; d="scan'208";a="15994726" Subject: Re: [PATCH 0/4] x86/module: Out-of-tree module decode and sanitize To: Peter Zijlstra CC: , , , , , , , , , , , , , , , , , , , , , , , References: <20200407110236.930134290@infradead.org> <20200407194112.GQ2452@worktop.programming.kicks-ass.net> From: Andrew Cooper Message-ID: <3245cf5e-b21b-634e-a9d7-a63d55145c33@citrix.com> Date: Tue, 7 Apr 2020 21:21:31 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <20200407194112.GQ2452@worktop.programming.kicks-ass.net> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Content-Language: en-GB X-ClientProxiedBy: AMSPEX02CAS01.citrite.net (10.69.22.112) To AMSPEX02CL02.citrite.net (10.69.22.126) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/04/2020 20:41, Peter Zijlstra wrote: > 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; > + Apologies - missed this before.  LLDT and LTR can be encoded with a memory operand, so you need to drop the modrm_mod check to spot all instances. ~Andrew