Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp674252ybb; Wed, 8 Apr 2020 07:50:01 -0700 (PDT) X-Google-Smtp-Source: APiQypKrQJ5sgObPFMvsYinwY9UYR3uLwvDd9soRk8fxS1f4NISf/D1E1PdBta1rL6jLMJiYrJDF X-Received: by 2002:a9d:734a:: with SMTP id l10mr1279882otk.42.1586357401633; Wed, 08 Apr 2020 07:50:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586357401; cv=none; d=google.com; s=arc-20160816; b=huo1weMJKMyl+PN2nSA6WZnQ5wZ6DTi6NrXx7DaxpYYm7rdPpIRFGtBX4dP9DS12kA aWa2GdnEBfIMu4dNCfqRbBiLD41/5L4u5D31DdWMaLke45an8vKqyQRd0uFh9zrittlC Q4ed7ZRKfzdemljHnMrHngsoLLFHpwV1NXhsfRETpelfCX5YfcTDrfIllIDaLHz9vb8t PStiMCdcj/t2MX9yMRN6LM27VISaP1qcND+bnPAnrubnO7URNj+zFQ5UYL42vAfV/1Yo DJG7PCouzaoINCS5qUA3LEtRHPq/SBM+Zy0/aOe2nSIIhl7WFyJjzqRHU51vrcZyCPU4 OmYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=7OIjY5EoKX4C6RwhttNL2PupNTxB5BnerOr9r6nnl9Y=; b=0dryYW+IAKzG5tshrt3Bce44YPRE/H5kk0e0RJo6Z5Iy/BhEAEUKsYIuIriYNCGxa7 05fn9yqheCmbfM9J9ZI06yqVDNzqSeCAwJzs9Yuu/gXUe9MOQOXfRA0j0/PBUoUUuYP/ /1k9nxxfDdtPJyYzwEDYlKRhnzKlsYCWAEhDTDmdcl4FEcwL1XMr7B7+pIJV5S6mNucm HizBRKBrFXS2STazBlDHpS4YGyfbstIByU77gOdPBHe10AUJ5HC6cqaHGb4V9HOqiXfB XsOUmvO4VkxVsn4SLqg5pFGF7FAR//cQXloG2mA2ZCY6IZj7kXKSRFqBedBAXi9G+RO6 PD1A== ARC-Authentication-Results: i=1; mx.google.com; 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 l4si2165131otr.212.2020.04.08.07.49.48; Wed, 08 Apr 2020 07:50:01 -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; 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 S1729150AbgDHN1b (ORCPT + 99 others); Wed, 8 Apr 2020 09:27:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:55460 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727795AbgDHN1a (ORCPT ); Wed, 8 Apr 2020 09:27:30 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 40A6E2072A; Wed, 8 Apr 2020 13:27:28 +0000 (UTC) Date: Wed, 8 Apr 2020 09:27:26 -0400 From: Steven Rostedt To: Peter Zijlstra 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, gregkh@linuxfoundation.org, jannh@google.com, keescook@chromium.org, David.Laight@aculab.com, dcovelli@vmware.com, mhiramat@kernel.org Subject: Re: [PATCH 4/4] x86,module: Detect CRn and DRn manipulation Message-ID: <20200408092726.7c2bda01@gandalf.local.home> In-Reply-To: <20200407111007.429362016@infradead.org> References: <20200407110236.930134290@infradead.org> <20200407111007.429362016@infradead.org> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 07 Apr 2020 13:02:40 +0200 Peter Zijlstra wrote: > Since we now have infrastructure to analyze module text, disallow > modules that write to CRn and DRn registers. > > Signed-off-by: Peter Zijlstra (Intel) > --- > arch/x86/kernel/module.c | 21 +++++++++++++++++++++ > 1 file changed, 21 insertions(+) > > --- a/arch/x86/kernel/module.c > +++ b/arch/x86/kernel/module.c > @@ -266,6 +266,22 @@ static bool insn_is_vmx(struct insn *ins > return false; > } > > +static bool insn_is_mov_CRn(struct insn *insn) > +{ > + if (insn->opcode.bytes[0] == 0x0f && insn->opcode.bytes[1] == 0x22) > + return true; > + > + return false; > +} > + > +static bool insn_is_mov_DRn(struct insn *insn) > +{ > + if (insn->opcode.bytes[0] == 0x0f && insn->opcode.bytes[1] == 0x23) > + return true; > + > + 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(); > @@ -285,6 +301,11 @@ static int decode_module(struct module * > return -ENOEXEC; > } > > + if (insn_is_mov_CRn(&insn) || insn_is_mov_DRn(&insn)) { > + pr_err("Module writes to CRn or DRn, please use the proper accessors: %s\n", mod->name); > + return -ENOEXEC; > + } > + Something like this should be done for all modules, not just out of tree modules. -- Steve