btrfs: fix uninitialized pointer free in add_inode_ref()
authorRoi Martin <jroi.martin@gmail.com>
Wed, 9 Oct 2024 08:08:33 +0000 (10:08 +0200)
committerDavid Sterba <dsterba@suse.com>
Fri, 11 Oct 2024 17:54:52 +0000 (19:54 +0200)
The add_inode_ref() function does not initialize the "name" struct when
it is declared.  If any of the following calls to "read_one_inode()
returns NULL,

dir = read_one_inode(root, parent_objectid);
if (!dir) {
ret = -ENOENT;
goto out;
}

inode = read_one_inode(root, inode_objectid);
if (!inode) {
ret = -EIO;
goto out;
}

then "name.name" would be freed on "out" before being initialized.

out:
...
kfree(name.name);

This issue was reported by Coverity with CID 1526744.

Fixes: e43eec81c516 ("btrfs: use struct qstr instead of name and namelen pairs")
CC: stable@vger.kernel.org # 6.6+
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Roi Martin <jroi.martin@gmail.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/tree-log.c

index e2ed2a791f8f0327ac7dfad046dab223eb4630ea..35c452bab1cab3be0a0970cd50822a48c4f22401 100644 (file)
@@ -1374,7 +1374,7 @@ static noinline int add_inode_ref(struct btrfs_trans_handle *trans,
        struct inode *inode = NULL;
        unsigned long ref_ptr;
        unsigned long ref_end;
-       struct fscrypt_str name;
+       struct fscrypt_str name = { 0 };
        int ret;
        int log_ref_ver = 0;
        u64 parent_objectid;