In the Linux kernel, the following vulnerability has been resolved:
md/raid5: avoid R5_Overlap races while breaking stripe batches
KCSAN report a race in breakstripebatchlist() vs. raid5make_request() on sh->dev[i].flags (plain word write vs. atomic bit op)..
and .. one possible scenario is:
CPU1 CPU2 breakstripebatchlist(sh1) -> handle sh2 -> lock(sh2) -> sh2->batchhead = NULL -> unlock(sh2) -> testandclearbit(R5Overlap, sh2->dev[i].flags) -> wakeupbit(sh2->dev[i].flags) raid5makerequest() -> addallstripebios(sh2) -> lock(sh2) -> stripebiooverlaps(sh2) returns true batchhead is NULL, so new bio overlap exist bio on sh2 -> true -> setbit(R5Overlap, sh2->dev[i].flags) -> unlock(sh2) -> waitonbit(sh2->dev[i].flags) -> sh2->dev[i].flags = sh1->dev[i].flags & ~R5_Overlap
No waitupbit(), CPU2 could be waitonbit() forever...
Fix by : - Expand the protect zone. - Use batchhead's device flag's snaphot when no held headsh->stripelock. - Move sh/headsh->batchhead = NULL to the end of protected zone , and , any concurrent addallstripebios() grabs sh->stripelock now either: - see batchhead != null, and , is rejected by stripebiooverlaps() under the lock (no R5Overlap wait ) , or , - sees batchhead == NULL, only after dev[i].flags has already been set and the prior R5_Overlap waiters worken.
BUG: KCSAN: data-race in breakstripebatchlist / raid5make_request
write (marked) to 0xffff8e89c8117548 of 8 bytes by task 4042 on cpu 0: raid5makerequest+0xea0/0x2930 mdhandlerequest+0x4a2/0xa40 mdsubmitbio+0x109/0x1a0 __submitbio+0x2ec/0x390 submitbionoacctnocheck+0x457/0x710 submitbionoacct+0x2a7/0xc20 submitbio+0x56/0x250 blkdevdirectIO+0x54c/0xda0 blkdevwriteiter+0x38f/0x570 aiowrite+0x22b/0x490 iosubmitone+0xa51/0xf70 _x64sysiosubmit+0xf7/0x220 x64syscall+0x1907/0x1c60 dosyscall64+0x130/0x570 entrySYSCALL64afterhwframe+0x76/0x7e
read to 0xffff8e89c8117548 of 8 bytes by task 4010 on cpu 5: breakstripebatchlist+0x249/0x480 handlestripecleanevent+0x720/0x9b0 handlestripe+0x32fb/0x4500 handleactivestripes.isra.0+0x6e0/0xa50 raid5d+0x7e0/0xba0 mdthread+0x15a/0x2d0 kthread+0x1e3/0x220 retfromfork+0x37a/0x410 retfromfork_asm+0x1a/0x30
value changed: 0x0000000000000019 -> 0x0000000000000099 --> R5_Overlap