During recovery/check operations, the process_checks function loops through available disks to find a 'primary' source with successfully read data. If no suitable source disk is found after checking all possibilities, the 'primary' index will reach conf->raid_disks * 2. Add an explicit check for this condition after the loop. If no source disk was found, print an error message and return early to prevent further processing without a valid primary source. Signed-off-by: Meir Elisha <meir.elisha@xxxxxxxxxxx> --- This was observed when forcefully disconnecting all iSCSI devices backing a RAID1 array(using --failfast flag) during a check operation, causing all reads within process_checks to fail. The resulting kernel oops shows: BUG: kernel NULL pointer dereference, address: 0000000000000040 RIP: 0010:process_checks+0x25e/0x5e0 [raid1] Code: ... <4c> 8b 53 40 ... // mov r10,[rbx+0x40] Call Trace: process_checks sync_request_write raid1d md_thread kthread ret_from_fork drivers/md/raid1.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c index 0efc03cea24e..b6a52c137f53 100644 --- a/drivers/md/raid1.c +++ b/drivers/md/raid1.c @@ -2296,6 +2296,12 @@ static void process_checks(struct r1bio *r1_bio) rdev_dec_pending(conf->mirrors[primary].rdev, mddev); break; } + + if (primary >= conf->raid_disks * 2) { + pr_err_ratelimited("md/raid1:%s: unable to find source disk\n", mdname(mddev)); + return; + } + r1_bio->read_disk = primary; for (i = 0; i < conf->raid_disks * 2; i++) { int j = 0; -- 2.34.1