]> git.baikalelectronics.ru Git - kernel.git/commit
ubifs: dirty_cow_znode: Fix memleak in error handling path
authorZhihao Cheng <chengzhihao1@huawei.com>
Fri, 18 Nov 2022 09:02:36 +0000 (17:02 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 11 Mar 2023 15:44:10 +0000 (16:44 +0100)
commitf85401f2f66bfe2c2e34b745d496612bcce0febf
treee422856a6998f1414c65fe0e150c52d69d4ee8c1
parente1d04e7a51e1fe40be35d7076cac81101ddbbba5
ubifs: dirty_cow_znode: Fix memleak in error handling path

[ Upstream commit 122deabfe1428bffe95e2bf364ff8a5059bdf089 ]

Following process will cause a memleak for copied up znode:

dirty_cow_znode
  zn = copy_znode(c, znode);
  err = insert_old_idx(c, zbr->lnum, zbr->offs);
  if (unlikely(err))
     return ERR_PTR(err);   // No one refers to zn.

Fix it by adding copied znode back to tnc, then it will be freed
by ubifs_destroy_tnc_subtree() while closing tnc.

Fetch a reproducer in [Link].

Link: https://bugzilla.kernel.org/show_bug.cgi?id=216705
Fixes: 974763da840d ("UBIFS: add new flash file system")
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/ubifs/tnc.c