Performing verification for Bionic I started a fresh VM with 4.15.0-206-generic from -updates. I attached 2x virtio disks of 3gb each, for scratch disks.
I ran btrfs/154 with the following results: # ./check btrfs/154 FSTYP -- btrfs PLATFORM -- Linux/x86_64 bionic-xfs 4.15.0-206-generic #217-Ubuntu SMP Fri Feb 3 19:10:13 UTC 2023 MKFS_OPTIONS -- /dev/vdd MOUNT_OPTIONS -- /dev/vdd /scratch btrfs/154 4s ... _check_dmesg: something found in dmesg (see /home/ubuntu/xfstests-dev/results//btrfs/154.dmesg) - output mismatch (see /home/ubuntu/xfstests-dev/results//btrfs/154.out.bad) --- tests/btrfs/154.out 2023-01-28 02:53:03.566450703 +0000 +++ /home/ubuntu/xfstests-dev/results//btrfs/154.out.bad 2023-03-14 04:46:12.824848412 +0000 @@ -1,2 +1,6 @@ QA output created by 154 +Traceback (most recent call last): + File "/home/ubuntu/xfstests-dev/src/btrfs_crc32c_forged_name.py", line 99, in <module> + os.rename(srcpath, dstpath) +OSError: [Errno 75] Value too large for defined data type: '/scratch/309' -> b'/scratch/ec73\xb4\xd3?\xc4249e4acad9bcfc483738ce72c1da9a5e0dcc098e3103a2e00d8e05fe6a463df2c472d5df948dc08e6aaf48cdff3c41de690ce50cd88be6cdea40e616db44152df10f8dfe36a5de62550b277db85c01455dde98b189b68' Silence is golden ... (Run 'diff -u /home/ubuntu/xfstests-dev/tests/btrfs/154.out /home/ubuntu/xfstests-dev/results//btrfs/154.out.bad' to see the entire diff) Ran: btrfs/154 Failures: btrfs/154 Failed 1 of 1 tests [ 69.108117] BTRFS: device fsid 032cd7d2-e729-4a6a-aa6d-95141191525a devid 1 transid 5 /dev/vdc [ 78.693183] BTRFS info (device vdc): disk space caching is enabled [ 78.693184] BTRFS info (device vdc): has skinny extents [ 78.693185] BTRFS info (device vdc): flagging fs with big metadata feature [ 78.695928] BTRFS info (device vdc): creating UUID tree [ 78.828837] BTRFS: device fsid 053e2dfb-59fb-45ab-8a69-08262d44d669 devid 1 transid 5 /dev/vdd [ 78.840701] BTRFS info (device vdd): disk space caching is enabled [ 78.840703] BTRFS info (device vdd): has skinny extents [ 78.840704] BTRFS info (device vdd): flagging fs with big metadata feature [ 78.843953] BTRFS info (device vdd): creating UUID tree [ 79.053524] BTRFS info (device vdc): disk space caching is enabled [ 79.053526] BTRFS info (device vdc): has skinny extents [ 79.104532] run fstests btrfs/154 at 2023-03-14 04:46:08 [ 79.230124] BTRFS: device fsid af57acbb-7a45-46e8-969f-4cb3ce52e29e devid 1 transid 5 /dev/vdd [ 79.235760] BTRFS info (device vdd): disk space caching is enabled [ 79.235761] BTRFS info (device vdd): has skinny extents [ 79.235761] BTRFS info (device vdd): flagging fs with big metadata feature [ 79.239893] BTRFS info (device vdd): creating UUID tree [ 82.714095] ------------[ cut here ]------------ [ 82.714098] BTRFS: Transaction aborted (error -75) [ 82.714180] WARNING: CPU: 2 PID: 1883 at /build/linux-sIqTXt/linux-4.15.0/fs/btrfs/inode.c:10217 btrfs_rename+0xcf1/0xdf0 [btrfs] [ 82.714210] CPU: 2 PID: 1883 Comm: python3 Not tainted 4.15.0-206-generic #217-Ubuntu [ 82.714212] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.0-debian-1.16.0-4 04/01/2014 [ 82.714234] RIP: 0010:btrfs_rename+0xcf1/0xdf0 [btrfs] [ 82.714235] RSP: 0018:ffffaf86c1adfd20 EFLAGS: 00010282 [ 82.714238] RAX: 0000000000000000 RBX: ffff96e6f7bac118 RCX: 0000000000000006 [ 82.714239] RDX: 0000000000000007 RSI: 0000000000000096 RDI: ffff96e6ffd1b4d0 [ 82.714240] RBP: ffffaf86c1adfdc0 R08: 00000000000002d9 R09: 0000000000000004 [ 82.714241] R10: 0000000000000000 R11: 0000000000000001 R12: 0000000000000236 [ 82.714242] R13: ffff96e6f6842618 R14: ffff96e6f7b78cc0 R15: ffff96e6f7bac118 [ 82.714245] FS: 00007fbf05988740(0000) GS:ffff96e6ffd00000(0000) knlGS:0000000000000000 [ 82.714246] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 82.714248] CR2: 00007fbf058ef4c8 CR3: 0000000175166005 CR4: 0000000000760ee0 [ 82.714254] PKRU: 55555554 [ 82.714255] Call Trace: [ 82.714277] btrfs_rename2+0x1d/0x30 [btrfs] [ 82.714283] vfs_rename+0x46e/0x960 [ 82.714287] SyS_rename+0x362/0x3c0 [ 82.714293] do_syscall_64+0x73/0x130 [ 82.714297] entry_SYSCALL_64_after_hwframe+0x59/0xbe [ 82.714299] RIP: 0033:0x7fbf053f8ce7 [ 82.714300] RSP: 002b:00007ffdb2ba86d8 EFLAGS: 00000246 ORIG_RAX: 0000000000000052 [ 82.714302] RAX: ffffffffffffffda RBX: 00007ffdb2ba8790 RCX: 00007fbf053f8ce7 [ 82.714303] RDX: 00000000ffffffff RSI: 00007fbf044872f0 RDI: 00007fbf057dafb0 [ 82.714304] RBP: 00000000ffffff00 R08: 0000000000000000 R09: 0000000000713557 [ 82.714306] R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffdb2ba8740 [ 82.714307] R13: 00000000ffffff9c R14: 00000000ffffff9c R15: 0000000001365da0 [ 82.714309] Code: 0f ba a8 d0 cd 00 00 02 72 2b 41 83 f8 fb 0f 84 d9 00 00 00 44 89 c6 48 c7 c7 68 83 43 c0 44 89 55 80 44 89 45 98 e8 6f 1c 0e f5 <0f> 0b 44 8b 45 98 44 8b 55 80 44 89 55 80 44 89 c1 44 89 45 98 [ 82.714329] ---[ end trace 4d63dbb061789135 ]--- [ 82.714333] BTRFS: error (device vdd) in btrfs_rename:10217: errno=-75 unknown [ 82.715832] BTRFS info (device vdd): forced readonly [ 82.990842] BTRFS info (device vdd): disk space caching is enabled [ 82.990845] BTRFS info (device vdd): has skinny extents The test fails on the kernel in -updates, as expected. I then enabled -proposed, and installed 4.15.0-207-generic. Re-running the test on a clean btrfs filesystem: # ./check btrfs/154 FSTYP -- btrfs PLATFORM -- Linux/x86_64 bionic-xfs 4.15.0-207-generic #218-Ubuntu SMP Thu Feb 23 23:36:05 UTC 2023 MKFS_OPTIONS -- /dev/vdd MOUNT_OPTIONS -- /dev/vdd /scratch btrfs/154 4s ... 4s Ran: btrfs/154 Passed all 1 tests The test passes and there is no output in dmesg. The kernel in -proposed fixes the issue and I am happy to mark it as verified for Bionic. ** Tags removed: verification-needed-bionic ** Tags added: verification-done-bionic -- You received this bug notification because you are a member of Kernel Packages, which is subscribed to linux in Ubuntu. https://bugs.launchpad.net/bugs/2004132 Title: btrfs/154: rename fails with EOVERFLOW when calculating item size during item key collision Status in linux package in Ubuntu: Fix Released Status in linux source package in Bionic: Fix Committed Status in linux source package in Focal: Fix Committed Bug description: BugLink: https://bugs.launchpad.net/bugs/2004132 [Impact] xfstests btrfs/154 fails on both Bionic and Focal, leading to a kernel oops and the btrfs volume being forced readonly. In btrfs, item key collision is allowed for some item types, namely dir item and inode references. When inserting items into the btree, there are two objects, the btrfs_item and the item data. These objects must fit within the btree nodesize. When a hash collision occurs, and we call btrfs_search_slot() to place the objects in the tree, when btrfs_search_slot() reaches the leaf node, a check is performed to see if we need to split the leaf. The check is incorrect, returning that we need to split the leaf, since it thinks that both btrfs_item and the item data need to be inserted, when in reality, the item can be merged with the existing one and no new btrfs_item will be inserted. split_leaf() will return EOVERFLOW from following code: if (extend && data_size + btrfs_item_size_nr(l, slot) + sizeof(struct btrfs_item) > BTRFS_LEAF_DATA_SIZE(fs_info)) return -EOVERFLOW; In the rename case, btrfs_check_dir_item_collision() is called early stages of treewalking, and correctly calculates the needed size, taking into account that a hash collision has occurred. data_size = sizeof(*di) + name_len; if (data_size + btrfs_item_size_nr(leaf, slot) + sizeof(struct btrfs_item) > BTRFS_LEAF_DATA_SIZE(root->fs_info)) The two sizes reported from btrfs_check_dir_item_collision() and btrfs_search_slot() are different, and rename fails due to split_leaf() returning -EOVERFLOW, leading to transaction abort and forcing the volume readonly. Kernel oops: BTRFS: Transaction aborted (error -75) WARNING: CPU: 0 PID: 2921 at /build/linux-fTmV3T/linux-4.15.0/fs/btrfs/inode.c:10217 btrfs_rename+0xcf1/0xdf0 [btrfs] CPU: 0 PID: 2921 Comm: python3 Not tainted 4.15.0-202-generic #213-Ubuntu RIP: 0010:btrfs_rename+0xcf1/0xdf0 [btrfs] RSP: 0018:ffff9e6f4183fd20 EFLAGS: 00010282 RAX: 0000000000000000 RBX: ffff91a493f27b98 RCX: 0000000000000006 RDX: 0000000000000007 RSI: 0000000000000096 RDI: ffff91a4bfc1b4d0 RBP: ffff9e6f4183fdc0 R08: 00000000000002b4 R09: 0000000000000004 R10: 0000000000000000 R11: 0000000000000001 R12: 0000000000000236 R13: ffff91a493f56518 R14: ffff91a4b6b57b40 R15: ffff91a493f27b98 FS: 00007f6041081740(0000) GS:ffff91a4bfc00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f6040fe84c8 CR3: 000000015c8ca005 CR4: 0000000000760ef0 PKRU: 55555554 Call Trace: btrfs_rename2+0x1d/0x30 [btrfs] vfs_rename+0x46e/0x960 SyS_rename+0x362/0x3c0 do_syscall_64+0x73/0x130 entry_SYSCALL_64_after_hwframe+0x41/0xa6 Code: 0f ba a8 d0 cd 00 00 02 72 2b 41 83 f8 fb 0f 84 d9 00 00 00 44 89 c6 48 c7 c7 68 43 4b c0 44 89 55 80 44 89 45 98 e8 8f 5c a6 d0 <0f> 0b 44 8b 45 98 44 8b 55 80 44 89 55 80 44 89 c1 44 89 45 98 ---[ end trace 9c6b87a19f4436f3 ]--- BTRFS: error (device vdd) in btrfs_rename:10217: errno=-75 unknown BTRFS info (device vdd): forced readonly [Testcase] Start a fresh Bionic or Focal VM. Attach two scratch disks, I used standard virtio disks with 3gb of storage each. These disks are /dev/vdc and /dev/vdd. Compile xfstests: $ sudo apt-get install acl attr automake bc dbench dump e2fsprogs fio gawk \ gcc git indent libacl1-dev libaio-dev libcap-dev libgdbm-dev libtool \ libtool-bin libuuid1 lvm2 make psmisc python3 quota sed \ uuid-dev uuid-runtime xfsprogs linux-headers-$(uname -r) sqlite3 make $ sudo apt-get install f2fs-tools ocfs2-tools udftools xfsdump \ xfslibs-dev $ git clone git://git.kernel.org/pub/scm/fs/xfs/xfstests-dev.git $ cd xfstests-dev $ make $ sudo su # mkdir /test # mkdir /scratch # mkfs.btrfs -f /dev/vdc # cat << EOF >> ./local.config export TEST_DEV=/dev/vdc export TEST_DIR=/test export SCRATCH_DEV=/dev/vdd export SCRATCH_MNT=/scratch EOF # ./check btrfs/154 btrfs/154 _check_dmesg: something found in dmesg (see /home/ubuntu/xfstests-dev/results//btrfs/154.dmesg) - output mismatch (see /home/ubuntu/xfstests-dev/results//btrfs/154.out.bad) --- tests/btrfs/154.out 2023-01-28 02:53:03.566450703 +0000 +++ /home/ubuntu/xfstests-dev/results//btrfs/154.out.bad 2023-01-28 06:51:34.113121042 +0000 @@ -1,2 +1,6 @@ QA output created by 154 +Traceback (most recent call last): + File "/home/ubuntu/xfstests-dev/src/btrfs_crc32c_forged_name.py", line 99, in <module> + os.rename(srcpath, dstpath) +OSError: [Errno 75] Value too large for defined data type: '/scratch/309' -> b'/scratch/fa5d\x90O\x97015d7a47c48fdeb99b857c17e8038da6382fcb05e3a6b367589a8f54a8c3c1327584dfa630b4bd8c5bbb37b4decc2b82fecb4c940e0bd0989166c44e6af2855e9e42a02a57cffa2fc5283525ac53b2b0d2baaf874ff50b' Ran: btrfs/154 Failures: btrfs/154 Failed 1 of 1 tests If you examine dmesg, you will see the oops from the impact section. If you install the test kernel from the below ppa: https://launchpad.net/~mruffell/+archive/ubuntu/sf349467-btrfs-154 The issue no longer occurs: # ./check btrfs/154 Ran: btrfs/154 Passed all 1 tests [Fix] This was fixed in 5.11-rc3 by the below commit: commit 9a664971569daf68254928149f580b4f5856d274 Author: ethanwu <etha...@synology.com> Date: Tue Dec 1 17:25:12 2020 +0800 Subject: btrfs: correctly calculate item size used when item key collision happens Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=9a664971569daf68254928149f580b4f5856d274 This cherry-picks to Focal, and required a small backport to Bionic, removing the hunk that contained comments explaining the parameters to btrfs_search_slot(). [Where problems could occur] Problems could occur when calculating the size required for btrfs_item and item data when hash collisions occur. Such collisions are rare in of itself, but possible if you have a large amount files or craft filenames to force collisions with the crc32 hash algorithm. If a regression were to occur, it could cause more transactions to be aborted, and would likely result in the users volume being forced read only. They might not lose any existing data, but data being written might be lost. To manage notifications about this bug go to: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2004132/+subscriptions -- Mailing list: https://launchpad.net/~kernel-packages Post to : kernel-packages@lists.launchpad.net Unsubscribe : https://launchpad.net/~kernel-packages More help : https://help.launchpad.net/ListHelp