2020-05-27 20:01:11

by Qiushi Wu

[permalink] [raw]
Subject: [PATCH] nilfs2: Fix reference count leak in nilfs_sysfs_create_snapshot_group.

From: Qiushi Wu <[email protected]>

kobject_init_and_add() takes reference even when it fails.
If this function returns an error, kobject_put() must be called to
properly clean up the memory associated with the object. Previous
commit "b8eb718348b8" fixed a similar problem.

Fixes: a5a7332a291b ("nilfs2: add /sys/fs/nilfs2/<device>/mounted_snapshots/<snapshot>group")
Signed-off-by: Qiushi Wu <[email protected]>
---
fs/nilfs2/sysfs.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/nilfs2/sysfs.c b/fs/nilfs2/sysfs.c
index e60be7bb55b0..b2517c5e773a 100644
--- a/fs/nilfs2/sysfs.c
+++ b/fs/nilfs2/sysfs.c
@@ -209,8 +209,10 @@ int nilfs_sysfs_create_snapshot_group(struct nilfs_root *root)
"%llu", root->cno);
}

- if (err)
+ if (err) {
+ kobject_put(&root->snapshot_kobj);
return err;
+ }

return 0;
}
--
2.17.1


2020-05-27 22:03:08

by Ryusuke Konishi

[permalink] [raw]
Subject: Re: [PATCH] nilfs2: Fix reference count leak in nilfs_sysfs_create_snapshot_group.

Andrew,

Apply this, please.

Acked-by: Ryusuke Konishi <[email protected]>

On Thu, May 28, 2020 at 4:55 AM <[email protected]> wrote:
>
> From: Qiushi Wu <[email protected]>
>
> kobject_init_and_add() takes reference even when it fails.
> If this function returns an error, kobject_put() must be called to
> properly clean up the memory associated with the object. Previous
> commit "b8eb718348b8" fixed a similar problem.
>
> Fixes: a5a7332a291b ("nilfs2: add /sys/fs/nilfs2/<device>/mounted_snapshots/<snapshot>group")
> Signed-off-by: Qiushi Wu <[email protected]>
> ---
> fs/nilfs2/sysfs.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/fs/nilfs2/sysfs.c b/fs/nilfs2/sysfs.c
> index e60be7bb55b0..b2517c5e773a 100644
> --- a/fs/nilfs2/sysfs.c
> +++ b/fs/nilfs2/sysfs.c
> @@ -209,8 +209,10 @@ int nilfs_sysfs_create_snapshot_group(struct nilfs_root *root)
> "%llu", root->cno);
> }
>
> - if (err)
> + if (err) {
> + kobject_put(&root->snapshot_kobj);
> return err;
> + }
>
> return 0;
> }
> --
> 2.17.1
>