Skip to content

Commit 0d0bd28

Browse files
YuKuai-huaweiliu-song-6
authored andcommitted
md/raid5-cache: fix null-ptr-deref for r5l_flush_stripe_to_raid()
r5l_flush_stripe_to_raid() will check if the list 'flushing_ios' is empty, and then submit 'flush_bio', however, r5l_log_flush_endio() is clearing the list first and then clear the bio, which will cause null-ptr-deref: T1: submit flush io raid5d handle_active_stripes r5l_flush_stripe_to_raid // list is empty // add 'io_end_ios' to the list bio_init submit_bio // io1 T2: io1 is done r5l_log_flush_endio list_splice_tail_init // clear the list T3: submit new flush io ... r5l_flush_stripe_to_raid // list is empty // add 'io_end_ios' to the list bio_init bio_uninit // clear bio->bi_blkg submit_bio // null-ptr-deref Fix this problem by clearing bio before clearing the list in r5l_log_flush_endio(). Fixes: 0dd00cb ("raid5-cache: fully initialize flush_bio when needed") Reported-and-tested-by: Corey Hickey <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Yu Kuai <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Song Liu <[email protected]>
1 parent 7b3c70c commit 0d0bd28

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

drivers/md/raid5-cache.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,14 +1260,13 @@ static void r5l_log_flush_endio(struct bio *bio)
12601260

12611261
if (bio->bi_status)
12621262
md_error(log->rdev->mddev, log->rdev);
1263+
bio_uninit(bio);
12631264

12641265
spin_lock_irqsave(&log->io_list_lock, flags);
12651266
list_for_each_entry(io, &log->flushing_ios, log_sibling)
12661267
r5l_io_run_stripes(io);
12671268
list_splice_tail_init(&log->flushing_ios, &log->finished_ios);
12681269
spin_unlock_irqrestore(&log->io_list_lock, flags);
1269-
1270-
bio_uninit(bio);
12711270
}
12721271

12731272
/*

0 commit comments

Comments
 (0)