Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp6088494ybh; Wed, 7 Aug 2019 17:08:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqyavIhbMdI99m6kGJHm8JQfqG3PV4HVeEBpb+qIRbcftvA0c/MlQnh/GDyL7ULJB8x9N9aA X-Received: by 2002:aa7:9591:: with SMTP id z17mr12277980pfj.215.1565222908680; Wed, 07 Aug 2019 17:08:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565222908; cv=none; d=google.com; s=arc-20160816; b=YPvFiPCSexpOfDTUQBDSSdXouyc98oG4aIt4Y4sXaNCABvq3Wp7x6GfTArEfONWkRN yKo7KeJIO5SXHTJtOUV4bO1kqPA9U2Ho5aV9SgeBQer53TLMPb6Z43/Om+AkBcG5f+NY VErmSR3YBXT7vUUW2Jq6yE8pWhdODKHPJMWdUw8qbgGwu0nyxfbKqJzDWMJrpsGGrtwt AGYFS8WY+TiTnFuOQE4pBsXFaKvA4xuWq6HbD5UAM2OMUb+pbD2KhsY2vPPin1WCbjbW cEFH3wd1KGrbTNCNjW2GQGeUsPzFQsr5k5AWsOkYnk1+OAos1BTZGxn11TORHn0Xme3C P38A== 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=WTiH4YTrH3kpcM05qpaK8fMoTjQf+8p0ghLlYf37sU8=; b=nCPOumObpXYUb2aqIQriu5+ScxeoWU4ASBlbnoVdvz6Bhzp3Q86k4er0o2hNpskI9p RMF3zncqa5hsgQ7KLnPSo5/uMz+M4gewFKGI9d0xDyeX0vsDFEETRT7aEvyB8iL1ffS9 +SEazrEzv3jheJ53tSeinS8Z5bsikUoUfFreBV2wvBG1rTAdYUKRI2SpeTO0FpjI7RhI arsaD8ALMfsSfaEZHdrhTDto0AQ79tYy/HNlpD5bqIzDoi/Rq9uOMEcfcPhWmNAriuX8 qsLFWaCJB7jPM5g75lcYGQERIRzEYG8IdfpUaQmzAPQKYi8EGTQaodQ9AKjLAiWrCFvp qg3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=k5u0bIMe; 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 y8si47269876plp.96.2019.08.07.17.08.13; Wed, 07 Aug 2019 17:08:28 -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=k5u0bIMe; 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 S1730604AbfHHAHd (ORCPT + 99 others); Wed, 7 Aug 2019 20:07:33 -0400 Received: from mail-pf1-f202.google.com ([209.85.210.202]:53676 "EHLO mail-pf1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730579AbfHHAHb (ORCPT ); Wed, 7 Aug 2019 20:07:31 -0400 Received: by mail-pf1-f202.google.com with SMTP id 191so57804182pfy.20 for ; Wed, 07 Aug 2019 17:07:30 -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=WTiH4YTrH3kpcM05qpaK8fMoTjQf+8p0ghLlYf37sU8=; b=k5u0bIMeReHa+u8U1oaho5+bd9aZVBkqeL9pAoxaP/N2Vfv5BYLzVOAuYRJmpKdX/w YCY2N8bXrxG2q5KaaEX4M8E2e94BNqAOrDA6ynwmLf7fynrtSjoX6JkHYvM/e07TQKed YRWoCaLmIVkLEbdXPEkIoTEXjZBVM0FFBcsKRQFlR6n7HkvIWTWa8PXKMPyv/w9EgqHf LACKT+bboiR4A3usw7+OWkBN7rH73WpzNsAbUS/33tgPYYV+KNSUUZ7KqsIpq/XUNRvv 2lkXE8txTKe5MwTrcCAoMsOG2+b/Cgl4yxF0ilAZKinN8gWE2Oyuht3tWnKGnogdhwEr J+7Q== 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=WTiH4YTrH3kpcM05qpaK8fMoTjQf+8p0ghLlYf37sU8=; b=rBwCW6zf6E20Jq+MLqbvLAFd0Cy1ZEfjafuNj9FCFRkh/xIuro3bP8QFR+QHCbpVnF m8hqDb/rhlRU1S/OQcJ0+kOAT075pMqW7yZaRv5dG2WsmTlS/mBFwsgCJ+9Filexhqs3 6DAND26bzlxDeFnTtq0YkRonQecD21nM7a4/mfb7kn/6H+R9QnJih4Kdxu9Yjve+QTvP PjW3bzaEE/KBOyMkYsuxvWPjxpNn3IBirSgnaO50Si0kgTEFEFpK3V+uzzPLilr7sxTc dxzuK5GXFPrREG0NWYODPAWrHagJB7LDoh6VEckONSKwH/DTUxNfoiX8/F5n11yYSzw4 jheQ== X-Gm-Message-State: APjAAAViqcXgtN6V5EhwBTrVC54ZGKNQMu/WrQ6XoqL/gnIwaGI2L3Yd MNb/cc3dyus4L52YH3YRO2ZSENDplNFMWiuA6QvaiQ== X-Received: by 2002:a63:7709:: with SMTP id s9mr9754003pgc.296.1565222849856; Wed, 07 Aug 2019 17:07:29 -0700 (PDT) Date: Wed, 7 Aug 2019 17:06:54 -0700 In-Reply-To: <20190808000721.124691-1-matthewgarrett@google.com> Message-Id: <20190808000721.124691-3-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 02/29] security: Add a "locked down" LSM hook From: Matthew Garrett To: jmorris@namei.org Cc: linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Matthew Garrett , Matthew Garrett , Kees Cook , Casey Schaufler 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 Add a mechanism to allow LSMs to make a policy decision around whether kernel functionality that would allow tampering with or examining the runtime state of the kernel should be permitted. Signed-off-by: Matthew Garrett Acked-by: Kees Cook Acked-by: Casey Schaufler --- include/linux/lsm_hooks.h | 2 ++ include/linux/security.h | 32 ++++++++++++++++++++++++++++++++ security/security.c | 6 ++++++ 3 files changed, 40 insertions(+) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index aebb0e032072..29c22cf40113 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1807,6 +1807,7 @@ union security_list_options { int (*bpf_prog_alloc_security)(struct bpf_prog_aux *aux); void (*bpf_prog_free_security)(struct bpf_prog_aux *aux); #endif /* CONFIG_BPF_SYSCALL */ + int (*locked_down)(enum lockdown_reason what); }; struct security_hook_heads { @@ -2046,6 +2047,7 @@ struct security_hook_heads { struct hlist_head bpf_prog_alloc_security; struct hlist_head bpf_prog_free_security; #endif /* CONFIG_BPF_SYSCALL */ + struct hlist_head locked_down; } __randomize_layout; /* diff --git a/include/linux/security.h b/include/linux/security.h index 66a2fcbe6ab0..c2b1204e8e26 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -77,6 +77,33 @@ enum lsm_event { LSM_POLICY_CHANGE, }; +/* + * These are reasons that can be passed to the security_locked_down() + * LSM hook. Lockdown reasons that protect kernel integrity (ie, the + * ability for userland to modify kernel code) are placed before + * LOCKDOWN_INTEGRITY_MAX. Lockdown reasons that protect kernel + * confidentiality (ie, the ability for userland to extract + * information from the running kernel that would otherwise be + * restricted) are placed before LOCKDOWN_CONFIDENTIALITY_MAX. + * + * LSM authors should note that the semantics of any given lockdown + * reason are not guaranteed to be stable - the same reason may block + * one set of features in one kernel release, and a slightly different + * set of features in a later kernel release. LSMs that seek to expose + * lockdown policy at any level of granularity other than "none", + * "integrity" or "confidentiality" are responsible for either + * ensuring that they expose a consistent level of functionality to + * userland, or ensuring that userland is aware that this is + * potentially a moving target. It is easy to misuse this information + * in a way that could break userspace. Please be careful not to do + * so. + */ +enum lockdown_reason { + LOCKDOWN_NONE, + LOCKDOWN_INTEGRITY_MAX, + LOCKDOWN_CONFIDENTIALITY_MAX, +}; + /* These functions are in security/commoncap.c */ extern int cap_capable(const struct cred *cred, struct user_namespace *ns, int cap, unsigned int opts); @@ -393,6 +420,7 @@ void security_inode_invalidate_secctx(struct inode *inode); int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen); int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen); int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen); +int security_locked_down(enum lockdown_reason what); #else /* CONFIG_SECURITY */ static inline int call_blocking_lsm_notifier(enum lsm_event event, void *data) @@ -1205,6 +1233,10 @@ static inline int security_inode_getsecctx(struct inode *inode, void **ctx, u32 { return -EOPNOTSUPP; } +static inline int security_locked_down(enum lockdown_reason what) +{ + return 0; +} #endif /* CONFIG_SECURITY */ #ifdef CONFIG_SECURITY_NETWORK diff --git a/security/security.c b/security/security.c index 90f1e291c800..ce6c945bf347 100644 --- a/security/security.c +++ b/security/security.c @@ -2392,3 +2392,9 @@ void security_bpf_prog_free(struct bpf_prog_aux *aux) call_void_hook(bpf_prog_free_security, aux); } #endif /* CONFIG_BPF_SYSCALL */ + +int security_locked_down(enum lockdown_reason what) +{ + return call_int_hook(locked_down, 0, what); +} +EXPORT_SYMBOL(security_locked_down); -- 2.22.0.770.g0f2c4a37fd-goog