Skip to contentSkip to conversation

udf: don't call mark_buffer_dirty on a null bh pointer

PATCH In review Colin King 3 participants 5 messages Feb 19, 2019 – Feb 20, 2019

Subsystems (2)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 udf: don't call mark_buffer_dirty on a null bh pointer

From: Colin Ian King <[email protected]>

There is a null check on the pointer bh to avoid a null pointer dereference on bh->b_data however later bh is passed to mark_buffer_dirty that can also cause a null pointer dereference on bh. Avoid this potential null pointer dereference by moving the call to mark_buffer_dirty inside the null checked block.

Fixes e8b4274735e4 ("udf: finalize integrity descriptor before writeback")
---
 fs/udf/super.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
fs/udf/super.c +6 -6
index a6940d90bedd..b7e9a83d39db 100644
@@ -2336,13 +2336,13 @@ static int udf_sync_fs(struct super_block *sb, int wait)
 
 			lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
 			udf_finalize_lvid(lvid);
-		}
 
-		/*
-		 * Blockdevice will be synced later so we don't have to submit
-		 * the buffer for IO
-		 */
-		mark_buffer_dirty(bh);
+			/*
+			 * Blockdevice will be synced later so we don't have
+			 * to submit the buffer for IO
+			 */
+			mark_buffer_dirty(bh);
+		}
 		sbi->s_lvid_dirty = 0;
 	}
 	mutex_unlock(&sbi->s_alloc_mutex);
Signature · 1 line
2.20.1
#1 lore raw
Quoted 10 lines · Colin King

From: Colin Ian King <[email protected]>

There is a null check on the pointer bh to avoid a null pointer dereference on bh->b_data however later bh is passed to mark_buffer_dirty that can also cause a null pointer dereference on bh. Avoid this potential null pointer dereference by moving the call to mark_buffer_dirty inside the null checked block.

Fixes e8b4274735e4 ("udf: finalize integrity descriptor before writeback")

Thanks for the patch! In fact it is the 'if (bh)' check that's unnecessarily defensive (we cannot have sbi->s_lvid_dirty and !sbi->s_lvid_bh). So I'll just drop that check (attached patch).

Honza

Quoted 32 lines
---
 fs/udf/super.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
fs/udf/super.c +6 -6
index a6940d90bedd..b7e9a83d39db 100644
@@ -2336,13 +2336,13 @@ static int udf_sync_fs(struct super_block *sb, int wait)
 
 			lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
 			udf_finalize_lvid(lvid);
-		}
 
-		/*
-		 * Blockdevice will be synced later so we don't have to submit
-		 * the buffer for IO
-		 */
-		mark_buffer_dirty(bh);
+			/*
+			 * Blockdevice will be synced later so we don't have
+			 * to submit the buffer for IO
+			 */
+			mark_buffer_dirty(bh);
+		}
 		sbi->s_lvid_dirty = 0;
 	}
 	mutex_unlock(&sbi->s_alloc_mutex);
Signature · 1 line
2.20.1
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR

From a00eb52e3f2f815efa52a9e3bf1b730d86c05faa Mon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Tue, 19 Feb 2019 14:59:43 +0100
Subject: [PATCH] udf: Drop pointless check from udf_sync_fs()

The check if (bh) in udf_sync_fs() is pointless as we cannot have sbi->s_lvid_dirty and !sbi->s_lvid_bh (as already asserted by udf_updated_lvid()). So just drop the pointless check.

---
 fs/udf/super.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
fs/udf/super.c +3 -6
index a6940d90bedd..ffd8038ff728 100644
@@ -2330,13 +2330,10 @@ static int udf_sync_fs(struct super_block *sb, int wait)
 	mutex_lock(&sbi->s_alloc_mutex);
 	if (sbi->s_lvid_dirty) {
 		struct buffer_head *bh = sbi->s_lvid_bh;
+		struct logicalVolIntegrityDesc *lvid;
 
-		if (bh) {
-			struct logicalVolIntegrityDesc *lvid;
-
-			lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
-			udf_finalize_lvid(lvid);
-		}
+		lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
+		udf_finalize_lvid(lvid);
 
 		/*
 		 * Blockdevice will be synced later so we don't have to submit
Signature · 1 line
2.16.4
Reviewed-by Steven J. Magnani
#2 lore raw
Quoted 40 lines · Jan Kara
Quoted 10 lines · Colin King

From: Colin Ian King <[email protected]>

There is a null check on the pointer bh to avoid a null pointer dereference on bh->b_data however later bh is passed to mark_buffer_dirty that can also cause a null pointer dereference on bh. Avoid this potential null pointer dereference by moving the call to mark_buffer_dirty inside the null checked block.

Fixes e8b4274735e4 ("udf: finalize integrity descriptor before writeback")

Thanks for the patch! In fact it is the 'if (bh)' check that's unnecessarily defensive (we cannot have sbi->s_lvid_dirty and !sbi->s_lvid_bh). So I'll just drop that check (attached patch).

Honza

Quoted 23 lines
---
  fs/udf/super.c | 12 ++++++------
  1 file changed, 6 insertions(+), 6 deletions(-)
fs/udf/super.c +4 -6
index a6940d90bedd..b7e9a83d39db 100644
@@ -2336,13 +2336,13 @@ static int udf_sync_fs(struct super_block *sb, int wait)
 
  			lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
  			udf_finalize_lvid(lvid);
-		}
 
-		/*
-		 * Blockdevice will be synced later so we don't have to submit
-		 * the buffer for IO
-		 */
-		mark_buffer_dirty(bh);
+			/*
+			 * Blockdevice will be synced later so we don't have
+			 * to submit the buffer for IO
+			 */
Quoted 8 lines
Quoted 8 lines
fs/udf/super.c +2 -0
+			mark_buffer_dirty(bh);
+		}
  		sbi->s_lvid_dirty = 0;
  	}
  	mutex_unlock(&sbi->s_alloc_mutex);
Signature · 1 line
2.20.1

Doh! Thanks for the catch Colin.

------------------------------------------------------------------------
 Steven J. Magnani               "I claim this network for MARS! www.digidescorp.com              Earthling, return my space modulator!"

 #include <standard.disclaimer>

#3 lore raw
Quoted 40 lines · Steve Magnani
Quoted 39 lines · Jan Kara
Quoted 10 lines · Colin King

From: Colin Ian King <[email protected]>

There is a null check on the pointer bh to avoid a null pointer dereference on bh->b_data however later bh is passed to mark_buffer_dirty that can also cause a null pointer dereference on bh. Avoid this potential null pointer dereference by moving the call to mark_buffer_dirty inside the null checked block.

Fixes e8b4274735e4 ("udf: finalize integrity descriptor before writeback")

Thanks for the patch! In fact it is the 'if (bh)' check that's unnecessarily defensive (we cannot have sbi->s_lvid_dirty and !sbi->s_lvid_bh). So I'll just drop that check (attached patch).

Honza

Quoted 22 lines
---
  fs/udf/super.c | 12 ++++++------
  1 file changed, 6 insertions(+), 6 deletions(-)
fs/udf/super.c +5 -6
index a6940d90bedd..b7e9a83d39db 100644
@@ -2336,13 +2336,13 @@ static int udf_sync_fs(struct super_block *sb, int wait)
  			lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
  			udf_finalize_lvid(lvid);
-		}
-		/*
-		 * Blockdevice will be synced later so we don't have to submit
-		 * the buffer for IO
-		 */
-		mark_buffer_dirty(bh);
+			/*
+			 * Blockdevice will be synced later so we don't have
+			 * to submit the buffer for IO
+			 */
+			mark_buffer_dirty(bh);
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
fs/udf/super.c +1 -0
+		}
  		sbi->s_lvid_dirty = 0;
  	}
  	mutex_unlock(&sbi->s_alloc_mutex);
Signature · 1 line
2.20.1

Is this Reviewed-by for my fixup or the Colin's? Because I've decided to rather remove the 'if (bh)' check completely since it is pointless...

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#4 lore raw
Quoted 53 lines · Jan Kara
Quoted 42 lines · Steve Magnani
Quoted 40 lines · Jan Kara
Quoted 11 lines · Colin King

From: Colin Ian King <[email protected]>

There is a null check on the pointer bh to avoid a null pointer dereference on bh->b_data however later bh is passed to mark_buffer_dirty that can also cause a null pointer dereference on bh. Avoid this potential null pointer dereference by moving the call to mark_buffer_dirty inside the null checked block.

Fixes e8b4274735e4 ("udf: finalize integrity descriptor before writeback")

Thanks for the patch! In fact it is the 'if (bh)' check that's unnecessarily defensive (we cannot have sbi->s_lvid_dirty and !sbi->s_lvid_bh). So I'll just drop that check (attached patch).

Honza

Quoted 22 lines
---
 fs/udf/super.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
fs/udf/super.c +5 -6
index a6940d90bedd..b7e9a83d39db 100644
@@ -2336,13 +2336,13 @@ static int udf_sync_fs(struct super_block *sb, int wait)
             lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
             udf_finalize_lvid(lvid);
-        }
-        /*
-         * Blockdevice will be synced later so we don't have to submit
-         * the buffer for IO
-         */
-        mark_buffer_dirty(bh);
+            /*
+             * Blockdevice will be synced later so we don't have
+             * to submit the buffer for IO
+             */
+            mark_buffer_dirty(bh);
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
fs/udf/super.c +1 -0
+        }
         sbi->s_lvid_dirty = 0;
     }
     mutex_unlock(&sbi->s_alloc_mutex);
Signature · 1 line
2.20.1
Quoted 5 lines

Is this Reviewed-by for my fixup or the Colin's? Because I've decided to rather remove the 'if (bh)' check completely since it is pointless...

Honza

Sorry, I realized on rereading that this could be ambiguous. The R-B is for your patch.

Steve