Skip to content

Commit f4a04c9

Browse files
vwaxrichardweinberger
authored andcommitted
ubifs: Fix memory leak of bud->log_hash
Ensure that the allocated bud->log_hash (if any) is freed in all cases when the bud itself is freed, to fix this leak caught by kmemleak: # keyctl add logon foo:bar data @s # echo clear > /sys/kernel/debug/kmemleak # mount -t ubifs /dev/ubi0_0 mnt -o auth_hash_name=sha256,auth_key=foo:bar # echo a > mnt/x # umount mnt # mount -t ubifs /dev/ubi0_0 mnt -o auth_hash_name=sha256,auth_key=foo:bar # umount mnt # sleep 5 # echo scan > /sys/kernel/debug/kmemleak # echo scan > /sys/kernel/debug/kmemleak # cat /sys/kernel/debug/kmemleak unreferenced object 0xff... (size 128): comm "mount" backtrace: __kmalloc __ubifs_hash_get_desc+0x5d/0xe0 ubifs ubifs_replay_journal ubifs_mount ... Fixes: da8ef65 ("ubifs: Authenticate replayed journal") Signed-off-by: Vincent Whitchurch <[email protected]> Reviewed-by: Zhihao Cheng <[email protected]> Signed-off-by: Richard Weinberger <[email protected]>
1 parent 48ec632 commit f4a04c9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

fs/ubifs/super.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,8 +923,10 @@ static void free_buds(struct ubifs_info *c)
923923
{
924924
struct ubifs_bud *bud, *n;
925925

926-
rbtree_postorder_for_each_entry_safe(bud, n, &c->buds, rb)
926+
rbtree_postorder_for_each_entry_safe(bud, n, &c->buds, rb) {
927+
kfree(bud->log_hash);
927928
kfree(bud);
929+
}
928930
}
929931

930932
/**
@@ -1193,6 +1195,7 @@ static void destroy_journal(struct ubifs_info *c)
11931195

11941196
bud = list_entry(c->old_buds.next, struct ubifs_bud, list);
11951197
list_del(&bud->list);
1198+
kfree(bud->log_hash);
11961199
kfree(bud);
11971200
}
11981201
ubifs_destroy_idx_gc(c);

0 commit comments

Comments
 (0)