Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2231934pxb; Fri, 5 Feb 2021 12:14:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJw76vP6YwfvwoKJ5sWyegtufnogZtWQ8F5SaJD+w6gm7GIVgtcd9yaTdaH5f75dB/txuPwa X-Received: by 2002:a17:906:15c7:: with SMTP id l7mr5667000ejd.226.1612556053360; Fri, 05 Feb 2021 12:14:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612556053; cv=none; d=google.com; s=arc-20160816; b=J+nioi+lCdtqI2SSs+y4goyMQlkL5XlU1Jv1QmyWob0g/F4QR13xN1OQS7I68Aq0rm WG/AMiYhqHz8oJS6+4ni9ro5fwPXt7Ox9OIppLHOh12dnyBcz851RKP0+INCilpq9TBi ok3pGPcPKfMzOsK9syvCLTG4TaU/4/TGFV8c781u5Rie3xg6ggFS66tIPwo9bsP0wupg ngE2eX5mcE348imG3t6Wsrs5HwDIq3TYfgYgkcfcQ2x7ZEZ7BHhxb7ehx+FaDGPyDHsa hGufVLxf8vQ3Kw8Po8WSsRTSoZEsHDnh+4pR35JjNC8RnpiUk/HGN1cq6bKbZSkOCV3j EqxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=47ZntiUpbMihLTRQdkwaMJPXN5ytI+epG3TvlbY63yU=; b=0taCK9qrPgE6db0LeBUzPQlPpS6ZYY6jtApouFWI5UWwB12PYZw2JqrbVgxi7+vD3A mUMAKb4Uc054IQ110hqrwgUjIqndA2DnQesJINeiZVgpcBkHF30ZAS1Z+R3usfXxfBnh bzXtnxbRCdiLb9+6gCwPW7TqwC20gJvuHxqpl3Ts/lTwNdWSva7zwPXmQx4wdDcuuHuq Aj1D2hl6P8PfVZsGLrXntXz67GJklnCR1Cg6CpRqNhf1jCy5IDWpCjy7VAQQSg1GuDx/ dXFGg317P9BlOBGQMGQkg8DJRJBlOGpf++bq0tJfdHcHLtqGN7RNLV4rDCsY3RnpB47S oeEA== 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 cf14si1746053edb.354.2021.02.05.12.13.49; Fri, 05 Feb 2021 12:14:13 -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 S231261AbhBESah (ORCPT + 99 others); Fri, 5 Feb 2021 13:30:37 -0500 Received: from mail.hallyn.com ([178.63.66.53]:53330 "EHLO mail.hallyn.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233134AbhBEPND (ORCPT ); Fri, 5 Feb 2021 10:13:03 -0500 Received: by mail.hallyn.com (Postfix, from userid 1001) id 30841283; Fri, 5 Feb 2021 08:21:43 -0600 (CST) Date: Fri, 5 Feb 2021 08:21:43 -0600 From: "Serge E. Hallyn" To: =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= Cc: James Morris , Jann Horn , "Serge E . Hallyn" , Al Viro , Andrew Morton , Andy Lutomirski , Anton Ivanov , Arnd Bergmann , Casey Schaufler , 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, =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= Subject: Re: [PATCH v28 06/12] fs,security: Add sb_delete hook Message-ID: <20210205142143.GA18451@mail.hallyn.com> References: <20210202162710.657398-1-mic@digikod.net> <20210202162710.657398-7-mic@digikod.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210202162710.657398-7-mic@digikod.net> User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 02, 2021 at 05:27:04PM +0100, Micka?l Sala?n wrote: > 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 One note below, but Acked-by: Serge Hallyn > Signed-off-by: Micka?l Sala?n > Reviewed-by: Jann Horn > --- > > 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 | 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 2c6cdea2ab2d..c3c5178cde65 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 7aaa753b8608..32472b3849bc 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 970106d98306..e339b201f79b 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). It's customary here to add the line detailing the @sb argument. > * @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 c35ea0ffccd9..c41a94e29b62 100644 > --- a/include/linux/security.h > +++ b/include/linux/security.h > @@ -288,6 +288,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); > @@ -620,6 +621,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 9f979d4afe6c..1b4a73b2549a 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.0