Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1236656ybi; Fri, 21 Jun 2019 17:04:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpBbjFsxadLLJ3PSnG0/eh8I0CfSJp9J+cCCuMgMXMtQZrVwcLPkxHeFjxqDCwlRtfhnbJ X-Received: by 2002:a17:902:b944:: with SMTP id h4mr9912583pls.179.1561161873952; Fri, 21 Jun 2019 17:04:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561161873; cv=none; d=google.com; s=arc-20160816; b=Gx4KEZMl9HtpIrvMKdlW9lfju00QicAFj7yJh7+mP2+FD+3OMDdVPDqhTdN5IjKJrd YNkye2g5WKq3sBYKzOtSr4qDQR7NYshT7y1CnamdPzWViINNSGgI6qGsFDoGrsaoJkbg Qds4vIfPDOgk7GkveBCoQaS1aDSx1pxRq6LerJzL4OdltXJhtBerTLblNdTtmtFNRUOB orSl5+2BwlHWJV2PNl+TxxiqB5kZuHDlC8m8q74XZf8KdGMqYEOnhlg6klPJYD+wKmmz JhbnUZnYza2OZYRk59rna4Q0aGHs7gli9zzxkOIcs1kX/ghlpSwtfgkHGjaAmAoMgXmb M76w== 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=9daZa8/hqWzZuaGJLkwK103skAzbS3nFdoLOu7tsdHI=; b=KFikJfM/6sZetWcb8nTejPWK3uFw/IRk2cY5xGmS82Q+u9e0zZ3G2WSopiccG7Ock6 add4Ms2eFtgsFgDFx0zLdiP2dhCGcHd65fhudf6hGnO6WhJutwpjW88fOspEKSvsOQSU w6ti96IRe31sLSbr8zCurGSF5HUURTANmNE+N7ewQXndF9JM1tSsrNzqCfnrFQ8DXfZ+ RjJo91siyMl+eZnkbYB0hrRiUxZmrprZhZCDVFmqwxZs07A59RVSLiy8l8bRX5ZjXIZc b+B5uM2xQmVNGi8lAwAUyeU7kKzNB9ydXzI6PlAspO4NOcvsP7aM0c5MG6sNqU99Z0g3 8stg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Q/D1El3S"; 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 e25si4252986pff.30.2019.06.21.17.04.19; Fri, 21 Jun 2019 17:04:33 -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="Q/D1El3S"; 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 S1726360AbfFVAEI (ORCPT + 99 others); Fri, 21 Jun 2019 20:04:08 -0400 Received: from mail-qt1-f202.google.com ([209.85.160.202]:32789 "EHLO mail-qt1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726264AbfFVAEH (ORCPT ); Fri, 21 Jun 2019 20:04:07 -0400 Received: by mail-qt1-f202.google.com with SMTP id r40so9843008qtk.0 for ; Fri, 21 Jun 2019 17:04:07 -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=9daZa8/hqWzZuaGJLkwK103skAzbS3nFdoLOu7tsdHI=; b=Q/D1El3SijlLetTLADKIIte9tNRO98kykcjbvezzo8iX6ULzwvyyXXdR2qZPh+3i26 1WbNkZ6l3vwcaw8ME7qaLeDwp41bwD8t/A4G9dsbhAxAbvpREcXGQ5PqicC98CXO/SXo 8a73xkKgdAoHHhuRTn6JlCmlG9PTKLfbzl/vOxwt9G7grClG0hHLcwxVwxKwvl3J+SEk 3mevF2DkRMytAztapn/3JDjXUkKUTvfId2XjFQ5pLAYBV0Xq7UVfKkb29LQ9TBVy2oCs hz0L+DiU6+PWc2LmT61ysG+fhiMaCTqt+tS+LRej/8oi9MH2EY+0zf/c+80BfhWsCciQ JlTA== 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=9daZa8/hqWzZuaGJLkwK103skAzbS3nFdoLOu7tsdHI=; b=mPAJTr9wV1Uq5iO4bRPAeVVONLfDS7g1WJIGgGCKUvmMl3kDXSLb8pTH2g5SoLsoC6 TaYAPKosHB0Mjr7bXfkRSrWP0XJbostr/QOL6vbhjGEohee7BPigWCxvvcwTf2NJ/pbZ QpSzNCXRRmZXqysvF+6NSj0tILB6H6pkNYEvbA4mxmOpeLfsAIUX3+NtIaY5rTeOx0Bn QRMJdstrgkcs4qn+vyGHSlI3toGZW4/6Vy9qil+vuaYHUqi3O97f0y4myEVF+ZrKSF0K iasNJy1/w59x5XGkfohTCOqb73pxK/Med95Jg2sO9kg2sRJBifGy7GvTI6hfEzuOuWsm 3RDQ== X-Gm-Message-State: APjAAAWMfnrWwkXhofRC86SYU2zsAEKVvIdx82ZU0VzkmAYR/HgWOjMr I8JLy0fwClB6u+Vqq5M9PNmPVzIORNXaapLmb7dIqg== X-Received: by 2002:a05:6214:222:: with SMTP id j2mr45977128qvt.121.1561161846752; Fri, 21 Jun 2019 17:04:06 -0700 (PDT) Date: Fri, 21 Jun 2019 17:03:31 -0700 In-Reply-To: <20190622000358.19895-1-matthewgarrett@google.com> Message-Id: <20190622000358.19895-3-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 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 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 --- include/linux/lsm_hooks.h | 2 ++ include/linux/security.h | 11 +++++++++++ security/security.c | 6 ++++++ 3 files changed, 19 insertions(+) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 66fd1eac7a32..df2aebc99838 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1790,6 +1790,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 { @@ -2027,6 +2028,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 1bb6fb2f1523..9eaf02e70707 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -76,6 +76,12 @@ enum lsm_event { LSM_POLICY_CHANGE, }; +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); @@ -389,6 +395,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_lsm_notifier(enum lsm_event event, void *data) @@ -1189,6 +1196,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 487e1f3eb2df..553f50e9a106 100644 --- a/security/security.c +++ b/security/security.c @@ -2382,3 +2382,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.410.gd8fdbe21b5-goog