udf: Fix two syzbot reports
Subsystems (3)
Jan Kara
reviewercover udf: Fix two syzbot reports
Hello,
these patches fix two issues syzbot found when fuzzing udf filesystem images. I plan to merge these fixes through my tree.
Honza
Jan Kara
reviewerPATCH 1/3 udf: Fix bogus checksum computation in udf_rename()
Syzbot reports uninitialized memory access in udf_rename() when updating checksum of '..' directory entry of a moved directory. This is indeed true as we pass on-stack diriter.fi to the udf_update_tag() and because that has only struct fileIdentDesc included in it and not the impUse or name fields, the checksumming function is going to checksum random stack contents beyond the end of the structure. This is actually harmless because the following udf_fiiter_write_fi() will recompute the checksum from on-disk buffers where everything is properly included. So all that is needed is just removing the bogus calculation.
--- fs/udf/namei.c | 2 -- 1 file changed, 2 deletions(-)
fs/udf/namei.c +0 -2
@@ -876,8 +876,6 @@ static int udf_rename(struct mnt_idmap *idmap, struct inode *old_dir,if (has_diriter) { diriter.fi.icb.extLocation =cpu_to_lelb (UDF_I (new_dir)->i_location); -udf_update_tag ((char *)&diriter.fi, -udf_dir_entry_len (&diriter.fi));udf_fiiter_write_fi (&diriter,NULL );udf_fiiter_release (&diriter); }
Signature · 1 line
2.35.3
Jan Kara
reviewerPATCH 2/3 udf: Avoid using corrupted block bitmap buffer
In reply to Jan KaraWhen the filesystem block bitmap is corrupted, we detect the corruption while loading the bitmap and fail the allocation with error. However the next allocation from the same bitmap will notice the bitmap buffer is already loaded and tries to allocate from the bitmap with mixed results (depending on the exact nature of the bitmap corruption). Fix the problem by using BH_verified bit to indicate whether the bitmap is valid or not.
--- fs/udf/balloc.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
fs/udf/balloc.c +13 -2
@@ -64,8 +64,12 @@ static int read_block_bitmap(struct super_block *sb, }for (i =0 ; i < count; i++) -if (udf_test_bit (i + off, bh->b_data)) +if (udf_test_bit (i + off, bh->b_data)) { + bitmap->s_block_bitmap[bitmap_nr] = +ERR_PTR (-EFSCORRUPTED ); +brelse (bh);return -EFSCORRUPTED ; + }return 0 ; }
@@ -81,8 +85,15 @@ static int __load_block_bitmap(struct super_block *sb, block_group, nr_groups); } -if (bitmap->s_block_bitmap[block_group]) +if (bitmap->s_block_bitmap[block_group]) { +/* +* The bitmap failed verification in the past. No point in +* trying again. +*/ +if (IS_ERR (bitmap->s_block_bitmap[block_group])) +return PTR_ERR (bitmap->s_block_bitmap[block_group]);return block_group; + } retval =read_block_bitmap (sb, bitmap, block_group, block_group);if (retval <0 )
Signature · 1 line
2.35.3
Jan Kara
reviewerPATCH 3/3 udf: Drop load_block_bitmap() wrapper
In reply to Jan KaraThe wrapper is completely pointless as all the checks are already done in __load_block_bitmap(). Just drop it and rename __load_block_bitmap().
--- fs/udf/balloc.c | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-)
fs/udf/balloc.c +3 -20
@@ -73,9 +73,9 @@ static int read_block_bitmap(struct super_block *sb,return 0 ; } -static int __load_block_bitmap (struct super_block *sb, -struct udf_bitmap *bitmap, -unsigned int block_group) +static int load_block_bitmap (struct super_block *sb, +struct udf_bitmap *bitmap, +unsigned int block_group) {int retval =0 ;int nr_groups = bitmap->s_nr_groups;
@@ -102,23 +102,6 @@ static int __load_block_bitmap(struct super_block *sb,return block_group; } -static inline int load_block_bitmap (struct super_block *sb, -struct udf_bitmap *bitmap, -unsigned int block_group) -{ -int slot; - - slot =__load_block_bitmap (sb, bitmap, block_group); - -if (slot <0 ) -return slot; - -if (!bitmap->s_block_bitmap[slot]) -return -EIO ; - -return slot; -} -static void udf_add_free_space (struct super_block *sb,u16 partition,u32 cnt) {struct udf_sb_info *sbi =UDF_SB (sb);
Signature · 1 line
2.35.3