Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4777601ybb; Tue, 7 Apr 2020 14:23:14 -0700 (PDT) X-Google-Smtp-Source: APiQypI6VjBcLTODxdAD60vuuGDzPMnI1p20cPjPnQr56BQy5xnSEtyrMjZBIZ00Y0noa6k/U90S X-Received: by 2002:a9d:69c2:: with SMTP id v2mr3395026oto.370.1586294594506; Tue, 07 Apr 2020 14:23:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586294594; cv=none; d=google.com; s=arc-20160816; b=KvmX0qHWp81CrFLcDsK3dw4UAM8FtOmctjJmR/fLGS92lx113ryRpmk05lLOOMkDhV 3ogTr3D8QOf/EitXKGfrTMwg++tgwnrX1Y/5L06hQb962amYmQ3f+yuLvgiTMfpmeZSl JrGNzUVhUvM0TPyJ89CQ/YCrxo2MxdsJxot+fcjYxYuSmtBrhO5HUGvsFodg18Sek1Zx JMJTwoDfH5At+/pLQJ9u0I1wIGqwFNsT8OhNDQZeN5fHbKFEl6tcPkDbTOGx/DX6HpO9 QDGMRVoacRie5KMscJ0KJxi5bYWEYahItpEhEhCSsZCRrjc+QWHuX1XA03spaYmP7jhT wqYg== 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=yZ6mWOaBSDd1vsnUSG4fPGc6uVMtwv1ud0iB0H7fcF0=; b=E0qCeRcO8600k9BPhPoxBtU7Acz9vDaDlWtKWHLAMOfJhDQZkyqi8NzAi3giew0uvo ERI80UEC4zHEVFwJxQue5IcC8+yX5BSOmh4uqk2NOlpfeA4qKlQgdGFQOeAmB2C4r/ca wKEBGRJ+dkoxVNmKRPwTRXt+StSr4B2Y795Iq18no2hWZvg9fuQM059kUlE8xOfqeoWx C5M3aq2MqZJM5A8ekD+YMRo2V/Y5RCpjvJvW94s2qTXwdN4OvCaMUChBh9D0r7mw0FhI TTy/DgJDh0MrHZrA3G3iRnfWr45Ioll4tIRL9onkbJ20RjT8cwL2n+Th28w1QGkdVF/j Pk4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@citrix.com header.s=securemail header.b=B2qz40op; 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 f12si1070445oig.263.2020.04.07.14.23.00; Tue, 07 Apr 2020 14:23:14 -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=B2qz40op; 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 S1726444AbgDGVVI (ORCPT + 99 others); Tue, 7 Apr 2020 17:21:08 -0400 Received: from esa6.hc3370-68.iphmx.com ([216.71.155.175]:22364 "EHLO esa6.hc3370-68.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726380AbgDGVVI (ORCPT ); Tue, 7 Apr 2020 17:21:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1586294467; h=subject:to:cc:references:from:message-id:date: mime-version:in-reply-to:content-transfer-encoding; bh=yohZgO1cSq06DF0y1oMl6qbvylo5IHTJURPzFHgykKA=; b=B2qz40opb6DJJtrtHJqMct2v9NtfyzAcNrFnCL83r2jKbt95d+TRDCHS SeMAYlhvxkBEqy24tcVAJDVQB4vwKTdu4a4/Kr9Chdzko5k1sOp+TXsQ/ 73ZBJYGsJ+GzWBPMrZ2rDySUcOeBWEHIRrRar6b+LdGdN4J8AdQkygNXx o=; Authentication-Results: esa6.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 (esa6.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=esa6.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.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=esa6.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 (esa6.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=esa6.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: T07NPnfs91txdCmkBzYw7URfU7gbHGeWsimmexUlwAFk+7pISy9lknhEjUONEtzYabCua/c4FC 9xsOYdZ0SQy/Gwjegmq58XM0TvJxdGeI/Myp573HIzABBdGd9nE24Y9UdBelg6kPJPqYTaLB/B YJV8/jr22AjwTBz0Vv1aOV3AY5WR2cwPZrMroh40RBuUywuTLipfHMnbKKZvU/zfmM2Qjiz7cF pRWIYnqfnsHf1qtRLi4TFCz2Z1lbGN5ViHiptcRXdLVHas++pQGRi4r9zl35yvxHMwpZaCq976 n28= X-SBRS: 2.7 X-MesageID: 15736135 X-Ironport-Server: esa6.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="15736135" 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> <20200407204530.GR2452@worktop.programming.kicks-ass.net> From: Andrew Cooper Message-ID: <34f2a325-45c4-44e8-595a-187d0d37afa6@citrix.com> Date: Tue, 7 Apr 2020 22:21:02 +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: <20200407204530.GR2452@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 21:45, Peter Zijlstra wrote: >> POPF: Don't really want someone being able to set IOPL3.  However, this >> might quite easily show up as a false positive depending on how the >> irqsafe infrastructure gets inlined. > local_irq_restore() will be a POPF :/ Ok.  Something to consider in an orthogonal direction.  A while ago, I put this into Xen as a security fix: iret_exit_to_guest:         andl  $~(X86_EFLAGS_IOPL|X86_EFLAGS_NT|X86_EFLAGS_VM),24(%rsp)         orl   $X86_EFLAGS_IF,24(%rsp)         addq  $8,%rsp .Lft0:  iretq which unconditionally fixes up the unsafe flags even if something manages to slips through (e.g. local_irq_restore() against stack rubble).  It turns out that it has saved us several CVEs in the intervening time. Is this the kind of things the hardening folk would be interested in? > --- a/arch/x86/kernel/module.c > +++ b/arch/x86/kernel/module.c > @@ -282,6 +282,68 @@ static bool insn_is_mov_DRn(struct insn > return false; > } > > +static bool insn_is_GDT_modifier(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: /* Grp6 */ > + switch (modrm_reg) { > + /* case 0x0: SLDT */ > + case 0x2: /* LLDT */ > + case 0x3: /* LTR */ > + return true; Come to think of it, if you include the Sxxx variants, a sufficiently clever compiler can collapse this entire switch statement into a single "and $~3, modrm_reg" instruction, rather than being forced to use "and $~1, modrm_reg; cmp $2, ...". Probably on the extreme end of micro-optimising however. ~Andrew