Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1237810ybi; Fri, 21 Jun 2019 17:05:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqzpVfF3JepEU/iE1Py1cMnfl7heEKgeLOW3GOs0YXOtkKXgbxb+o6ewWOsxHGZub+KdjMcW X-Received: by 2002:a17:90a:3210:: with SMTP id k16mr9562558pjb.13.1561161954427; Fri, 21 Jun 2019 17:05:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561161954; cv=none; d=google.com; s=arc-20160816; b=ine3B2hROxh4QDf7OCW3gFPiEi5O8iqaJY3JVRRTgaVi2+A7t6DyK1644hevmek0TL sNyl2SuapJdWFS7ccHRBbUfq+3DQEsCOR54IkV5qaIqRYTaIlPsD4rwdMy/n1IWE/spY OZvcPgFRr+slL9G5n6N9CTj98P+1vNzRFZn+WXJnD1B8pwmYS1Qr1kWuZnHbvhi3SsBR efhH/kWHm+eWibatCwn7aoYhKHUjEfJe57UlpRYDe33S+jeWWhH3taI8SgFuwduwDUhs dKUpAYtdDdQeK/EgV5MxIFZUyY+tY5tgHEpXCixju0Oa3pOScrkiJDIHjul2Ng29LuiA eFKA== 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=MSE1dfKm6a4U6gWG+XXV/6IbZHfhkaYY6qykZ2fiyyA=; b=O7z5hM7XOAtkSFmNwl/V4cEk9z7mxtbJPe6hxTUi59CS2zDgrYaFwHasCIfi8rY1u5 dL9yokeszenqdgZoCI+AhSX5lLYV/ayU2rileiM5qW7i5pCzEQwwT3rRMzkjTBrM26NW xyQmcDWVDDi22fPjXw0M3jAKfgk/i+hgxFzPiNOltHe+DaOY9EKj+QMOMA6AJIu37neG 22NSmPbAX++Vss4gKmGpSVlyK1nKtAFMc6WJ13gWI10NW9Wppe0AUQ2yJ/H9WE7cwnDC IJ8dHtkz7xtrQVwYxk/WA0J4uQWBZfpsvS+A2IiuNPmcLBMfTq2eGQOD56qnlE9wv1ah D5Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=fXPdtbJm; 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 c12si3732107pgg.421.2019.06.21.17.05.38; Fri, 21 Jun 2019 17:05:54 -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=pass header.i=@google.com header.s=20161025 header.b=fXPdtbJm; 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 S1726951AbfFVAFF (ORCPT + 99 others); Fri, 21 Jun 2019 20:05:05 -0400 Received: from mail-pf1-f202.google.com ([209.85.210.202]:36775 "EHLO mail-pf1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726937AbfFVAFD (ORCPT ); Fri, 21 Jun 2019 20:05:03 -0400 Received: by mail-pf1-f202.google.com with SMTP id h15so5335771pfn.3 for ; Fri, 21 Jun 2019 17:05:02 -0700 (PDT) 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=MSE1dfKm6a4U6gWG+XXV/6IbZHfhkaYY6qykZ2fiyyA=; b=fXPdtbJmSfE8Q4WIQs2dmiKmnq4w8wPH44i8xF217pTQ0RnXb0fgs5rTReQYKwAFOt a45BB1kJLiVV3CiZFCq8P6HNcq5NJ8IAQDtyoswUv6yquzD3SntcGwcr/sDfQSxNRQin WqwIhqEP91O8JDsS/3Oczyt3jflEpGI5xj7uHsHdcdy1ULhHWcpsec3ntSNQmASPniis RrTw8AJIj0B/CSkFuSclsom2q4SOUahEDlV4cJL8BPdNDlx6MoY9MejEAssBYRifgYGa qgpysJEVpWPkUa6SA+iZLF4rWnfXt5zObKpaxukLwnpfsCdeUO5ywRflWBnWirymhIcP lHjg== 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=MSE1dfKm6a4U6gWG+XXV/6IbZHfhkaYY6qykZ2fiyyA=; b=PCeowdF5maYpeOO6KhhHQIMGOMpIxmK9SG9ZDF8mMBEm271NI13h2S4t4NwU5T0FJl xPJDqW+gUloHADD5Ks8CVk4SpPHZULJ1AAAp9v08e5a5WWJicqFiNRm7yZaPWwuztp/x 5aq/4/Kvh88vLNxUUVEW01EshSp/3eSRfc5OTR7MqYZpP76Iya7NRIaI6nyCJRAkC4g9 5oKJMaFPfAmhbB6ORRKupOxCby82Uc17JTsoY/5+JS3rjd/4HrQesnasZST4l/j+GtLM 43iutnOZDkDsJ5r8/QjjNASXYa/ivD5trvNI+KbP9wf/FQZ3zE538UZPM/VCMNck9WjE DQTA== X-Gm-Message-State: APjAAAXk9J/lbH108jOOf7QzMs5DD8GZIl1XjH9IFYvbrnxLxLyKylxE 3kZYlSG44EiVOcL5nN2hI0vW6usgAJiEaBDe8WbeDQ== X-Received: by 2002:a63:e953:: with SMTP id q19mr21349257pgj.313.1561161902178; Fri, 21 Jun 2019 17:05:02 -0700 (PDT) Date: Fri, 21 Jun 2019 17:03:53 -0700 In-Reply-To: <20190622000358.19895-1-matthewgarrett@google.com> Message-Id: <20190622000358.19895-25-matthewgarrett@google.com> Mime-Version: 1.0 References: <20190622000358.19895-1-matthewgarrett@google.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog Subject: [PATCH V34 24/29] Lock down perf when in confidentiality mode From: Matthew Garrett To: jmorris@namei.org Cc: linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, David Howells , Matthew Garrett , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo 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: David Howells Disallow the use of certain perf facilities that might allow userspace to access kernel data. Signed-off-by: David Howells Signed-off-by: Matthew Garrett Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo --- include/linux/security.h | 1 + kernel/events/core.c | 7 +++++++ security/lockdown/lockdown.c | 1 + 3 files changed, 9 insertions(+) diff --git a/include/linux/security.h b/include/linux/security.h index de0d37b1fe79..53ea85889a48 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -98,6 +98,7 @@ enum lockdown_reason { LOCKDOWN_KCORE, LOCKDOWN_KPROBES, LOCKDOWN_BPF_READ, + LOCKDOWN_PERF, LOCKDOWN_CONFIDENTIALITY_MAX, }; diff --git a/kernel/events/core.c b/kernel/events/core.c index 72d06e302e99..77f36551756e 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -10731,6 +10731,13 @@ SYSCALL_DEFINE5(perf_event_open, return -EINVAL; } + err = security_locked_down(LOCKDOWN_PERF); + if (err && (attr.sample_type & PERF_SAMPLE_REGS_INTR)) + /* REGS_INTR can leak data, lockdown must prevent this */ + return err; + else + err = 0; + /* Only privileged users can get physical addresses */ if ((attr.sample_type & PERF_SAMPLE_PHYS_ADDR) && perf_paranoid_kernel() && !capable(CAP_SYS_ADMIN)) diff --git a/security/lockdown/lockdown.c b/security/lockdown/lockdown.c index 2eea2cc13117..a7e75c614416 100644 --- a/security/lockdown/lockdown.c +++ b/security/lockdown/lockdown.c @@ -34,6 +34,7 @@ static char *lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1] = { [LOCKDOWN_KCORE] = "/proc/kcore access", [LOCKDOWN_KPROBES] = "use of kprobes", [LOCKDOWN_BPF_READ] = "use of bpf to read kernel RAM", + [LOCKDOWN_PERF] = "unsafe use of perf", [LOCKDOWN_CONFIDENTIALITY_MAX] = "confidentiality", }; -- 2.22.0.410.gd8fdbe21b5-goog