Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4267785ybb; Tue, 7 Apr 2020 04:14:00 -0700 (PDT) X-Google-Smtp-Source: APiQypI7lk4XjvNg6LwFTMjBPiJ3lBHGL9eH1IfFPK5/xUPcvMcpAtRI5iObmExAO70DZQWIFfYL X-Received: by 2002:aca:5345:: with SMTP id h66mr1267329oib.110.1586258040721; Tue, 07 Apr 2020 04:14:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586258040; cv=none; d=google.com; s=arc-20160816; b=rKZ9jpszB/jsxQXv/RhKDqIE1+I9b2QMx8sHj48dW2kRfFkjq0j1DJyTZnBXnV5K2W 4S67SNyyKz32aLUQq69BJ1rKE8ZuZvbD/jQiXZXYKeshUYaMbuKX8o3lH5ouUcXyqeqf DVuinTqKQUMC+gQ+OJHYcYh6slIO6di+vKM7xyvS4EkDSREfPcSbkb/hz/KTWkiGLjo/ K0jQTaRyu/8NPHmQI0BarUeAoHIck6MRi6qo9XLbwoyvBOjFRmC66mVPb+9QETDM1l93 1m2toqcXEfYK7j42oJBSfLFQU/tUGX5n7GLStz31bPCLAQyyUT1E4WPOwcmGtcC1hf+n 1qHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:subject:cc:to :from:date:user-agent:message-id:dkim-signature; bh=jKJXZpzzDrrjmwLNRHLcBZgkJJqiHAXwqSXGUdiOBYo=; b=rpeDYb7zIc1subuj/XZh3InZ9geTU0BbRWkSXeAmQVf0IYKi6hQiTbn4rWsfj04Htv mqY26v6m7zd9w19chBgrx+xX64C95XqUPmO89kgFdM/nJjvGIf0SKePEXR7uJYW/S0GK we50ep50933pYvIhJ+ATYBxlwysMovRSy4DfG+HBxllGFvXDdXsBwfHKKpDk906HDkja mL3LRhjQLO53UTEGCZZ3HluqjzE6k6Rm/CpmJhRzNbUr1Rs+L64D8HzAzvOHW3q+FAa4 5d9gPBCL9oGMhxowULpzwORt67h6wcDEEKKFnAJCSQiqOgkDhKzDHv6on2uM4mqSPvOT 9lmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=0j+dqzCw; 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 b17si1047007otq.269.2020.04.07.04.13.48; Tue, 07 Apr 2020 04:14:00 -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=0j+dqzCw; 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 S1728557AbgDGLNM (ORCPT + 99 others); Tue, 7 Apr 2020 07:13:12 -0400 Received: from merlin.infradead.org ([205.233.59.134]:42482 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728495AbgDGLNJ (ORCPT ); Tue, 7 Apr 2020 07:13:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-Id:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=jKJXZpzzDrrjmwLNRHLcBZgkJJqiHAXwqSXGUdiOBYo=; b=0j+dqzCwYKeCySGxRekkKqS18I Ci4hvKzYPKjEPtpr0yDYoOQfLkgInKK5Am6VbHyjnWE+6tpIXnkM++yfH69CFy+71eKW0wOLC15EM mGUfAbvj14OTkzee+xcIuGyRFMTgOF1sOzUhvQTCqHlgi6mh3Nmqd1Mkv1N2wiijcwvjjIfEsPut9 meT/gty9dwvqxnuuGuK4n8ZnF2tQvNjMvv04Q8Z595cDgt0rF3ckoUIpnvHZEvJcT8vT3VgJNc8ew 4oVAMlOUcslek5ZWl43n7ciUgQp1chuZYE6BI0o52KWcC1c1GVM5X+ZmFJ5EkMGTD34EdVgEPW9BD 55DFhRVg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jLm9m-0007DP-Oh; Tue, 07 Apr 2020 11:12:39 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 4E45D30604B; Tue, 7 Apr 2020 13:12:36 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 25ACF29C96F21; Tue, 7 Apr 2020 13:12:36 +0200 (CEST) Message-Id: <20200407111007.429362016@infradead.org> User-Agent: quilt/0.65 Date: Tue, 07 Apr 2020 13:02:40 +0200 From: Peter Zijlstra To: tglx@linutronix.de, linux-kernel@vger.kernel.org Cc: hch@infradead.org, sean.j.christopherson@intel.com, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org, kenny@panix.com, peterz@infradead.org, 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: [PATCH 4/4] x86,module: Detect CRn and DRn manipulation References: <20200407110236.930134290@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; + } + text += insn.length; }