Skip to contentSkip to conversation

btrfs: fix uninit pointer free on read_alloc_one_name error

PATCH In review Roi Martin 3 participants 3 messages Oct 10, 2024 – Oct 11, 2024 Btrfs file system

lore
Share & tools
lore

Roi Martin

author
#0 lore raw

PATCH 1/1 btrfs: fix uninit pointer free on read_alloc_one_name error

The read_alloc_one_name function does not initialize the name field of the passed fscrypt_str struct if kmalloc fails to allocate the corresponding buffer. Thus, it is not guaranteed that fscrypt_str.name is initialized when freeing it.

This is a follow-up to the linked patch that fixes the remaining instances of the bug introduced by commit e43eec81c516 ("btrfs: use struct qstr instead of name and namelen pairs").

Fixes e43eec81c516 ("btrfs: use struct qstr instead of name and namelen pairs")
---
 fs/btrfs/tree-log.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/tree-log.c +2 -2
index e2ed2a791f8f..d2e5781701f9 100644
@@ -1845,7 +1845,7 @@ static noinline int replay_one_name(struct btrfs_trans_handle *trans,
 				    struct btrfs_dir_item *di,
 				    struct btrfs_key *key)
 {
-	struct fscrypt_str name;
+	struct fscrypt_str name = { 0 };
 	struct btrfs_dir_item *dir_dst_di;
 	struct btrfs_dir_item *index_dst_di;
 	bool dir_dst_matches = false;
@@ -2125,7 +2125,7 @@ static noinline int check_item_in_log(struct btrfs_trans_handle *trans,
 	struct extent_buffer *eb;
 	int slot;
 	struct btrfs_dir_item *di;
-	struct fscrypt_str name;
+	struct fscrypt_str name = { 0 };
 	struct inode *inode = NULL;
 	struct btrfs_key location;
 

base-commit: eb952c47d154ba2aac794b99c66c3c45eb4cc4ec

Signature · 1 line
2.46.0
#2 lore raw
In reply to Roi Martin
Quoted 5 lines · Roi Martin

The read_alloc_one_name function does not initialize the name field of the passed fscrypt_str struct if kmalloc fails to allocate the corresponding buffer. Thus, it is not guaranteed that fscrypt_str.name is initialized when freeing it.

Quoted 7 lines

This is a follow-up to the linked patch that fixes the remaining instances of the bug introduced by commit e43eec81c516 ("btrfs: use struct qstr instead of name and namelen pairs").

Fixes e43eec81c516 ("btrfs: use struct qstr instead of name and namelen pairs")

Added to for-next, thanks.