Skip to contentSkip to conversation

ext4: Fix possible use after free of buffer head

PATCH Applied Lukas Czerner 3 participants 3 messages Nov 29, 2012 – Nov 30, 2012 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: Fix possible use after free of buffer head

Commit fa77dcfafeaa6bc73293c646bfc3d5192dcf0be2 introduces block bitmap checksum calculation into ext4_new_inode() in the case that block group was uninitialized. However we brelse() the bitmap buffer before we attempt to checksum it so we have no guarantee that the buffer is still there.

Fix this by releasing the buffer after the possible checksum computation.

---
 fs/ext4/ialloc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/ext4/ialloc.c +1 -1
index 3a100e7..c7efa88 100644
@@ -762,7 +762,6 @@ got:
 
 		BUFFER_TRACE(block_bitmap_bh, "dirty block bitmap");
 		err = ext4_handle_dirty_metadata(handle, NULL, block_bitmap_bh);
-		brelse(block_bitmap_bh);
 
 		/* recheck and clear flag under lock if we still need to */
 		ext4_lock_group(sb, group);
@@ -775,6 +774,7 @@ got:
 			ext4_group_desc_csum_set(sb, group, gdp);
 		}
 		ext4_unlock_group(sb, group);
+		brelse(block_bitmap_bh);
 
 		if (err)
 			goto fail;
Signature · 1 line
1.7.7.6
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Lukas Czerner

Commit fa77dcfafeaa6bc73293c646bfc3d5192dcf0be2 introduces block bitmap checksum calculation into ext4_new_inode() in the case that block group was uninitialized. However we brelse() the bitmap buffer before we attempt to checksum it so we have no guarantee that the buffer is still there.

Fix this by releasing the buffer after the possible checksum computation.

Looks ok, so:

That IBM fellow is gone. ;)

--D

Quoted 35 lines
---
 fs/ext4/ialloc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/ext4/ialloc.c +1 -1
index 3a100e7..c7efa88 100644
@@ -762,7 +762,6 @@ got:
 
 		BUFFER_TRACE(block_bitmap_bh, "dirty block bitmap");
 		err = ext4_handle_dirty_metadata(handle, NULL, block_bitmap_bh);
-		brelse(block_bitmap_bh);
 
 		/* recheck and clear flag under lock if we still need to */
 		ext4_lock_group(sb, group);
@@ -775,6 +774,7 @@ got:
 			ext4_group_desc_csum_set(sb, group, gdp);
 		}
 		ext4_unlock_group(sb, group);
+		brelse(block_bitmap_bh);
 
 		if (err)
 			goto fail;
Signature · 6 lines
1.7.7.6

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
maintainer Applied
#2 lore raw
Quoted 7 lines · Darrick J. Wong
Quoted 6 lines · Lukas Czerner

Commit fa77dcfafeaa6bc73293c646bfc3d5192dcf0be2 introduces block bitmap checksum calculation into ext4_new_inode() in the case that block group was uninitialized. However we brelse() the bitmap buffer before we attempt to checksum it so we have no guarantee that the buffer is still there.

Quoted 5 lines
Quoted 2 lines

Fix this by releasing the buffer after the possible checksum computation.

Looks ok, so:

Applied, thanks.

- Ted