Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4683948ybi; Mon, 15 Jul 2019 13:00:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqw/OImzuPD1GRpCU4l4B8YKLZdFcoywZEdSoyu7uBcmK767j2xi+YUGlf+Tkk8S5zpTo7Ub X-Received: by 2002:a17:902:424:: with SMTP id 33mr30373046ple.151.1563220855522; Mon, 15 Jul 2019 13:00:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563220855; cv=none; d=google.com; s=arc-20160816; b=Kk5SUaIgdwJBzhH48A9Lle7Vr5dPUVn+linmsI88W6p/JEtLanCC3sPBIev2cpe7k7 lKTqLVWrvEyVDR569jsV3W0erq3m/+4afASo+XRpkzAzJxp9Xzcu6N9vEtQZKEmV2wzh yKSjTNZ+qryD3EsXffV8qCraXsDogJBbNOg4Ey7xa/1pwr+vhENoKeMjzv8qo+a0tWp7 AiTN+xUrf8mrFwW0GIdbTg4AWmqVVAj3XJfa+efDa1kQ6XnCHZXlDcHGJuB4YgQqsVQ2 jqrqLW24Q/gKDz20cpUBZtT5KdTPwkdeYZJNVPWUI1mHDYuhpEiZXp4anapXQjJzx0CY 3oNQ== 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=f/RnEfWSrg+mjsb2cXMX4L7C/xNmjjOSgJcVU/cQXL4=; b=OKS+Ckf0L5Xv589DhCt7RPbIK1DZij9IeXd/dKXM1ZsPshtD+qBMvZ5A7dJy83Q4ix n8/tK4dRnS6O77Ibu4N0lpCPvM6Dg/iMJcyNzIpN5ZAsdLDbF0tFCTQUjdk4QMTvcbeB 6pbSggVAdx5RdOajM4RyglXgXohEWl1flYCBIL/urQhAKSMIf3uzxUzqu/dr/dsx7eXO HkrLQcXfazq3xH0pLPcGP+cpFCY4V9PeXbqmcZyS/YXspzFht0ZhnADSTWqfG3dIk0LY KaR1rnYtu3qDq76ZWB3FVADo8N8/NKcA4EjqwXhVYSspm/SXgAt/nV8fXf1zWKxt0gIe iDpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=O3wJDTMn; 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 f17si16741774pgv.338.2019.07.15.13.00.39; Mon, 15 Jul 2019 13:00:55 -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=O3wJDTMn; 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 S1731761AbfGOUAB (ORCPT + 99 others); Mon, 15 Jul 2019 16:00:01 -0400 Received: from mail-pf1-f201.google.com ([209.85.210.201]:45092 "EHLO mail-pf1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732155AbfGOT77 (ORCPT ); Mon, 15 Jul 2019 15:59:59 -0400 Received: by mail-pf1-f201.google.com with SMTP id i27so10857100pfk.12 for ; Mon, 15 Jul 2019 12:59:58 -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=f/RnEfWSrg+mjsb2cXMX4L7C/xNmjjOSgJcVU/cQXL4=; b=O3wJDTMnR9+H3RojAsFfUzZ287o93Xl/j+eBzr9xiJ7GSnL6wH09hswz5HkUJo5TO0 zSIxrKaO7KxH1NGZU7OTkNwfKk0GwAeKc+MKisrrtdIClB8NctvgLH77qjBC5hKc/QNx 90e0sVBG4jPv7BUvyWIiRJhlq59sTL/+jDBqvmkICOjjJPFXRubWcJBrG3bYXhIeJMTx WcdMWTeTFuVC1gX8BKQw0/+98YB4jYff2uID6Vz0O0yOW0JHGKEGXJHEzUU/7bJ8ovCB z1mfyjYl0jF0/UyMq87sSAtqXC8sIdTLF2q38qdJlTGG5wkbomCUUrM9ehm3vT5Nppbc C49g== 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=f/RnEfWSrg+mjsb2cXMX4L7C/xNmjjOSgJcVU/cQXL4=; b=PaHtz2E57QwtvU8FbI6QWoCwS3ehgFFtE361d/JfUTuGUeH5zHuWiGTqVNnLi3IMWe 6zrj+y5Le461JKrc9tNIcoNcb62dasAi4KKSmJjtvUK8kECRcCA2WvshT11g/DvS6Z7l nzS8P0q/6Va9y7rxvd7giwBruRkUyAa2xiq7wkxYZCquxP8umtA15Y4rhu0mER2r8RSx O1UxNRe1x+bJoQJe5Obp2DSdpMMkZIdRsoF+fiX8xcEDARh8jB89YrRQ9v2NZpSG1NbA i5JxeRlho+lIw74AY9S0iqkFMQA1e6JGYKgpqKEsxR/bxPRPlPOxQUr4RtFoQABbGTC9 2sVg== X-Gm-Message-State: APjAAAX0cdXfmH61c14m7JYpwDOFZSUGEZvUqDDcDL0L8SX28atslAkm AZWDiqklGmrGvjPMPgb6TZdsSHgtkfDmiOJnfUiqxw== X-Received: by 2002:a63:1310:: with SMTP id i16mr28407114pgl.187.1563220798084; Mon, 15 Jul 2019 12:59:58 -0700 (PDT) Date: Mon, 15 Jul 2019 12:59:19 -0700 In-Reply-To: <20190715195946.223443-1-matthewgarrett@google.com> Message-Id: <20190715195946.223443-3-matthewgarrett@google.com> Mime-Version: 1.0 References: <20190715195946.223443-1-matthewgarrett@google.com> X-Mailer: git-send-email 2.22.0.510.g264f2c817a-goog Subject: [PATCH V35 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 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 --- 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.510.g264f2c817a-goog