Re: [PATCH] drivers: binderfs: fix memory leak in binderfs_fill_super
From: Christian Brauner
Date: Fri Aug 12 2022 - 10:19:59 EST
On Fri, Aug 12, 2022 at 09:48:40PM +0800, Dongliang Mu wrote:
> On Fri, Aug 12, 2022 at 9:41 PM Christian Brauner <brauner@xxxxxxxxxx> wrote:
> >
> > On Fri, Aug 12, 2022 at 09:21:24PM +0800, Dongliang Mu wrote:
> > > From: Dongliang Mu <mudongliangabcd@xxxxxxxxx>
> > >
> > > In binderfs_fill_super, if s_root is not successfully initialized by
> > > d_make_root, the previous allocated s_sb_info will not be freed since
> > > generic_shutdown_super first checks if sb->s_root and then does
> > > put_super operation. The put_super operation calls binderfs_put_super
> > > to deallocate s_sb_info and put ipc_ns. This will lead to memory leak
> > > in binderfs_fill_super.
> > >
> > > Fix this by invoking binderfs_put_super at error sites before s_root
> > > is successfully initialized.
> > >
> > > Fixes: 095cf502b31e ("binderfs: port to new mount api")
> > > Reported-by: syzkaller <syzkaller@xxxxxxxxxxxxxxxx>
> > > Signed-off-by: Dongliang Mu <mudongliangabcd@xxxxxxxxx>
> > > ---
> >
> > Seems right but where's the full syzbot link to the issue?
> > Also, wouldn't (untested) sm like the below be better?:
>
> I originally would like to change the order to object initialization,
> but I am not sure if they can be exchanged since many *_fill_super are
> ended with d_make_root.
>
> If you are sure about this exchange, I can resubmit a v2 patch.
I think we should just always clean up the allocated memory in
binderfs_fill_super() when d_make_root() fails and before via a goto
block after the successful return. So we keep the cleanup in
binderfs_fill_super() consistent and restricted to a single location.