]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
ubifs: ubifs_add_orphan: Fix a memory leak bug
authorZhihao Cheng <chengzhihao1@huawei.com>
Tue, 3 Mar 2020 09:40:23 +0000 (17:40 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 1 Oct 2020 11:17:51 +0000 (13:17 +0200)
[ Upstream commit 927cc5cec35f01fe4f8af0ba80830a90b0533983 ]

Memory leak occurs when files with extended attributes are added to
orphan list.

Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Fixes: 988bec41318f3fa897e2f8 ("ubifs: orphan: Handle xattrs like files")
Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/ubifs/orphan.c

index 7dd740e3692daf0a6db5c8014c67bd6d984781ac..283f9eb48410d9d8aeb9f07979ea89eebb825aab 100644 (file)
@@ -157,7 +157,7 @@ int ubifs_add_orphan(struct ubifs_info *c, ino_t inum)
        int err = 0;
        ino_t xattr_inum;
        union ubifs_key key;
-       struct ubifs_dent_node *xent;
+       struct ubifs_dent_node *xent, *pxent = NULL;
        struct fscrypt_name nm = {0};
        struct ubifs_orphan *xattr_orphan;
        struct ubifs_orphan *orphan;
@@ -181,11 +181,16 @@ int ubifs_add_orphan(struct ubifs_info *c, ino_t inum)
                xattr_inum = le64_to_cpu(xent->inum);
 
                xattr_orphan = orphan_add(c, xattr_inum, orphan);
-               if (IS_ERR(xattr_orphan))
+               if (IS_ERR(xattr_orphan)) {
+                       kfree(xent);
                        return PTR_ERR(xattr_orphan);
+               }
 
+               kfree(pxent);
+               pxent = xent;
                key_read(c, &xent->key, &key);
        }
+       kfree(pxent);
 
        return 0;
 }