* [PATCH v2] binderfs: rework superblock destruction
@ 2022-08-23 9:53 Christian Brauner
2022-08-23 10:45 ` Greg Kroah-Hartman
0 siblings, 1 reply; 3+ messages in thread
From: Christian Brauner @ 2022-08-23 9:53 UTC (permalink / raw)
To: Greg Kroah-Hartman, Todd Kjos, linux-kernel
Cc: Al Viro, Arve Hjønnevåg, Martijn Coenen, Joel Fernandes,
Carlos Llamas, Suren Baghdasaryan, Kees Cook, Dongliang Mu,
syzkaller
From: Al Viro <viro@zeniv.linux.org.uk>
So far we relied on
.put_super = binderfs_put_super()
to destroy info we stashed in sb->s_fs_info. This gave us the required ordering
between ->evict_inode() and sb->s_fs_info destruction.
But the current implementation of binderfs_fill_super() has a memory leak in
the rare circumstance that d_make_root() fails because ->put_super() is only
called when sb->s_root is initialized. Fix this by removing ->put_super() and
simply do all that work in binderfs_kill_super().
Reported-by: Dongliang Mu <mudongliangabcd@gmail.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
---
drivers/android/binderfs.c | 30 +++++++++++++++++-------------
1 file changed, 17 insertions(+), 13 deletions(-)
diff --git a/drivers/android/binderfs.c b/drivers/android/binderfs.c
index 588d753a7a19..927776fdeb1a 100644
--- a/drivers/android/binderfs.c
+++ b/drivers/android/binderfs.c
@@ -340,22 +340,10 @@ static int binderfs_show_options(struct seq_file *seq, struct dentry *root)
return 0;
}
-static void binderfs_put_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);
- sb->s_fs_info = NULL;
-}
-
static const struct super_operations binderfs_super_ops = {
.evict_inode = binderfs_evict_inode,
.show_options = binderfs_show_options,
.statfs = simple_statfs,
- .put_super = binderfs_put_super,
};
static inline bool is_binderfs_control_device(const struct dentry *dentry)
@@ -785,11 +773,27 @@ static int binderfs_init_fs_context(struct fs_context *fc)
return 0;
}
+static void binderfs_kill_super(struct super_block *sb)
+{
+ struct binderfs_info *info = sb->s_fs_info;
+
+ /*
+ * During inode eviction struct binderfs_info is needed.
+ * So first wipe the super_block then free struct binderfs_info.
+ */
+ kill_litter_super(sb);
+
+ if (info && info->ipc_ns)
+ put_ipc_ns(info->ipc_ns);
+
+ kfree(info);
+}
+
static struct file_system_type binder_fs_type = {
.name = "binder",
.init_fs_context = binderfs_init_fs_context,
.parameters = binderfs_fs_parameters,
- .kill_sb = kill_litter_super,
+ .kill_sb = binderfs_kill_super,
.fs_flags = FS_USERNS_MOUNT,
};
base-commit: 1c23f9e627a7b412978b4e852793c5e3c3efc555
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] binderfs: rework superblock destruction
2022-08-23 9:53 [PATCH v2] binderfs: rework superblock destruction Christian Brauner
@ 2022-08-23 10:45 ` Greg Kroah-Hartman
2022-08-23 10:57 ` Christian Brauner
0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2022-08-23 10:45 UTC (permalink / raw)
To: Christian Brauner
Cc: Todd Kjos, linux-kernel, Al Viro, Arve Hjønnevåg,
Martijn Coenen, Joel Fernandes, Carlos Llamas, Suren Baghdasaryan,
Kees Cook, Dongliang Mu, syzkaller
On Tue, Aug 23, 2022 at 11:53:39AM +0200, Christian Brauner wrote:
> From: Al Viro <viro@zeniv.linux.org.uk>
>
> So far we relied on
> .put_super = binderfs_put_super()
> to destroy info we stashed in sb->s_fs_info. This gave us the required ordering
> between ->evict_inode() and sb->s_fs_info destruction.
>
> But the current implementation of binderfs_fill_super() has a memory leak in
> the rare circumstance that d_make_root() fails because ->put_super() is only
> called when sb->s_root is initialized. Fix this by removing ->put_super() and
> simply do all that work in binderfs_kill_super().
>
> Reported-by: Dongliang Mu <mudongliangabcd@gmail.com>
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
> ---
> drivers/android/binderfs.c | 30 +++++++++++++++++-------------
> 1 file changed, 17 insertions(+), 13 deletions(-)
What changed from v1?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] binderfs: rework superblock destruction
2022-08-23 10:45 ` Greg Kroah-Hartman
@ 2022-08-23 10:57 ` Christian Brauner
0 siblings, 0 replies; 3+ messages in thread
From: Christian Brauner @ 2022-08-23 10:57 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Todd Kjos, linux-kernel, Al Viro, Arve Hjønnevåg,
Martijn Coenen, Joel Fernandes, Carlos Llamas, Suren Baghdasaryan,
Kees Cook, Dongliang Mu, syzkaller
On Tue, Aug 23, 2022 at 12:45:26PM +0200, Greg Kroah-Hartman wrote:
> On Tue, Aug 23, 2022 at 11:53:39AM +0200, Christian Brauner wrote:
> > From: Al Viro <viro@zeniv.linux.org.uk>
> >
> > So far we relied on
> > .put_super = binderfs_put_super()
> > to destroy info we stashed in sb->s_fs_info. This gave us the required ordering
> > between ->evict_inode() and sb->s_fs_info destruction.
> >
> > But the current implementation of binderfs_fill_super() has a memory leak in
> > the rare circumstance that d_make_root() fails because ->put_super() is only
> > called when sb->s_root is initialized. Fix this by removing ->put_super() and
> > simply do all that work in binderfs_kill_super().
> >
> > Reported-by: Dongliang Mu <mudongliangabcd@gmail.com>
> > Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> > Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
> > ---
> > drivers/android/binderfs.c | 30 +++++++++++++++++-------------
> > 1 file changed, 17 insertions(+), 13 deletions(-)
>
> What changed from v1?
Ah, forgot to add:
/* v2 */
Christian Brauner (Microsoft) <brauner@kernel.org>:
- Call kill_litter_super() before sb->s_fs_info cleanup.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-08-23 13:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-23 9:53 [PATCH v2] binderfs: rework superblock destruction Christian Brauner
2022-08-23 10:45 ` Greg Kroah-Hartman
2022-08-23 10:57 ` Christian Brauner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox