In the Linux kernel, the following vulnerability has been resolved: btrfs: handle case when repair happens with dev-replace [BUG] There is a bug report that a BUGON() in btrfsrepairiofailure() (originally repairiofailure() in v6.0 kernel) got triggered when replacing a unreliable disk: BTRFS warning (device sda1): csum failed root 257 ino 2397453 off 39624704 csum 0xb0d18c75 expected csum 0x4dae9c5e mirror 3 kernel BUG at fs/btrfs/extentio.c:2380! invalid opcode: 0000 [#1] PREEMPT SMP NOPTI CPU: 9 PID: 3614331 Comm: kworker/u257:2 Tainted: G OE 6.0.0-5-amd64 #1 Debian 6.0.10-2 Hardware name: Micro-Star International Co., Ltd. MS-7C60/TRX40 PRO WIFI (MS-7C60), BIOS 2.70 07/01/2021 Workqueue: btrfs-endio btrfsendbiowork [btrfs] RIP: 0010:repairiofailure+0x24a/0x260 [btrfs] Call Trace: <TASK> cleaniofailure+0x14d/0x180 [btrfs] endbioextent_readpage+0x412/0x6e0 [btrfs] ? _switchto+0x106/0x420 processonework+0x1c7/0x380 workerthread+0x4d/0x380 ? rescuerthread+0x3a0/0x3a0 kthread+0xe9/0x110 ? kthreadcompleteandexit+0x20/0x20 retfromfork+0x22/0x30 [CAUSE] Before the BUGON(), we got some read errors from the replace target first, note the mirror number (3, which is beyond RAID1 duplication, thus it's read from the replace target device). Then at the BUGON() location, we are trying to writeback the repaired sectors back the failed device. The check looks like this: ret = btrfsmapblock(fsinfo, BTRFSMAPWRITE, logical, &maplength, &bioc, mirrornum); if (ret) goto outcounterdec; BUGON(mirrornum != bioc->mirrornum); But inside btrfsmapblock(), we can modify bioc->mirrornum especially for dev-replace: if (devreplaceisongoing && mirrornum == map->numstripes + 1 && !needfullstripe(op) && devreplace->tgtdev != NULL) { ret = getextramirrorfromreplace(fsinfo, logical, *length, devreplace->srcdev->devid, &mirrornum, &physicaltopatchinfirststripe); patchthefirststripefordevreplace = 1; } Thus if we're repairing the replace target device, we're going to trigger that BUGON(). But in reality, the read failure from the replace target device may be that, our replace hasn't reached the range we're reading, thus we're reading garbage, but with replace running, the range would be properly filled later. Thus in that case, we don't need to do anything but let the replace routine to handle it. [FIX] Instead of a BUGON(), just skip the repair if we're repairing the device replace target device.