commit:     a933280f70611c0dd026f824c5f52feaecd8803b
Author:     Arisu Tachibana <alicef <AT> gentoo <DOT> org>
AuthorDate: Thu Oct  2 03:23:52 2025 +0000
Commit:     Arisu Tachibana <alicef <AT> gentoo <DOT> org>
CommitDate: Thu Oct  2 03:26:41 2025 +0000
URL:        https://gitweb.gentoo.org/proj/linux-patches.git/commit/?id=a933280f

Add patch btrfs: don't allow adding block device of less than 1 MB

Ref: 
https://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git/tree/queue-6.16/btrfs-don-t-allow-adding-block-device-of-less-than-1.patch
Signed-off-by: Arisu Tachibana <alicef <AT> gentoo.org>

 0000_README                                        |  4 ++
 ...-allow-adding-block-device-of-less-than-1.patch | 54 ++++++++++++++++++++++
 2 files changed, 58 insertions(+)

diff --git a/0000_README b/0000_README
index 7c89ecd8..3f823104 100644
--- a/0000_README
+++ b/0000_README
@@ -79,6 +79,10 @@ Patch:  1008_linux-6.16.9.patch
 From:   https://www.kernel.org
 Desc:   Linux 6.16.9
 
+Patch:  1401_btrfs-don-t-allow-adding-block-device-of-less-than-1.patch
+From:   
https://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git/tree/queue-6.16/btrfs-don-t-allow-adding-block-device-of-less-than-1.patch
+Desc:   btrfs: don't allow adding block device of less than 1 MB
+
 Patch:  1510_fs-enable-link-security-restrictions-by-default.patch
 From:   
http://sources.debian.net/src/linux/3.16.7-ckt4-3/debian/patches/debian/fs-enable-link-security-restrictions-by-default.patch/
 Desc:   Enable link security restrictions by default.

diff --git a/1401_btrfs-don-t-allow-adding-block-device-of-less-than-1.patch 
b/1401_btrfs-don-t-allow-adding-block-device-of-less-than-1.patch
new file mode 100644
index 00000000..e03e21a2
--- /dev/null
+++ b/1401_btrfs-don-t-allow-adding-block-device-of-less-than-1.patch
@@ -0,0 +1,54 @@
+From b4cbca440070641199920a2d73a6abd95c9a9ec7 Mon Sep 17 00:00:00 2001
+From: Sasha Levin <[email protected]>
+Date: Tue, 2 Sep 2025 11:34:10 +0100
+Subject: btrfs: don't allow adding block device of less than 1 MB
+
+From: Mark Harmstone <[email protected]>
+
+[ Upstream commit 3d1267475b94b3df7a61e4ea6788c7c5d9e473c4 ]
+
+Commit 15ae0410c37a79 ("btrfs-progs: add error handling for
+device_get_partition_size_fd_stat()") in btrfs-progs inadvertently
+changed it so that if the BLKGETSIZE64 ioctl on a block device returned
+a size of 0, this was no longer seen as an error condition.
+
+Unfortunately this is how disconnected NBD devices behave, meaning that
+with btrfs-progs 6.16 it's now possible to add a device you can't
+remove:
+
+  # btrfs device add /dev/nbd0 /root/temp
+  # btrfs device remove /dev/nbd0 /root/temp
+  ERROR: error removing device '/dev/nbd0': Invalid argument
+
+This check should always have been done kernel-side anyway, so add a
+check in btrfs_init_new_device() that the new device doesn't have a size
+less than BTRFS_DEVICE_RANGE_RESERVED (i.e. 1 MB).
+
+Reviewed-by: Qu Wenruo <[email protected]>
+Signed-off-by: Mark Harmstone <[email protected]>
+Reviewed-by: David Sterba <[email protected]>
+Signed-off-by: David Sterba <[email protected]>
+Signed-off-by: Sasha Levin <[email protected]>
+---
+ fs/btrfs/volumes.c | 5 +++++
+ 1 file changed, 5 insertions(+)
+
+diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
+index f475b4b7c4578..817d3ef501ec4 100644
+--- a/fs/btrfs/volumes.c
++++ b/fs/btrfs/volumes.c
+@@ -2714,6 +2714,11 @@ int btrfs_init_new_device(struct btrfs_fs_info 
*fs_info, const char *device_path
+               goto error;
+       }
+ 
++      if (bdev_nr_bytes(file_bdev(bdev_file)) <= BTRFS_DEVICE_RANGE_RESERVED) 
{
++              ret = -EINVAL;
++              goto error;
++      }
++
+       if (fs_devices->seeding) {
+               seeding_dev = true;
+               down_write(&sb->s_umount);
+-- 
+2.51.0
+

Reply via email to