Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp3450285ybd; Fri, 28 Jun 2019 08:50:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqwCYQyzF9Pj44v85vh6gDOkeHqRz0h+AA/RYeeVXYgOxa6xkp5FnrSqUMo9xrCA1G2ZYf3G X-Received: by 2002:a17:902:5c2:: with SMTP id f60mr12384978plf.61.1561737043175; Fri, 28 Jun 2019 08:50:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561737043; cv=none; d=google.com; s=arc-20160816; b=HKWj9fZ07ZPWTGcBhZeqpuBtwmXm00Y7P5B5Su0zrkO9ST7LHF0w5TO9dsGhZ8ejd9 CWAyTx965JrtCB91kRhcnDk5XkrVr+grUovrT9btRrPclwFz0KRGh6zoTI2I4xD1Jfqa ZwX0GpZP6mcX7dctZd6kkERKd5AxxUiia1A2hfvwy6T2FM3MQHdQHHTeZeOCOVJUvq3L tHpbUbcg/GFl+wEHJx5U0AKE06GtKEKGf0BAr3dsDnbRTyuMSa6g9sEAVVaGtjTdy2KR t5ypzdEl5u9TVfOUAX3MZIfmFBzr/68UdBrfQm9+wIm9qFoq6UIQyOwuhbz1LOSWdSND 0s7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization; bh=2YnqHh1AejfjvYwy874DMHvAkRKEt3ftcOIQUnPEdbY=; b=oIh4p6vGICTU4Mr4HfMNltSiF7K9Lm3F5GSCVjJ9hqejQqE1OC4z+ejXKMe7mrcOiv XNrsZEr5Zv42tM7Q5WM+YMucNkfZfVDHfSybsltSpqfQ2DwNki35gkxHhFcFYPXtQEV4 C11D8xZ6z6va49tS55+4NyJoGi5NNan6uz8C4eH0BO4sRYT4YTTMCv0CXUbfLomC0QhW y+eRI93U/WxowblyIDfA0NXva8D8VcmYixNd2IDGYzRmrQjPXWsey4NSnvhpvBy5vaP4 DYOz2XxF9FyrHYCE3Rmxy6DNx654A1FTi02Oxus5CAoemzPEUCNOWAvLdQMn1xui1g5c g9TA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w198si3048864pfd.106.2019.06.28.08.50.27; Fri, 28 Jun 2019 08:50: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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727400AbfF1Ps6 (ORCPT + 99 others); Fri, 28 Jun 2019 11:48:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48032 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726905AbfF1Ps5 (ORCPT ); Fri, 28 Jun 2019 11:48:57 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AA298308FBB4; Fri, 28 Jun 2019 15:48:56 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-219.rdu2.redhat.com [10.10.120.219]) by smtp.corp.redhat.com (Postfix) with ESMTP id 379BF26DF3; Fri, 28 Jun 2019 15:48:48 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 2/9] security: Add hooks to rule on setting a watch [ver #5] From: David Howells To: viro@zeniv.linux.org.uk Cc: dhowells@redhat.com, Casey Schaufler , Stephen Smalley , Greg Kroah-Hartman , nicolas.dichtel@6wind.com, raven@themaw.net, Christian Brauner , dhowells@redhat.com, keyrings@vger.kernel.org, linux-usb@vger.kernel.org, linux-security-module@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-block@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 28 Jun 2019 16:48:47 +0100 Message-ID: <156173692760.15137.9636883182556029747.stgit@warthog.procyon.org.uk> In-Reply-To: <156173690158.15137.3985163001079120218.stgit@warthog.procyon.org.uk> References: <156173690158.15137.3985163001079120218.stgit@warthog.procyon.org.uk> User-Agent: StGit/unknown-version MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 28 Jun 2019 15:48:56 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add security hooks that will allow an LSM to rule on whether or not a watch may be set. More than one hook is required as the watches watch different types of object. Signed-off-by: David Howells cc: Casey Schaufler cc: Stephen Smalley cc: linux-security-module@vger.kernel.org --- include/linux/lsm_hooks.h | 22 ++++++++++++++++++++++ include/linux/security.h | 15 +++++++++++++++ security/security.c | 13 +++++++++++++ 3 files changed, 50 insertions(+) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 47f58cfb6a19..f9d31f6445e4 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1413,6 +1413,20 @@ * @ctx is a pointer in which to place the allocated security context. * @ctxlen points to the place to put the length of @ctx. * + * Security hooks for the general notification queue: + * + * @watch_key: + * Check to see if a process is allowed to watch for event notifications + * from a key or keyring. + * @watch: The watch object + * @key: The key to watch. + * + * @watch_devices: + * Check to see if a process is allowed to watch for event notifications + * from devices (as a global set). + * @watch: The watch object + * + * * Security hooks for using the eBPF maps and programs functionalities through * eBPF syscalls. * @@ -1688,6 +1702,10 @@ union security_list_options { int (*inode_notifysecctx)(struct inode *inode, void *ctx, u32 ctxlen); int (*inode_setsecctx)(struct dentry *dentry, void *ctx, u32 ctxlen); int (*inode_getsecctx)(struct inode *inode, void **ctx, u32 *ctxlen); +#ifdef CONFIG_WATCH_QUEUE + int (*watch_key)(struct watch *watch, struct key *key); + int (*watch_devices)(struct watch *watch); +#endif /* CONFIG_WATCH_QUEUE */ #ifdef CONFIG_SECURITY_NETWORK int (*unix_stream_connect)(struct sock *sock, struct sock *other, @@ -1964,6 +1982,10 @@ struct security_hook_heads { struct hlist_head inode_notifysecctx; struct hlist_head inode_setsecctx; struct hlist_head inode_getsecctx; +#ifdef CONFIG_WATCH_QUEUE + struct hlist_head watch_key; + struct hlist_head watch_devices; +#endif /* CONFIG_WATCH_QUEUE */ #ifdef CONFIG_SECURITY_NETWORK struct hlist_head unix_stream_connect; struct hlist_head unix_may_send; diff --git a/include/linux/security.h b/include/linux/security.h index 659071c2e57c..540863678355 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -57,6 +57,7 @@ struct mm_struct; struct fs_context; struct fs_parameter; enum fs_value_type; +struct watch; /* Default (no) options for the capable function */ #define CAP_OPT_NONE 0x0 @@ -392,6 +393,10 @@ 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); +#ifdef CONFIG_WATCH_QUEUE +int security_watch_key(struct watch *watch, struct key *key); +int security_watch_devices(struct watch *watch); +#endif /* CONFIG_WATCH_QUEUE */ #else /* CONFIG_SECURITY */ static inline int call_lsm_notifier(enum lsm_event event, void *data) @@ -1204,6 +1209,16 @@ static inline int security_inode_getsecctx(struct inode *inode, void **ctx, u32 { return -EOPNOTSUPP; } +#ifdef CONFIG_WATCH_QUEUE +static inline int security_watch_key(struct watch *watch, struct key *key) +{ + return 0; +} +static inline int security_watch_devices(struct watch *watch) +{ + return 0; +} +#endif /* CONFIG_WATCH_QUEUE */ #endif /* CONFIG_SECURITY */ #ifdef CONFIG_SECURITY_NETWORK diff --git a/security/security.c b/security/security.c index 613a5c00e602..2c9919226ad1 100644 --- a/security/security.c +++ b/security/security.c @@ -1917,6 +1917,19 @@ int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen) } EXPORT_SYMBOL(security_inode_getsecctx); +#ifdef CONFIG_WATCH_QUEUE +int security_watch_key(struct watch *watch, struct key *key) +{ + return call_int_hook(watch_key, 0, watch, key); +} + +int security_watch_devices(struct watch *watch) +{ + return call_int_hook(watch_devices, 0, watch); +} + +#endif /* CONFIG_WATCH_QUEUE */ + #ifdef CONFIG_SECURITY_NETWORK int security_unix_stream_connect(struct sock *sock, struct sock *other, struct sock *newsk)