diff mbox series

ovl: fix memory leak in ovl_parse_param

Message ID tencent_3FF186FD92C8C658498FEEEE6EDACC8BA706@qq.com (mailing list archive)
State New, archived
Headers show
Series ovl: fix memory leak in ovl_parse_param | expand

Commit Message

Edward Adam Davis Nov. 12, 2023, 10:35 a.m. UTC
After failing to parse parameters in ovl_parse_param_lowerdir(), it is 
necessary to update ctx->nr with the correct nr before using 
ovl_reset_lowerdirs() to release l->name.

Reported-and-tested-by: syzbot+26eedf3631650972f17c@syzkaller.appspotmail.com
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
---
 fs/overlayfs/params.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Amir Goldstein Nov. 12, 2023, 2:36 p.m. UTC | #1
On Sun, Nov 12, 2023 at 12:35 PM Edward Adam Davis <eadavis@qq.com> wrote:
>
> After failing to parse parameters in ovl_parse_param_lowerdir(), it is
> necessary to update ctx->nr with the correct nr before using
> ovl_reset_lowerdirs() to release l->name.
>
> Reported-and-tested-by: syzbot+26eedf3631650972f17c@syzkaller.appspotmail.com
> Signed-off-by: Edward Adam Davis <eadavis@qq.com>
> ---
>  fs/overlayfs/params.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/fs/overlayfs/params.c b/fs/overlayfs/params.c
> index ddab9ea267d1..1f73f0173015 100644
> --- a/fs/overlayfs/params.c
> +++ b/fs/overlayfs/params.c
> @@ -530,6 +530,7 @@ static int ovl_parse_param_lowerdir(const char *name, struct fs_context *fc)
>         return 0;
>
>  out_put:
> +       ctx->nr = nr;
>         ovl_reset_lowerdirs(ctx);
>
>  out_err:
> --
> 2.25.1
>

Thanks for the patch!

I prefer to fix it by eliminating the local vars instead of
syncing with them:

I've kept your commit message and tagged you as Co-authored-by:
https://github.com/amir73il/linux/commit/97d58994e880ccb19e1b9b935928538903fca41c

Thanks,
Amir.
diff mbox series

Patch

diff --git a/fs/overlayfs/params.c b/fs/overlayfs/params.c
index ddab9ea267d1..1f73f0173015 100644
--- a/fs/overlayfs/params.c
+++ b/fs/overlayfs/params.c
@@ -530,6 +530,7 @@  static int ovl_parse_param_lowerdir(const char *name, struct fs_context *fc)
 	return 0;
 
 out_put:
+	ctx->nr = nr;
 	ovl_reset_lowerdirs(ctx);
 
 out_err: