Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4677798pxu; Wed, 21 Oct 2020 02:26:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzm4xtoPKaVyab7k66gYUulbfvvhuJ/K/R3eDjlaFR+k3fJayBxQTwmj6BlO2SlHUQjtDPr X-Received: by 2002:a17:906:fc10:: with SMTP id ov16mr2637309ejb.417.1603272380032; Wed, 21 Oct 2020 02:26:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603272380; cv=none; d=google.com; s=arc-20160816; b=PdwtEw1aiEhXd9nnqOMQyqzOH5t5nW0xtKsoeHdg5rKR2p4+JstFCXdFHSgfS0Lggh +zdfgw9eCSuL6bmDvrsmahl/LFraabzuLyldZY3J1yVbUduLQX2YR2DjZ8wUZhyN8iwA VvnBwu1TMnPpqilUe2rnvJ1AFwrofi1C0Vf50qAP/SsAmqRGce1AB086MTzT7Q8nsenn KJm01XTKbCw9SlHk8dxgdqSSGIRwkdpoRasOqrsehPksa4JUWVEZd4jYyaoLO39dsVoP +jqSwY6GFKgYwolkJ6Z7o7TqxsUfnn0VWJJwU/XNulbcNXC6/6KNB2nGxg8lPRZqmNQW /mvQ== 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=03XzyPRqTYqPotDy0MiXJcgZfWZTR5R9qfPuX0FwCjA=; b=rXyQc0EK3g8NiySJsZTePMFQuCGtoFx6Va/J6Bh2ujBxeYlx6200nt/exGefxUrlzT MAJKCDMciEFWZM6LLSizaXy8xfAju1sO01c2qUf6hMiErBeN0b4ZX0oZZAFcwsU+J/+Y M8c1hOPLlwo/cg+tje4pfSFIs5uj/5/aEpJTPK+9CCciYBamEtv1Oz7P4cAZ9c6kZDkk hXeEID1UrMe60jnZHMBtapf48jc7pNybrH9OrF8TPZPEVw6eK6SwHDOEkAB8rxH9OcPG AmnY1Hhlju1x1E2y3TpxItrJXy6vEXWIDpzjnmW4jOVzQlI1bZFGjuZDSB6TqsTf072V WiuA== 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 w26si954790ejn.748.2020.10.21.02.25.52; Wed, 21 Oct 2020 02:26:20 -0700 (PDT) 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 S2438040AbgJTTP5 (ORCPT + 99 others); Tue, 20 Oct 2020 15:15:57 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:44556 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438038AbgJTTP4 (ORCPT ); Tue, 20 Oct 2020 15:15:56 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id BDAB41F44C36 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 2/7] security: Add hooks to rule on setting a watch for superblock Date: Tue, 20 Oct 2020 15:15:38 -0400 Message-Id: <20201020191543.601784-3-krisman@collabora.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201020191543.601784-1-krisman@collabora.com> References: <20201020191543.601784-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 | 7 +++++++ 4 files changed, 25 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 8814e3d5952d..325f50bea1ba 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..a5581aadc644 100644 --- a/security/security.c +++ b/security/security.c @@ -2068,12 +2068,19 @@ int security_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen) EXPORT_SYMBOL(security_inode_getsecctx); #ifdef CONFIG_WATCH_QUEUE + int security_post_notification(const struct cred *w_cred, const struct cred *cred, struct watch_notification *n) { 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.28.0