Skip to contentSkip to conversation

fs/btrfs: Zero file data not backed by extents

PATCH In review Fabian Vogt 3 participants 3 messages Oct 5, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/btrfs: Zero file data not backed by extents

Implicit holes in file data need to be zeroed explicitly, instead of just leaving the data in the buffer uninitialized.

This led to kernels randomly failing to boot in "fun" ways when loaded from btrfs with the no_holes feature enabled, because large blocks of zeros in the kernel file contained random data instead.

---
 grub-core/fs/btrfs.c | 2 ++
 1 file changed, 2 insertions(+)
grub-core/fs/btrfs.c +2 -0
index 19bff4610..ba0c58352 100644
@@ -1603,6 +1603,8 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data,
 	      csize = grub_le_to_cpu64 (key_out.offset) - pos;
 	      if (csize > len)
 		      csize = len;
+
+	      grub_memset (buf, 0, csize);
 	      buf += csize;
 	      pos += csize;
 	      len -= csize;
Signature · 10 lines
2.42.0





_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Fabian Vogt

Implicit holes in file data need to be zeroed explicitly, instead of just leaving the data in the buffer uninitialized.

This led to kernels randomly failing to boot in "fun" ways when loaded from btrfs with the no_holes feature enabled, because large blocks of zeros in the kernel file contained random data instead.

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Reviewed-by on v1 1/1
#2 lore raw
In reply to Fabian Vogt
Quoted 8 lines · Fabian Vogt

Implicit holes in file data need to be zeroed explicitly, instead of just leaving the data in the buffer uninitialized.

This led to kernels randomly failing to boot in "fun" ways when loaded from btrfs with the no_holes feature enabled, because large blocks of zeros in the kernel file contained random data instead.

Thanks,
Qu

Quoted 9 lines
---
  grub-core/fs/btrfs.c | 2 ++
  1 file changed, 2 insertions(+)
grub-core/fs/btrfs.c +0 -0
index 19bff4610..ba0c58352 100644

grub-core/fs/btrfs.c grub_btrfs_extent_read (struct grub_btrfs_data *data, · line 1610

Quoted 8 lines
grub-core/fs/btrfs.c +2 -0
@@ -1603,6 +1603,8 @@ grub_btrfs_extent_read (struct grub_btrfs_data *data,
  	      csize = grub_le_to_cpu64 (key_out.offset) - pos;
  	      if (csize > len)
  		      csize = len;
+
+	      grub_memset (buf, 0, csize);
  	      buf += csize;
  	      pos += csize;
  	      len -= csize;

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel