diff mbox series

[1/3] btrfs-progs: fix the incorrect buffer size for super block

Message ID aeb365337a8e4a4a4df1689f428b34cec27c7392.1740542229.git.wqu@suse.com (mailing list archive)
State New
Headers show
Series btrfs-progs: allowing 2K block size for experimental builds | expand

Commit Message

Qu Wenruo Feb. 26, 2025, 3:59 a.m. UTC
Inside the function btrfs_add_to_fsid(), we allocate a buffer to write
the superblock to the disk.

However the buffer size is based on block size, which can cause two
problems:

- 2K block size
  The block size is too small for the super block, and we will write
  beyond the buffer and corrupt the memory.

- 16/64K block size
  The block size will be larger than super block size, this will not
  cause any problem but waste some memory.

Fix the bug by using BTRFS_SUPER_INFO_SIZE as the correct buffer size.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 common/device-scan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/common/device-scan.c b/common/device-scan.c
index a34d86652f06..7d7d67fb5b71 100644
--- a/common/device-scan.c
+++ b/common/device-scan.c
@@ -148,7 +148,7 @@  int btrfs_add_to_fsid(struct btrfs_trans_handle *trans,
 	if (!device)
 		return -ENOMEM;
 
-	buf = calloc(1, sectorsize);
+	buf = calloc(1, BTRFS_SUPER_INFO_SIZE);
 	if (!buf) {
 		ret = -ENOMEM;
 		goto out;