Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp6090464ybh; Wed, 7 Aug 2019 17:10:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqydCSUaw8RwrpdytmmxAthaULcqnLrG439Rv2MS76Gm0tvaOUQF1UTYMV+uQ+9LovfnGm0O X-Received: by 2002:a62:27c2:: with SMTP id n185mr11670270pfn.79.1565223043052; Wed, 07 Aug 2019 17:10:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565223043; cv=none; d=google.com; s=arc-20160816; b=PEoz4dxOUCY0HKrgNeDpL1YAV3v80+17ijOr89Tl/BNFQw54lGVeCSFoOBgkj58513 7o2+dPEWBAh9iRoLsVfzfso1cRF5DWVbE9S6Q4cmGPSpJJ4aC5tMxtOrsI6NQWLmyonV QzZ3N70Tq9yAmXCDZuYWR0iP6WZUgV0be8zuLXBjhjXaNW0+dGDxJsefximnabkVTB+6 kPfgyeYuAjFD97x4mSfwMmcRwU2gDB7g7X+niOTIg/2oH85qIAhZAPH5Rr173eQqx3q/ 6GlVZzdkZKuVIyDEn4s/+JmGtFgcP5WrRjE3uSEFGw8maDWUd//KOscEwEY8MGWGw2lc FkcQ== 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=wWUVtXS/AXD8335Dh0MfmfyjjxhSNslzhtjFi/unWYg=; b=hm1FL/Rz14CCjB/sWwvXb5MBMpQdzw6j/e1Q5F1Xk9aOnNYpVB1NSgySdjPV/uJOPK HQk/MrSrppvGsqMtlIKhT8KewDOPCDA4WfhwgdKbPagUQeyzAxFiE02nkHiL5rnt6Djf +uVbg+P3Alfc988XqVq7SADWXu0v0YcISO0xZoIrYrMLbLqxhUuXn2oIidqL3oHYO4uJ C0Gwy4TEq3V4/97szFSJIQ1/NPn6fvKrYAfEyyLhVN75Wxc5T01GUSs013t3weqeyWoT wK5Wu7wg+r9S1KvBIpwu1hNVOLF29N510sW0rkm8bbMJZaz2XZA8QQQ4CLyWX/1DnajC rJ/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=DdNVqYf2; 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 i12si23944309pgq.65.2019.08.07.17.10.27; Wed, 07 Aug 2019 17:10:43 -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=DdNVqYf2; 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 S2389837AbfHHAJC (ORCPT + 99 others); Wed, 7 Aug 2019 20:09:02 -0400 Received: from mail-vk1-f201.google.com ([209.85.221.201]:55717 "EHLO mail-vk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389742AbfHHAI1 (ORCPT ); Wed, 7 Aug 2019 20:08:27 -0400 Received: by mail-vk1-f201.google.com with SMTP id b85so39732293vke.22 for ; Wed, 07 Aug 2019 17:08:27 -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=wWUVtXS/AXD8335Dh0MfmfyjjxhSNslzhtjFi/unWYg=; b=DdNVqYf2plZN2kFlxuLhjtuWgXV8nm1gqJlf97T8/uot+/jaf1l90CprMRuBIm7xA8 VYaRWGfMozlZ0zi/w8YA51Hh/y+9qBV6iXNBdePVkg/sDgT9NEVyXH0lPlgX3vY5F6RW Ug+ylmGoY9yf9ILn3vJ1NZaONO0mdn/TbdCjm3B8uoV3r/8Gm7rISK+G0lWADAZtre0Z pEr8J5UFhOLT4Y5TKH+mAoKVke8ovg8ipF4UbWDLGX/xGDQ+xsU5EnbAXQNtkXyj7Skr Ih1a7z3Zs1TBZJdE+SOw6CU/yhIkcrbYCP4xstObpW3RBdf5krwSl2Zy7EQGS/VQqiQ1 h0rA== 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=wWUVtXS/AXD8335Dh0MfmfyjjxhSNslzhtjFi/unWYg=; b=UFvblOqYOUVDH3XgRwoPGSzdI/QkWRMItmJ0+ErioFZlUJgtDgxZRPSCjHnegaAUja 8fH4VrEqxN2Mthcns0UR6SUsgNUwekjOHk1A/Vaf5g2xvvcDynM1ugEfBMFcFSXaHFoY IvaPQHwkIE3gozA1cwBpbKBIVkjFeuHF85Ql+wBsuWoW6zPiR7l6LK1EeSo6Mjim+U++ tk7mN0Ki0n4MC/XR1sOYK3+aHr5XJ5I18tNEBQtsWFf8H5L45mwL940j1UYoDFywfCpc SRtMieD6et74HllQkZavBMFqTSy0telDyy1HIJOFqOzZvAkGIXXJgzDRNUvK0fvtz8UU IjxA== X-Gm-Message-State: APjAAAXvv71p4Jla+GcxKfmpyNN10os0OyNYmif5DI9uUpAHx/P9kkK8 GkRAYmac4u5rybdY51FeRrKBf8gRFK2qcCkjdeBnRA== X-Received: by 2002:a1f:b0b:: with SMTP id 11mr4694030vkl.64.1565222906414; Wed, 07 Aug 2019 17:08:26 -0700 (PDT) Date: Wed, 7 Aug 2019 17:07:16 -0700 In-Reply-To: <20190808000721.124691-1-matthewgarrett@google.com> Message-Id: <20190808000721.124691-25-matthewgarrett@google.com> Mime-Version: 1.0 References: <20190808000721.124691-1-matthewgarrett@google.com> X-Mailer: git-send-email 2.22.0.770.g0f2c4a37fd-goog Subject: [PATCH V38 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 , Kees Cook , 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 Reviewed-by: Kees Cook 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 8dd1741a52cd..8ef366de70b0 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -119,6 +119,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 c1f52a749db2..5c520b60163a 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -10826,6 +10826,13 @@ SYSCALL_DEFINE5(perf_event_open, perf_paranoid_kernel() && !capable(CAP_SYS_ADMIN)) return -EACCES; + 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; + + err = 0; + /* * In cgroup mode, the pid argument is used to pass the fd * opened to the cgroup directory in cgroupfs. The cpu argument diff --git a/security/lockdown/lockdown.c b/security/lockdown/lockdown.c index 1b89d3e8e54d..fb437a7ef5f2 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.770.g0f2c4a37fd-goog