Messages in this thread Patch in this message | | | Date | Wed, 17 Aug 2022 16:51:44 +0200 | From | Christian Brauner <> | Subject | Re: [PATCH] binderfs: rework superblock destruction |
| |
On Wed, Aug 17, 2022 at 03:19:13PM +0100, Al Viro wrote: > On Wed, Aug 17, 2022 at 04:01:49PM +0200, Christian Brauner wrote: > > On Wed, Aug 17, 2022 at 02:59:02PM +0100, Al Viro wrote: > > > On Wed, Aug 17, 2022 at 03:03:06PM +0200, Christian Brauner wrote: > > > > > > > +static void binderfs_kill_super(struct super_block *sb) > > > > +{ > > > > + struct binderfs_info *info = sb->s_fs_info; > > > > + > > > > + if (info && info->ipc_ns) > > > > + put_ipc_ns(info->ipc_ns); > > > > + > > > > + kfree(info); > > > > + kill_litter_super(sb); > > > > +} > > > > > > Other way round, please - shut the superblock down, *then* > > > free the objects it'd been using. IOW, > > > > I wondered about that but a lot of places do it the other way around. > > So maybe the expected order should be documented somewhere. > > ??? > > "If you are holding internal references to dentries/inodes/etc., drop them > first; if you are going to free something that is used by filesystem > methods, don't do that before the filesystem is shut down" > > That's just common sense... Which filesystems are doing that "the other > way around"?
I think at least these below. Completely untested...
Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org> --- arch/s390/hypfs/inode.c | 3 +-- fs/devpts/inode.c | 2 +- fs/ramfs/inode.c | 4 +++- security/selinux/selinuxfs.c | 12 ++++++------ 4 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/arch/s390/hypfs/inode.c b/arch/s390/hypfs/inode.c index 5c97f48cea91..d7d275ef132f 100644 --- a/arch/s390/hypfs/inode.c +++ b/arch/s390/hypfs/inode.c @@ -329,9 +329,8 @@ static void hypfs_kill_super(struct super_block *sb) hypfs_delete_tree(sb->s_root); if (sb_info && sb_info->update_file) hypfs_remove(sb_info->update_file); - kfree(sb->s_fs_info); - sb->s_fs_info = NULL; kill_litter_super(sb); + kfree(sb->s_fs_info); } static struct dentry *hypfs_create_file(struct dentry *parent, const char *name, diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c index 4f25015aa534..78a9095e1748 100644 --- a/fs/devpts/inode.c +++ b/fs/devpts/inode.c @@ -509,10 +509,10 @@ static void devpts_kill_sb(struct super_block *sb) { struct pts_fs_info *fsi = DEVPTS_SB(sb); + kill_litter_super(sb); if (fsi) ida_destroy(&fsi->allocated_ptys); kfree(fsi); - kill_litter_super(sb); } static struct file_system_type devpts_fs_type = { diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c index bc66d0173e33..bff49294e037 100644 --- a/fs/ramfs/inode.c +++ b/fs/ramfs/inode.c @@ -280,8 +280,10 @@ int ramfs_init_fs_context(struct fs_context *fc) static void ramfs_kill_sb(struct super_block *sb) { - kfree(sb->s_fs_info); + struct ramfs_fs_info *fsi = sb->s_fs_info; + kill_litter_super(sb); + kfree(fsi); } static struct file_system_type ramfs_fs_type = { diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c index 8fcdd494af27..fb1dae422d93 100644 --- a/security/selinux/selinuxfs.c +++ b/security/selinux/selinuxfs.c @@ -96,9 +96,8 @@ static int selinux_fs_info_create(struct super_block *sb) return 0; } -static void selinux_fs_info_free(struct super_block *sb) +static void selinux_fs_info_free(struct selinux_fs_info *fsi) { - struct selinux_fs_info *fsi = sb->s_fs_info; int i; if (fsi) { @@ -107,8 +106,7 @@ static void selinux_fs_info_free(struct super_block *sb) kfree(fsi->bool_pending_names); kfree(fsi->bool_pending_values); } - kfree(sb->s_fs_info); - sb->s_fs_info = NULL; + kfree(fsi); } #define SEL_INITCON_INO_OFFSET 0x01000000 @@ -2180,7 +2178,7 @@ static int sel_fill_super(struct super_block *sb, struct fs_context *fc) pr_err("SELinux: %s: failed while creating inodes\n", __func__); - selinux_fs_info_free(sb); + selinux_fs_info_free(fsi); return ret; } @@ -2202,8 +2200,10 @@ static int sel_init_fs_context(struct fs_context *fc) static void sel_kill_sb(struct super_block *sb) { - selinux_fs_info_free(sb); + struct selinux_fs_info *fsi = sb->s_fs_info; + kill_litter_super(sb); + selinux_fs_info_free(fsi); } static struct file_system_type sel_fs_type = { -- 2.34.1
| |