Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp102547imb; Thu, 28 Feb 2019 17:27:16 -0800 (PST) X-Google-Smtp-Source: APXvYqxTd0Fqmdsq5/zH607VTWf5XKLku6UQ45rebiWKwGWdb9JNzVSIrjmydz9sByBh/zub72S9 X-Received: by 2002:a17:902:1347:: with SMTP id r7mr2643988ple.82.1551403636635; Thu, 28 Feb 2019 17:27:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551403636; cv=none; d=google.com; s=arc-20160816; b=bzeAj88AcsvZ5Fp1rSRGj/qSsLtPF5yBebZ+MMHXRFn5EVnUszmVwYkrJBgzzW8UYX FZ/MEsxEVQlbpipmX0V0dJ9Lu1qoBu7AOIVBTULW1HuFz9oTa9rKoWle6zOJUFCud1gn c8jcNHZ5BAFG51Oetr+wP+/Z02vjFcOEo9uTbVrUTjP8g1H/ga56d4XlisiT5N0A3SjX eHMHq1gT5BOSn0KOYquTon0TyQvIzADdPs4KG4xGfNIyl4AO42Ev3qPTPnOLG+wV+Jjp wua+gHNdv8WuOCojs03uT+3jtxK5hASNVvfR278kE4LeC/TMfROnDUfbnVyyNgM7QNLx tccA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=VhmO31ASaR5AbbhJWKJOBB028OwydePZqKoH4vU4z54=; b=wSDNxaY4/TYf8ng0OMRP6HuP57VzEjBYp4NRHMvH5vpI8kRbVzqTk9h4pSjyoYnpw4 0JxaucCsDP8KxgTt5IiBhwFrWoDsGTlyZdO/0HyixJvwTNVyKlZPqgEhBumeTjF33niH EZCPJwzwx431LOp3XhvdfkjLMJz6PwZiWBczDspUxT9qhndzc9sgvwYUqeUUq3rFNqYj QVEotWTTGjgTiWL+LBoHRs3SfYq0FXaa3P6YQLJLoHNVE2Ii32+k9ES7KsaOEZF38fCC lKEEaTF3wqeFizE+v+lfM1ZJD4e+sM0SxXxvJJohHSk/SiIDUTajPOYcnvh/VShxxNsG lEcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VxgH7GKW; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f11si18386279plo.96.2019.02.28.17.27.00; Thu, 28 Feb 2019 17:27:16 -0800 (PST) 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=pass header.i=@google.com header.s=20161025 header.b=VxgH7GKW; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387856AbfB1XMk (ORCPT + 99 others); Thu, 28 Feb 2019 18:12:40 -0500 Received: from mail-qt1-f201.google.com ([209.85.160.201]:45046 "EHLO mail-qt1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387827AbfB1XMi (ORCPT ); Thu, 28 Feb 2019 18:12:38 -0500 Received: by mail-qt1-f201.google.com with SMTP id c9so19960201qte.11 for ; Thu, 28 Feb 2019 15:12:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=VhmO31ASaR5AbbhJWKJOBB028OwydePZqKoH4vU4z54=; b=VxgH7GKWv5U4pP/baW0EyNSMJWfYR8gz/BNo9nVnFnEbb7Wbl++IfRu+fPTJW+sC+t abIrkqtE/EIbIUcTRr00QmRoWKgu6q69FQ2LLvQPHXNRek+QGxuYUXxmcjQvTQ+NZnm/ xyWgVAEFG4KKloh3LwEDipU9xFX9B/8XIFCDbJ9pQHU9bvru88IxfktsGmYgZxc8nE1k F6u5QdZr+olLTyOkzOs2Wpa26v6gRZ/WJRWB3zElt/pKkmJQs6kA3UsNRuJxcKJbeEpO +26QhH7uKevD/pI+FR64cPIcixbS0Q8nN5JMztze+qS2V1T3dkpySufI0b05e0UCmT87 Khhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=VhmO31ASaR5AbbhJWKJOBB028OwydePZqKoH4vU4z54=; b=fEl1vQxbM5RcCnUgbVSC8N1XQc+jTMPPnSQY0/w23eq07Z2T/8fOBubsSRU/evhKwE hDJNmSpDJ6MjWPGA/FQTIocsYD+opr7n6d68sATH5tWZLYqA7L3xisJmvTKN7G/RYwhm 7QUdyjO55h9h4UvNt7Un74vaNqOEvm+HaRg3Noh0OWAHib7XhYuXVSp9g1MWvU9lIx6X aFBFHDxo328KEX07DOmn6DRl5JWp5Lj9VLYQmDVLQsXrB/hfeu0bKtSvUdDJo21Ks8L6 9xYDbXy04dCFqIyunxXcsmpIph0QH6eSo7Ho+Sy6USjlrifqAhst4OzGWIDpYkA4ImmP HVbA== X-Gm-Message-State: APjAAAXdio2c280iOVHzdcmD6ngCQAaTVnns/45OC+yop7um/mxtPMhI 6PORUCjDdXt1KrhMTgoE8FJDyU4rDvKcqAtfvzRGAQ== X-Received: by 2002:a0c:af6c:: with SMTP id j41mr1093756qvc.29.1551395557856; Thu, 28 Feb 2019 15:12:37 -0800 (PST) Date: Thu, 28 Feb 2019 15:11:49 -0800 In-Reply-To: <20190228231203.212359-1-matthewgarrett@google.com> Message-Id: <20190228231203.212359-13-matthewgarrett@google.com> Mime-Version: 1.0 References: <20190228231203.212359-1-matthewgarrett@google.com> X-Mailer: git-send-email 2.21.0.352.gf09ad66450-goog Subject: [PATCH 13/27] x86/msr: Restrict MSR access when the kernel is locked down From: Matthew Garrett To: jmorris@namei.org Cc: linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, dhowells@redhat.com 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 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 4588414e2561..f5a2cf07972f 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; -- 2.21.0.352.gf09ad66450-goog