Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp712584pxb; Tue, 3 Nov 2020 10:24:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJx4cfG3os2dBE8o5cHEmymhiZOhNsQR4jJ1jPn/OVGDm62gWask9at3I8DkHG1DbaY7Oe87 X-Received: by 2002:a05:6402:3136:: with SMTP id dd22mr11294176edb.256.1604427881512; Tue, 03 Nov 2020 10:24:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604427881; cv=none; d=google.com; s=arc-20160816; b=Cn+gTjIGPomt7fT1udOFWNLtWtwYGqqXy+MP+vmA2771kg5iWL3NWmgkmgQuXyjX5v kfg1gmtpOzQntr5DnDUuKKWxKjtmdlcavS9UwwiLrf2fPRBxTl9Xw6/3APCKr3s04MOm SBP//OOLbduhrhoN6uM293MNEV5pYY6ozXQM1BWeUUMY0K2Glw7NSMzV55JmEoyLokYW F7GZnRLLr5YxBl1Fzz2urw4U4QGvnAAQ07Qx53f/v+SHq4ktG4IPdKPmpFr46eRMnB9A Tz/RIKeYVkVXkq8SiBAIAItvYfpd5aVbJtrpidPx+ATbZqkzkeR4/HYWzpzAZ3/g3K0N nWmw== 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=XEmd1tlBQZ4uR5laNSWkbyJJHkReyfCD05x3VpQ+JaE=; b=JbTYQLncAer+uhcFBsJwiJoB/AvBgu4CbIA+pLbFNXm5YM22UTXpVDIVTgtGgOtAQz bGVWyjs9hWWSlHIsnemG3Z9gXBI5fJt9c7HqOUK7SObSBa+ptqAfGclgdOXqP5ddMqi5 5knrMN1PT+k1irBY/4eM7CZC8F0pSTz14eIPK7/45Mcgl++w61UOz8hAyNIVC6kmlXhL A7e3oyRTUwRTVOp5ql7pl70wxxc4Kfznro26Fh4V+Xtxz+k40080MgX0g0h79Dbc7K89 wegEDDvLtyvY/y1JZdag4PbKI9uxcNJv/8qY/1lVOdOKGN6iPcQBA7gCygw7Luvru7iG WIUA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g8si13308672edw.77.2020.11.03.10.24.18; Tue, 03 Nov 2020 10:24:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729391AbgKCSWZ (ORCPT + 99 others); Tue, 3 Nov 2020 13:22:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729396AbgKCSV0 (ORCPT ); Tue, 3 Nov 2020 13:21:26 -0500 Received: from smtp-190e.mail.infomaniak.ch (smtp-190e.mail.infomaniak.ch [IPv6:2001:1600:4:17::190e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AC01C040201 for ; Tue, 3 Nov 2020 10:21:24 -0800 (PST) Received: from smtp-2-0001.mail.infomaniak.ch (unknown [10.5.36.108]) by smtp-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4CQdQW33Z8zlhl6F; Tue, 3 Nov 2020 19:21:23 +0100 (CET) Received: from localhost (unknown [94.23.54.103]) by smtp-2-0001.mail.infomaniak.ch (Postfix) with ESMTPA id 4CQdQV1vstzlh8T2; Tue, 3 Nov 2020 19:21:22 +0100 (CET) From: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= To: James Morris , "Serge E . Hallyn" Cc: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Al Viro , Andy Lutomirski , Anton Ivanov , Arnd Bergmann , Casey Schaufler , Jann Horn , Jeff Dike , Jonathan Corbet , Kees Cook , Michael Kerrisk , Richard Weinberger , Shuah Khan , Vincent Dagonneau , kernel-hardening@lists.openwall.com, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-security-module@vger.kernel.org, x86@kernel.org, =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= Subject: [PATCH v23 06/12] fs,security: Add sb_delete hook Date: Tue, 3 Nov 2020 19:21:03 +0100 Message-Id: <20201103182109.1014179-7-mic@digikod.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201103182109.1014179-1-mic@digikod.net> References: <20201103182109.1014179-1-mic@digikod.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mickaël Salaün The sb_delete security hook is called when shutting down a superblock, which may be useful to release kernel objects tied to the superblock's lifetime (e.g. inodes). This new hook is needed by Landlock to release (ephemerally) tagged struct inodes. This comes from the unprivileged nature of Landlock described in the next commit. Cc: Al Viro Cc: James Morris Cc: Kees Cook Cc: Serge E. Hallyn Signed-off-by: Mickaël Salaün Reviewed-by: Jann Horn --- Changes since v17: * Initial patch to replace the direct call to landlock_release_inodes() (requested by James Morris). https://lore.kernel.org/lkml/alpine.LRH.2.21.2005150536440.7929@namei.org/ --- fs/super.c | 1 + include/linux/lsm_hook_defs.h | 1 + include/linux/lsm_hooks.h | 2 ++ include/linux/security.h | 4 ++++ security/security.c | 5 +++++ 5 files changed, 13 insertions(+) diff --git a/fs/super.c b/fs/super.c index a51c2083cd6b..fea9475189f7 100644 --- a/fs/super.c +++ b/fs/super.c @@ -454,6 +454,7 @@ void generic_shutdown_super(struct super_block *sb) evict_inodes(sb); /* only nonzero refcount inodes can have marks */ fsnotify_sb_delete(sb); + security_sb_delete(sb); if (sb->s_dio_done_wq) { destroy_workqueue(sb->s_dio_done_wq); diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h index 32a940117e7a..1ba9b4dfecb3 100644 --- a/include/linux/lsm_hook_defs.h +++ b/include/linux/lsm_hook_defs.h @@ -59,6 +59,7 @@ LSM_HOOK(int, 0, fs_context_dup, struct fs_context *fc, LSM_HOOK(int, -ENOPARAM, fs_context_parse_param, struct fs_context *fc, struct fs_parameter *param) LSM_HOOK(int, 0, sb_alloc_security, struct super_block *sb) +LSM_HOOK(void, LSM_RET_VOID, sb_delete, struct super_block *sb) LSM_HOOK(void, LSM_RET_VOID, sb_free_security, struct super_block *sb) LSM_HOOK(void, LSM_RET_VOID, sb_free_mnt_opts, void *mnt_opts) LSM_HOOK(int, 0, sb_eat_lsm_opts, char *orig, void **mnt_opts) diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index ff0f03a45c56..dbfcec05a176 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -108,6 +108,8 @@ * allocated. * @sb contains the super_block structure to be modified. * Return 0 if operation was successful. + * @sb_delete: + * Release objects tied to a superblock (e.g. inodes). * @sb_free_security: * Deallocate and clear the sb->s_security field. * @sb contains the super_block structure to be modified. diff --git a/include/linux/security.h b/include/linux/security.h index bc2725491560..a4603b62d444 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -287,6 +287,7 @@ void security_bprm_committed_creds(struct linux_binprm *bprm); int security_fs_context_dup(struct fs_context *fc, struct fs_context *src_fc); int security_fs_context_parse_param(struct fs_context *fc, struct fs_parameter *param); int security_sb_alloc(struct super_block *sb); +void security_sb_delete(struct super_block *sb); void security_sb_free(struct super_block *sb); void security_free_mnt_opts(void **mnt_opts); int security_sb_eat_lsm_opts(char *options, void **mnt_opts); @@ -619,6 +620,9 @@ static inline int security_sb_alloc(struct super_block *sb) return 0; } +static inline void security_sb_delete(struct super_block *sb) +{ } + static inline void security_sb_free(struct super_block *sb) { } diff --git a/security/security.c b/security/security.c index 4ffd6c3af9d7..4563e7a79216 100644 --- a/security/security.c +++ b/security/security.c @@ -899,6 +899,11 @@ int security_sb_alloc(struct super_block *sb) return rc; } +void security_sb_delete(struct super_block *sb) +{ + call_void_hook(sb_delete, sb); +} + void security_sb_free(struct super_block *sb) { call_void_hook(sb_free_security, sb); -- 2.28.0