btrfs: fix uninitialized pointer free on add_inode_ref
PATCH 1/1 btrfs: fix uninitialized pointer free on add_inode_ref
The "add_inode_ref" function does not initializes 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.
--- fs/btrfs/tree-log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/tree-log.c +1 -1
@@ -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;
base-commit: 75b607fab38d149f232f01eae5e6392b394dd659
Signature · 1 line
2.46.0
Quoted 19 lines · Roi Martin
The "
add_inode_ref" function does not initializes 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.
Quoted 7 lines
out:
... kfree(name.name);This issue was reported by Coverity with CID 1526744.
Signed-off-by Roi Martin <[email protected]>
namelen pairs")
Looks good, thanks.
Quoted 23 lines
--- fs/btrfs/tree-log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/btrfs/tree-log.c +1
-1@@ -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;base-commit:
75b607fab38d149f232f01eae5e6392b394dd659--
2.46.0
Quoted 18 lines · Roi Martin
The "
add_inode_ref" function does not initializes 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.
Quoted 7 lines
out:
... kfree(name.name);This issue was reported by Coverity with CID 1526744.
Signed-off-by Roi Martin <[email protected]>
Added to for-next, thanks.