UBIFS: fix memory leak on error path
Subsystems (2)
PATCH 1/1 UBIFS: fix memory leak on error path
UBIFS leaks memory on error path in 'mount_ubifs()'. In case of failure in 'ubifs_lpt_init()' or 'ubifs_fixup_free_space()', it does not call 'ubifs_lpt_free()' whereas LPT data structures can potentially be allocated. The amount of memory leaked can be quite high -- see 'ubifs_lpt_init()'.
The bug was introduced when moving the LPT initialisation earlier in the mount process (commit '781c5717a95a74b294beb38b8276943b0f8b5bb4').
--- fs/ubifs/super.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
fs/ubifs/super.c +2 -2
@@ -1296,12 +1296,12 @@ static int mount_ubifs(struct ubifs_info *c) err =ubifs_lpt_init (c,1 , !c->ro_mount);if (err) - goto out_master; + goto out_lpt;if (!c->ro_mount && c->space_fixup) { err =ubifs_fixup_free_space (c);if (err) - goto out_master; + goto out_lpt; }if (!c->ro_mount) {
Signature · 1 line
1.7.5.4
PATCH 1/2 UBIFS: make ubifs_lpt_init clean-up in case of failure
From: Artem Bityutskiy <[email protected]>
Most functions in UBIFS follow the following designn pattern: if the function allocates multiple resources, and failss at some point, it frees what it has allocated and returns an error. So the caller can rely on the fact that the callee has cleaned up everything after own failure.
--- fs/ubifs/lpt.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
fs/ubifs/lpt.c +6 -2
@@ -1740,16 +1740,20 @@ int ubifs_lpt_init(struct ubifs_info *c, int rd, int wr)if (rd) { err =lpt_init_rd (c);if (err) -return err; + goto out_err; }if (wr) { err =lpt_init_wr (c);if (err) -return err; + goto out_err; }return 0 ; + +out_err: +ubifs_lpt_free (c,0 ); +return err; }/**
Signature · 1 line
1.7.10
PATCH 2/2 UBIFS: fix memory leak on error path
From: Sidney Amani <[email protected]>
UBIFS leaks memory on error path in 'mount_ubifs()'. In case of failure in 'ubifs_fixup_free_space()', it does not call 'ubifs_lpt_free()' whereas LPT data structures can potentially be allocated. The amount of memory leaked can be quite high -- see 'ubifs_lpt_init()'.
The bug was introduced when moving the LPT initialisation earlier in the mount process (commit '781c5717a95a74b294beb38b8276943b0f8b5bb4').
--- fs/ubifs/super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ubifs/super.c +1 -1
@@ -1301,7 +1301,7 @@ static int mount_ubifs(struct ubifs_info *c)if (!c->ro_mount && c->space_fixup) { err =ubifs_fixup_free_space (c);if (err) - goto out_master; + goto out_lpt; }if (!c->ro_mount) {
Signature · 1 line
1.7.10
Quoted 10 lines · Sidney Amani
UBIFS leaks memory on error path in '
mount_ubifs()'. In case of failure in 'ubifs_lpt_init()' or 'ubifs_fixup_free_space()', it does not call 'ubifs_lpt_free()' whereas LPT data structures can potentially be allocated. The amount of memory leaked can be quite high -- see 'ubifs_lpt_init()'.The bug was introduced when moving the LPT initialisation earlier in the mount process (commit '
781c5717a95a74b294beb38b8276943b0f8b5bb4').CC Ben Gardiner <[email protected]>Signed-off-by Sidney Amani <[email protected]>
I've replied to you with the counter-proposal patches which I think should fix this issue in a bit better way. Please, take a look - If you are fine with that, I can push it.
Signature · 2 lines
Best Regards, Artem Bityutskiy
Re: [PATCH 1/2] UBIFS: make ubifs_lpt_init clean-up in case of failure
In reply to Artem BityutskiyQuoted 8 lines · Artem Bityutskiy
From: Artem Bityutskiy <[email protected]>
Most functions in UBIFS follow the following designn pattern: if the function allocates multiple resources, and failss at some point, it frees what it has allocated and returns an error. So the caller can rely on the fact that the callee has cleaned up everything after own failure.
Signed-off-by Artem Bityutskiy <[email protected]>
Signature · 1 line
Sidney
Quoted 4 lines · Artem Bityutskiy
I've replied to you with the counter-proposal patches which I think should fix this issue in a bit better way. Please, take a look - If you are fine with that, I can push it.
Agreed, your set of patches is better.
Cheers
Signature · 1 line
Sidney