Skip to content

Commit 10256f0

Browse files
Zhihao Chengrichardweinberger
authored andcommitted
ubifs: do_kill_orphans: Fix a memory leak bug
If there are more than one valid snod on the sleb->nodes list, do_kill_orphans will malloc ino more than once without releasing previous ino's memory. Finally, it will trigger memory leak. Fixes: ee1438c ("ubifs: Check link count of inodes when...") Signed-off-by: Zhihao Cheng <[email protected]> Signed-off-by: zhangyi (F) <[email protected]> Signed-off-by: Richard Weinberger <[email protected]>
1 parent 91cbf01 commit 10256f0

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

fs/ubifs/orphan.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -631,12 +631,17 @@ static int do_kill_orphans(struct ubifs_info *c, struct ubifs_scan_leb *sleb,
631631
ino_t inum;
632632
int i, n, err, first = 1;
633633

634+
ino = kmalloc(UBIFS_MAX_INO_NODE_SZ, GFP_NOFS);
635+
if (!ino)
636+
return -ENOMEM;
637+
634638
list_for_each_entry(snod, &sleb->nodes, list) {
635639
if (snod->type != UBIFS_ORPH_NODE) {
636640
ubifs_err(c, "invalid node type %d in orphan area at %d:%d",
637641
snod->type, sleb->lnum, snod->offs);
638642
ubifs_dump_node(c, snod->node);
639-
return -EINVAL;
643+
err = -EINVAL;
644+
goto out_free;
640645
}
641646

642647
orph = snod->node;
@@ -663,20 +668,18 @@ static int do_kill_orphans(struct ubifs_info *c, struct ubifs_scan_leb *sleb,
663668
ubifs_err(c, "out of order commit number %llu in orphan node at %d:%d",
664669
cmt_no, sleb->lnum, snod->offs);
665670
ubifs_dump_node(c, snod->node);
666-
return -EINVAL;
671+
err = -EINVAL;
672+
goto out_free;
667673
}
668674
dbg_rcvry("out of date LEB %d", sleb->lnum);
669675
*outofdate = 1;
670-
return 0;
676+
err = 0;
677+
goto out_free;
671678
}
672679

673680
if (first)
674681
first = 0;
675682

676-
ino = kmalloc(UBIFS_MAX_INO_NODE_SZ, GFP_NOFS);
677-
if (!ino)
678-
return -ENOMEM;
679-
680683
n = (le32_to_cpu(orph->ch.len) - UBIFS_ORPH_NODE_SZ) >> 3;
681684
for (i = 0; i < n; i++) {
682685
union ubifs_key key1, key2;

0 commit comments

Comments
 (0)