hfsplus: fix uninit-value in hfsplus_strcasecmp
Subsystems (2)
PATCH v2 1/1 hfsplus: fix uninit-value in hfsplus_strcasecmp
Syzbot reported a KMSAN uninit-value issue in hfsplus_strcasecmp() during filesystem mount operations. The root cause is that hfsplus_find_cat() declares a local hfsplus_cat_entry variable without initialization before passing it to hfs_brec_read().
When the filesystem image is corrupted or malformed (as syzbot fuzzes), hfs_brec_read() may read less data than sizeof(hfsplus_cat_entry). In such cases, the tmp.thread.nodeName.unicode array may only be partially filled, leaving remaining bytes uninitialized.
hfsplus_cat_build_key_uni() then copies from this array based on nodeName.length. If the on-disk length field is corrupted or the array wasn't fully written by hfs_brec_read(), uninitialized stack data gets copied into the search key. When hfsplus_strcasecmp() subsequently reads these uninitialized bytes and uses them in case_fold() as an array index into hfsplus_case_fold_table, KMSAN detects the use of uninitialized values.
Fix this by initializing tmp to zero, ensuring that even with corrupted filesystem images, no uninitialized data is propagated.
---
Changes in v2:
- Use structure initialization (= {0}) instead of memset() as suggested by Viacheslav Dubeyko
- Improved commit message to clarify how uninitialized data is used
--- fs/hfsplus/catalog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/hfsplus/catalog.c +1 -1
@@ -194,7 +194,7 @@ static int hfsplus_fill_cat_thread(struct super_block *sb,int hfsplus_find_cat (struct super_block *sb,u32 cnid,struct hfs_find_data *fd) { -hfsplus_cat_entry tmp; +hfsplus_cat_entry tmp = {0 };int err;u16 type;
Signature · 1 line
2.43.0
Quoted 9 lines · Deepanshu Kartikey
Syzbot reported a KMSAN uninit-value issue in
hfsplus_strcasecmp()during filesystem mount operations. The root cause is thathfsplus_find_cat()declares a localhfsplus_cat_entryvariable without initialization before passing it tohfs_brec_read().When the filesystem image is corrupted or malformed (as syzbot fuzzes),
hfs_brec_read()may read less data thansizeof(hfsplus_cat_entry). In such cases, the tmp.thread.nodeName.unicode array may only be partially filled, leaving remaining bytes uninitialized.
I still don't understand this point. Please, see my questions in the thread for v1 of the patch. Could you please address my questions/worries?
Thanks,
Slava.
Quoted 39 lines
hfsplus_cat_build_key_uni()then copies from this array based on nodeName.length. If the on-disk length field is corrupted or the array wasn't fully written byhfs_brec_read(), uninitialized stack data gets copied into the search key. Whenhfsplus_strcasecmp()subsequently reads these uninitialized bytes and uses them incase_fold()as an array index intohfsplus_case_fold_table, KMSAN detects the use of uninitialized values.Fix this by initializing tmp to zero, ensuring that even with corrupted filesystem images, no uninitialized data is propagated.
Reported-by [email protected]Tested-by [email protected]Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")Signed-off-by Deepanshu Kartikey <[email protected]>---
Changes in v2:
- Use structure initialization (= {0}) instead ofmemset()as suggested by Viacheslav Dubeyko
- Improved commit message to clarify how uninitialized data is used--- fs/hfsplus/catalog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/hfsplus/catalog.c +1
-1@@ -194,7 +194,7 @@ static int hfsplus_fill_cat_thread(struct super_block *sb,int hfsplus_find_cat (struct super_block *sb,u32 cnid,struct hfs_find_data *fd) { -hfsplus_cat_entry tmp; +hfsplus_cat_entry tmp = {0 };int err;u16 type;