Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp691675pxb; Wed, 11 Nov 2020 13:53:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJzBvhXIHvPtN3RL6HEF/3KKXu9ilve0/YFTShjHkv/UO6UGB0cUD+JZHlFBeTJt7itR6Um1 X-Received: by 2002:a17:906:cc4f:: with SMTP id mm15mr27238716ejb.267.1605131593625; Wed, 11 Nov 2020 13:53:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605131593; cv=none; d=google.com; s=arc-20160816; b=md5sy0RVCxqlk3rpPDpF2UdNtlxxdc5H3O2GDQN3+iGo0u+zK7IrYWaX6nabheEI4T rtz1FxXAwBJk3dHwb5isgkUYAa+fSR6c87PPV4KsH6/JpjLoxpguD+0V7T0sKiyMig2t VFOvBHgEfCssOVjJ45DMD4XEbqhp6+ZSXMFFEB8a93DP1UhiaEvEsFt3ZXNOlDf09t/N Qh76LR+PlHB02sqYuXSq/qVVZxDhsrTvD0aowLdLFxeUpKcrOg6Gm+I555rswgy6hAwd JXvJNlGUWAlsP6+Vm3c3yhbVS5HUxwIOWTxgPjm75EKwfBJkHWzIedIuhQzcPnJGQbo1 JZLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=jlyXpOvGwG5VTWMVMo+wDWoHijXA5Ta+te15rGPHBao=; b=TQL1lxD93saW9KjGEw09/ALAS4VIoLw2OM2UOIG1AU1wMFHpMpT/O11DmZHDbbLpeq sOcayv9hHmlwId6wXNdb6za6t1KBYqfHYyLKuq/0fLPtrPffCi4ly7O7X7ULYJHmIvxF vYNjXuE1zetYKiGno0gPnhz72pswYq+EaUenfyHhgCCioKSsHGfnoetnWHxj3JY5TJyb UkI2m4fUIHJNX3CAStMbMX0m3wSN1Q6AqwECcSu2DmYNBGgd4f4F4zy+VJVAvZEyz1hI uLecGagmBDjteliqX4U5yRKwXBufK4XjbUvM3qZlw624H2uDKTXJVNxyQG95UZfOJH0q gUEw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q18si2256098ejx.84.2020.11.11.13.52.50; Wed, 11 Nov 2020 13:53:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726671AbgKKVwf (ORCPT + 99 others); Wed, 11 Nov 2020 16:52:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726618AbgKKVwe (ORCPT ); Wed, 11 Nov 2020 16:52:34 -0500 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D3A5C0613D1; Wed, 11 Nov 2020 13:52:34 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id BE9711F45E06 From: Gabriel Krisman Bertazi To: dhowells@redhat.com Cc: viro@zeniv.linux.org.uk, tytso@mit.edu, khazhy@google.com, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel@collabora.com, Gabriel Krisman Bertazi Subject: [PATCH RFC v2 2/8] security: Add hooks to rule on setting a watch for superblock Date: Wed, 11 Nov 2020 16:52:07 -0500 Message-Id: <20201111215213.4152354-3-krisman@collabora.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201111215213.4152354-1-krisman@collabora.com> References: <20201111215213.4152354-1-krisman@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: David Howells Add security hooks that will allow an LSM to rule on whether or not a watch may be set for a supperblock. Signed-off-by: David Howells [Drop mount and key changes. Rebase to mainline] Signed-off-by: Gabriel Krisman Bertazi --- include/linux/lsm_hook_defs.h | 1 + include/linux/lsm_hooks.h | 4 ++++ include/linux/security.h | 13 +++++++++++++ security/security.c | 6 ++++++ 4 files changed, 24 insertions(+) diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h index 32a940117e7a..8fa8533598bc 100644 --- a/include/linux/lsm_hook_defs.h +++ b/include/linux/lsm_hook_defs.h @@ -261,6 +261,7 @@ LSM_HOOK(int, 0, inode_getsecctx, struct inode *inode, void **ctx, #if defined(CONFIG_SECURITY) && defined(CONFIG_WATCH_QUEUE) LSM_HOOK(int, 0, post_notification, const struct cred *w_cred, const struct cred *cred, struct watch_notification *n) +LSM_HOOK(int, 0, watch_sb, struct super_block *sb) #endif /* CONFIG_SECURITY && CONFIG_WATCH_QUEUE */ #if defined(CONFIG_SECURITY) && defined(CONFIG_KEY_NOTIFICATIONS) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index c503f7ab8afb..11197bf167d3 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -1475,6 +1475,10 @@ * @w_cred: The credentials of the whoever set the watch. * @cred: The event-triggerer's credentials * @n: The notification being posted + * @watch_sb: + * Check to see if a process is allowed to watch for event notifications + * from a superblock. + * @sb: The superblock to watch. * * @watch_key: * Check to see if a process is allowed to watch for event notifications diff --git a/include/linux/security.h b/include/linux/security.h index bc2725491560..078e11a8872a 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -456,6 +456,11 @@ 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); + +#ifdef CONFIG_WATCH_QUEUE +int security_watch_sb(struct super_block *sb); +#endif /* CONFIG_WATCH_QUEUE */ + #else /* CONFIG_SECURITY */ static inline int call_blocking_lsm_notifier(enum lsm_event event, void *data) @@ -1304,6 +1309,14 @@ static inline int security_locked_down(enum lockdown_reason what) { return 0; } + +#ifdef CONFIG_WATCH_QUEUE +static inline int security_watch_sb(struct super_block *sb) +{ + return 0; +} +#endif /* CONFIG_WATCH_QUEUE */ + #endif /* CONFIG_SECURITY */ #if defined(CONFIG_SECURITY) && defined(CONFIG_WATCH_QUEUE) diff --git a/security/security.c b/security/security.c index a28045dc9e7f..a23a972063cd 100644 --- a/security/security.c +++ b/security/security.c @@ -2074,6 +2074,12 @@ int security_post_notification(const struct cred *w_cred, { return call_int_hook(post_notification, 0, w_cred, cred, n); } + +int security_watch_sb(struct super_block *sb) +{ + return call_int_hook(watch_sb, 0, sb); +} + #endif /* CONFIG_WATCH_QUEUE */ #ifdef CONFIG_KEY_NOTIFICATIONS -- 2.29.2