Messages in this thread | | | From | Dongliang Mu <> | Date | Mon, 15 Aug 2022 08:59:11 +0800 | Subject | Re: [PATCH] drivers: binderfs: fix memory leak in binderfs_fill_super |
| |
On Fri, Aug 12, 2022 at 10:18 PM Christian Brauner <brauner@kernel.org> wrote: > > 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@kernel.org> wrote: > > > > > > On Fri, Aug 12, 2022 at 09:21:24PM +0800, Dongliang Mu wrote: > > > > From: Dongliang Mu <mudongliangabcd@gmail.com> > > > > > > > > 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@googlegroups.com> > > > > Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com> > > > > --- > > > > > > 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.
Hi Christian,
So the final decision is to keep the cleanup or error handling code in a single goto location at the end of binderfs_fill_super.
If I understand correctly, this change keeps the same semantic as mine but is more elegant to maintain.
| |