Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp6097430ybh; Wed, 7 Aug 2019 17:19:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqwXqIhtV3sIPBY8Tyqxg+lafn3RsQVBeOZMCTSiDGFJ1IZeZfykCC7KevKhH7k9vdrX1RFH X-Received: by 2002:a63:204b:: with SMTP id r11mr10058681pgm.121.1565223570682; Wed, 07 Aug 2019 17:19:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565223570; cv=none; d=google.com; s=arc-20160816; b=BwkGjHwjyEV0DYR8daWyWXM4AgPHmZIuvdWkzs8KN9bsBum7p0AzIOZ5I5hYv2a5UA fFRsuEEIjKBK+iwLyP+j0T3E75jD01J6Z8J75xlQJhlcodsnw1X/akgRF5Lqwr4VOJoj Hs+MufStUqsPM5dRdE74g5M4UTavjjumqSF0XXv0vCG5Xan17Jgk+6qRyqGlMet4OQWK gRgU5vBNAB7UzqjdNaKx2pMow4AetMvrrR8BnX5x01pVEAWcst22WqCvmSfEVJuVwTAx fb3KzD1x2LQK9U3Rzc7bxDc+9uXlcO/giv6UAIKdmXLuNxxaVVPJgNDVtM44h9uSm4XN Q0FA== 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=8yt0J0pt8aHuQPT7nXOB+XR/9vHKjGA14LTvJs583ko=; b=ZtaA9hRMrQTVtTXuXvt7Y8tVu4AdhNuu2VulGdGt6W8lVHGoeLkGUHQ4lGX8CK+j6v eIpSrYYnx+WU+WQtDBIEGWnxOJ/rxo5UX7LLJig18dXFb5mnBiXDx5W+Thx25f//2XnO Bp8V+5c+E+mGkgZM62HGKaSC5YB4PVqxseQUxbNewUXeRRY2jsTkmb4LIEdZMvbutFDX lK9PB51PaKC/MqkTuiGtptmrOfxWv4VT3xJIRC6/CU82xc0hNnrfDx710GNxFSK2Ymi/ XHy4pVG5AoBPDDgvTK27O3qJ2CeTiw3sRSOmuVGbbhBaOSeQF5dOPyBQQa+s58P0BlKk +R3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="R/kcNwmg"; 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 f2si52653333pgl.74.2019.08.07.17.19.12; Wed, 07 Aug 2019 17:19:30 -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="R/kcNwmg"; 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 S2389757AbfHHAIa (ORCPT + 99 others); Wed, 7 Aug 2019 20:08:30 -0400 Received: from mail-qt1-f202.google.com ([209.85.160.202]:34792 "EHLO mail-qt1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389733AbfHHAIY (ORCPT ); Wed, 7 Aug 2019 20:08:24 -0400 Received: by mail-qt1-f202.google.com with SMTP id p34so83928609qtp.1 for ; Wed, 07 Aug 2019 17:08:24 -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=8yt0J0pt8aHuQPT7nXOB+XR/9vHKjGA14LTvJs583ko=; b=R/kcNwmgbX+sKxSEQsYUzy5uU1k4FuUGmKARS2fBkMDe+ZiZsiyQt4yd4lR2R6nsjb wpjUNdDlXARvS5FUlu+PthqfTsorWtf88u58FgL5DuOglBXkEUFf7g8Wu357CPD1PEj5 58PkL4hmWYOY6O8/DHp19TdCXlQTC0/7jAjVyZ3EbA8nlErkBnnDpNrUXmd6bZLaLCSp 7+JRhvoUP7mO5NTA3UhzFDk0WXgQYiBqgdLwiUahFgrbJ15hUKqPL5FbLDdHBnCsuzTv 1cFf2P13Z4ho/mB37/OdEUSP3mKSUvgH6BHIR9A0yKppvEfzMfT+TzvFoDGYMESasC8r 2Mvw== 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=8yt0J0pt8aHuQPT7nXOB+XR/9vHKjGA14LTvJs583ko=; b=uAhkIPhRUbWoqksqyQl3uUDlayCcpBWGQeVX89euVg1tFL1Y0rLUheTrxopqSduK6i AXRzr6NfKIOh1Tt+LkfcNWih1HhCPfn2NaRGPNg+Kq4v+9IkqXINkp14Ud8z4oTM792c czS2Px1RGn1S04LCA+6HdWvPRo2sR4YbbfHnQskTfyCi10GyRi8XZYV0+Yfj1GZn9I49 6aF+xHqHDRhRVRkC7vaaozp5nTsb6mhfES+Kph2eUpRtkzrq01o5f1pMyZhnLm5PQqCz LgL7u0bJPwraFlaFf7DogztX+WffZuDIdW1KS0ajQ+muUF/nnuCHJ9UmDRwU1REB6gmX PNgA== X-Gm-Message-State: APjAAAW0Mxrn6O9NT8pLWjjfEBSEMCHwwV6O8ZpbFRSfzNBDTziC8dpY kuXmFscqhZn20Yg7uUl8Lh6XvEn3nQkofi+7xiQC/g== X-Received: by 2002:a37:90c2:: with SMTP id s185mr11369315qkd.161.1565222903745; Wed, 07 Aug 2019 17:08:23 -0700 (PDT) Date: Wed, 7 Aug 2019 17:07:15 -0700 In-Reply-To: <20190808000721.124691-1-matthewgarrett@google.com> Message-Id: <20190808000721.124691-24-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 23/29] bpf: Restrict bpf when kernel lockdown is 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 , Alexei Starovoitov , Matthew Garrett , Kees Cook , netdev@vger.kernel.org, Chun-Yi Lee , Daniel Borkmann 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 bpf_read() and bpf_read_str() could potentially be abused to (eg) allow private keys in kernel memory to be leaked. Disable them if the kernel has been locked down in confidentiality mode. Suggested-by: Alexei Starovoitov Signed-off-by: Matthew Garrett Reviewed-by: Kees Cook cc: netdev@vger.kernel.org cc: Chun-Yi Lee cc: Alexei Starovoitov Cc: Daniel Borkmann --- include/linux/security.h | 1 + kernel/trace/bpf_trace.c | 10 ++++++++++ security/lockdown/lockdown.c | 1 + 3 files changed, 12 insertions(+) diff --git a/include/linux/security.h b/include/linux/security.h index 987d8427f091..8dd1741a52cd 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -118,6 +118,7 @@ enum lockdown_reason { LOCKDOWN_INTEGRITY_MAX, LOCKDOWN_KCORE, LOCKDOWN_KPROBES, + LOCKDOWN_BPF_READ, LOCKDOWN_CONFIDENTIALITY_MAX, }; diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index ca1255d14576..492a8bfaae98 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -142,8 +142,13 @@ BPF_CALL_3(bpf_probe_read, void *, dst, u32, size, const void *, unsafe_ptr) { int ret; + ret = security_locked_down(LOCKDOWN_BPF_READ); + if (ret < 0) + goto out; + ret = probe_kernel_read(dst, unsafe_ptr, size); if (unlikely(ret < 0)) +out: memset(dst, 0, size); return ret; @@ -569,6 +574,10 @@ BPF_CALL_3(bpf_probe_read_str, void *, dst, u32, size, { int ret; + ret = security_locked_down(LOCKDOWN_BPF_READ); + if (ret < 0) + goto out; + /* * The strncpy_from_unsafe() call will likely not fill the entire * buffer, but that's okay in this circumstance as we're probing @@ -580,6 +589,7 @@ BPF_CALL_3(bpf_probe_read_str, void *, dst, u32, size, */ ret = strncpy_from_unsafe(dst, unsafe_ptr, size); if (unlikely(ret < 0)) +out: memset(dst, 0, size); return ret; diff --git a/security/lockdown/lockdown.c b/security/lockdown/lockdown.c index 6b123cbf3748..1b89d3e8e54d 100644 --- a/security/lockdown/lockdown.c +++ b/security/lockdown/lockdown.c @@ -33,6 +33,7 @@ static char *lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1] = { [LOCKDOWN_INTEGRITY_MAX] = "integrity", [LOCKDOWN_KCORE] = "/proc/kcore access", [LOCKDOWN_KPROBES] = "use of kprobes", + [LOCKDOWN_BPF_READ] = "use of bpf to read kernel RAM", [LOCKDOWN_CONFIDENTIALITY_MAX] = "confidentiality", }; -- 2.22.0.770.g0f2c4a37fd-goog