Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp899985pxf; Wed, 7 Apr 2021 14:32:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxlA4mK1+43xA003YfokpMCVNUvw0lMSbmlMP6R4JZU80V0c5JcX+0z25bEo1LrsWmHLKVw X-Received: by 2002:a17:907:3f10:: with SMTP id hq16mr6227840ejc.181.1617831156087; Wed, 07 Apr 2021 14:32:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617831156; cv=none; d=google.com; s=arc-20160816; b=kGWb1pWoklPal+o/vKX94iw/fvgaCi1dxd5Aon5xPYanGcQJHuedOM9BKyf5dXrQTT JgWoSUMSGPkiROssa+SOQ1bY1fYrF0Pop3PDQJ1i1x9Mp1Z9XCILqMoCOny3Ydh+KBW9 p+mivZ2xfXTaql+FHA8yg8UW58Nw6TbZd8eoXqoq5hIaLYS1yCvmi2l2gAg4fHRNggVF kP1UUCCqXeTvE5u3uJzMHynTo59ow8p7H09hM4zHLK7kc8em0ZQMWtd9wRtrAqo/8HNp Jdf1umrKgHIAoY22vpm11IEYlL2rMiSgwZ8OgriC309qNSjBmc4maIHJoYQCYm4vWGmc h1SA== 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=sFKlv57/sWYdt5sEeexiBHlZNuSU8kxskAuXVznSILo=; b=GKsFnagws7LB2Tf3XTTmQzk0X/EjsbkT2FK/axV/mWJlyOyHBJTysl+E3NEjuJK1xe /kpsOuq5ZM0BmpvQBsS2b3Wb16s/l0Srg4ndIriskoBnOAj/oENe40FoxFSM+rl0uwTS 2dl7dBYPCLfRSuOBrMWJqOvdsZJK9f6IpwSiIZHwy86cz5M6TB1EQkEKCHagGC8xPCDL MSkoAJH6/Lri5RxMSDY0A/jWSYGyr2DoCesxxZj5AMdP8LcTcZXmnntaKyh2N7ij/pI1 DrY7oFvD79XvHb8QxC0O+fMJa38QcCf35f8WILJ1gRBkCZqic0ZwbgoybXhRY2wlLjA+ OamQ== 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 dr7si22817861ejc.126.2021.04.07.14.32.06; Wed, 07 Apr 2021 14:32:36 -0700 (PDT) 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 S1354188AbhDGQGs (ORCPT + 99 others); Wed, 7 Apr 2021 12:06:48 -0400 Received: from smtp-190f.mail.infomaniak.ch ([185.125.25.15]:34781 "EHLO smtp-190f.mail.infomaniak.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354138AbhDGQGM (ORCPT ); Wed, 7 Apr 2021 12:06:12 -0400 Received: from smtp-2-0001.mail.infomaniak.ch (unknown [10.5.36.108]) by smtp-2-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4FFq4k0fRjzMqJTG; Wed, 7 Apr 2021 18:05:58 +0200 (CEST) Received: from localhost (unknown [23.97.221.149]) by smtp-2-0001.mail.infomaniak.ch (Postfix) with ESMTPA id 4FFq4j4c1Zzlh8TD; Wed, 7 Apr 2021 18:05:57 +0200 (CEST) From: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= To: James Morris , Jann Horn , "Serge E . Hallyn" Cc: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Al Viro , Andrew Morton , Andy Lutomirski , Anton Ivanov , Arnd Bergmann , Casey Schaufler , David Howells , 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 v33 06/12] fs,security: Add sb_delete hook Date: Wed, 7 Apr 2021 18:07:20 +0200 Message-Id: <20210407160726.542794-7-mic@digikod.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210407160726.542794-1-mic@digikod.net> References: <20210407160726.542794-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 Signed-off-by: Mickaël Salaün Reviewed-by: Jann Horn Acked-by: Serge Hallyn Reviewed-by: Kees Cook Link: https://lore.kernel.org/r/20210407160726.542794-7-mic@digikod.net --- Changes since v30: * Add Reviewed-by Kees Cook. Changes since v28: * Extend hook description (suggested by Serge Hallyn). * Add Acked-by Serge Hallyn. Changes since v22: * Add 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 | 3 +++ include/linux/security.h | 4 ++++ security/security.c | 5 +++++ 5 files changed, 14 insertions(+) diff --git a/fs/super.c b/fs/super.c index 8c1baca35c16..11b7e7213fd1 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 477a597db013..e8adadbf9581 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 75715998a95f..cc2eaaaec0e4 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -108,6 +108,9 @@ * 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 contains the super_block structure being released. * @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 8aeebd6646dc..90298baa4551 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -291,6 +291,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); @@ -631,6 +632,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 e9c29480eb18..bb666f992497 100644 --- a/security/security.c +++ b/security/security.c @@ -900,6 +900,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.30.2