Skip to contentSkip to conversation

udf: Fix two syzbot reports

PATCH New Jan Kara 1 participant 4 messages Jun 17, 2024

Subsystems (3)
lore
Share & tools
lore

Jan Kara

author reviewer
#0 lore raw

cover 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

author reviewer
#1 lore raw

PATCH 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.

Fixes e9109a92d2a9 ("udf: Convert udf_rename() to new directory iteration code")
Reported-by [email protected]
---
 fs/udf/namei.c | 2 --
 1 file changed, 2 deletions(-)
fs/udf/namei.c +0 -2
index 1308109fd42d..78a603129dd5 100644
@@ -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
author reviewer
#2 lore raw

PATCH 2/3 udf: Avoid using corrupted block bitmap buffer

In reply to Jan Kara

When 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.

Reported-by [email protected]
Fixes 1e0d4adf17e7 ("udf: Check consistency of Space Bitmap Descriptor")
---
 fs/udf/balloc.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
fs/udf/balloc.c +13 -2
index ab3ffc355949..558ad046972a 100644
@@ -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
author reviewer
#3 lore raw

PATCH 3/3 udf: Drop load_block_bitmap() wrapper

In reply to Jan Kara

The 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
index 558ad046972a..a76490b2ca19 100644
@@ -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