Received: by 10.192.165.156 with SMTP id m28csp938565imm; Wed, 11 Apr 2018 09:34:06 -0700 (PDT) X-Google-Smtp-Source: AIpwx48sMv+oN5f42AeWnuRCgTKEdSUo5i8KlJvCwtFGyLdww6SJLusvJTtaopIEc511ZHUZgp0B X-Received: by 10.99.37.196 with SMTP id l187mr4003323pgl.221.1523464446233; Wed, 11 Apr 2018 09:34:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523464446; cv=none; d=google.com; s=arc-20160816; b=pCoW4wmas9cjhW17FZx21+txxtvBkaKFrLj5/IPcoQXfvG66qPe/hL05e0i4Y1em0Y OAdgchnQ91tg9tAVnyiP+yIHaAe8fi1EDH7bfYdPO87U0p1ac68Mj5Kw0SgCZYnZok9c ZXPnYbZFKoS6g9Vofgl5zrWUL3uSG58sE/kEzyDKo4iWuDgKu6e9Hf+VgQFqhlmhWwIe iNXm80zDif+x8ZDp0PKS/5sLODka2m9fAD9ifkqOlybd/i/xV7/6pYrN8C5QMPHiB3GC sp5cIOgA8opalfRNjZ6vO3LeKf2CMudrg7BJYxseu0a4AlvE8fCx1w8gE8SOyQC6YrtQ S6Zg== 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 :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization:arc-authentication-results; bh=DsQYdWLyoP5j0GEtH5G62Jol0BM0cZfgvZN5TY1Dfco=; b=xGdCzjQCXDDIrqAayybb9YmlE7ccKzILzdHYEldjNHbQVBwb9+QHJ55Ksng7Iw/xMa atrVoueVHLcjrobpd7kuDGRcF842PMBMMSU2lpc7FL1rtylKY5Cf2lohMc5WDfEBdCLF CTuSPflgHyt/u+BSwBHLNvFUnabMhC64DG4Ti9KFWsfp/iM5DHQQPrNy9ywkDegedR4B GQsQei4rMN0kg1yo2EOBY6X+9TOXq3eomlVhc2IHxXPOdlsgJJVB/Kec3msejzbrCC3t T+Lo+TspElVmQE5tgt+J0WC7GMKDnZDnapjnY4/US2mENYUICMXKxttuoDMoXp68ppVN l5/Q== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 186si1149917pfe.49.2018.04.11.09.33.11; Wed, 11 Apr 2018 09:34:06 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754155AbeDKQZ5 (ORCPT + 99 others); Wed, 11 Apr 2018 12:25:57 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45170 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754146AbeDKQZy (ORCPT ); Wed, 11 Apr 2018 12:25:54 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 85D1481A88A0; Wed, 11 Apr 2018 16:25:52 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-8.rdu2.redhat.com [10.10.120.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id B0FE4BDC56; Wed, 11 Apr 2018 16:25:51 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 11/24] x86/msr: Restrict MSR access when the kernel is locked down From: David Howells To: torvalds@linux-foundation.org Cc: linux-man@vger.kernel.org, linux-api@vger.kernel.org, jmorris@namei.org, linux-kernel@vger.kernel.org, dhowells@redhat.com, linux-security-module@vger.kernel.org Date: Wed, 11 Apr 2018 17:25:51 +0100 Message-ID: <152346395124.4030.8504337214384655170.stgit@warthog.procyon.org.uk> In-Reply-To: <152346387861.4030.4408662483445703127.stgit@warthog.procyon.org.uk> References: <152346387861.4030.4408662483445703127.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 11 Apr 2018 16:25:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 11 Apr 2018 16:25:52 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'dhowells@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Matthew Garrett Writing to MSRs should not be allowed if the kernel is locked down, since it could lead to execution of arbitrary code in kernel mode. Based on a patch by Kees Cook. MSR accesses are logged for the purposes of building up a whitelist as per Alan Cox's suggestion. Signed-off-by: Matthew Garrett Signed-off-by: David Howells Acked-by: Kees Cook Reviewed-by: Thomas Gleixner Reviewed-by: "Lee, Chun-Yi" cc: x86@kernel.org --- arch/x86/kernel/msr.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c index ef688804f80d..dfb61d358196 100644 --- a/arch/x86/kernel/msr.c +++ b/arch/x86/kernel/msr.c @@ -84,6 +84,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf, int err = 0; ssize_t bytes = 0; + if (kernel_is_locked_down("Direct MSR access")) { + pr_info("Direct access to MSR %x\n", reg); + return -EPERM; + } + if (count % 8) return -EINVAL; /* Invalid chunk size */ @@ -135,6 +140,11 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg) err = -EFAULT; break; } + if (kernel_is_locked_down("Direct MSR access")) { + pr_info("Direct access to MSR %x\n", regs[1]); /* Display %ecx */ + err = -EPERM; + break; + } err = wrmsr_safe_regs_on_cpu(cpu, regs); if (err) break;