md/raid10: initialize r10_bio->read_slot before use.
PATCH 1/1 md/raid10: initialize r10_bio->read_slot before use.
In __make_request() a new r10bio is allocated and passed to raid10_read_request(). The read_slot member of the bio is not initialized, and the raid10_read_request() uses it to index an array. This leads to occasional panics.
Fix by initializing the field to invalid value and checking for valid value in raid10_read_request().
--- drivers/md/raid10.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/raid10.c +2 -1
@@ -1143,7 +1143,7 @@ static void raid10_read_request(struct mddev *mddev, struct bio *bio,struct md_rdev *err_rdev =NULL ;gfp_t gfp =GFP_NOIO ; -if (r10_bio->devs[slot].rdev) { +if (slot >=0 && r10_bio->devs[slot].rdev) {/* * This is an error retry, but we cannot * safely dereference the rdev in the r10_bio,
@@ -1508,6 +1508,7 @@ static void __make_request(struct mddev *mddev, struct bio *bio, int sectors) r10_bio->mddev = mddev; r10_bio->sector = bio->bi_iter.bi_sector; r10_bio->state =0 ; + r10_bio->read_slot =-1 ;memset (r10_bio->devs,0 ,sizeof (r10_bio->devs[0 ]) * conf->copies);if (bio_data_dir (bio) ==READ )
Signature · 1 line
2.26.2
Song Liu
maintainerQuoted 10 lines · Kevin Vigor
In
__make_request()a new r10bio is allocated and passed toraid10_read_request(). Theread_slotmember of the bio is not initialized, and theraid10_read_request()uses it to index an array. This leads to occasional panics.Fix by initializing the field to invalid value and checking for valid value in
raid10_read_request().Signed-off-by Kevin Vigor <[email protected]>
Thanks for the fix!
I am having problem apply this patch, could you please rebase against
git://git.kernel.org/pub/scm/linux/kernel/git/song/md.git md-next
Quoted 9 lines
--- drivers/md/raid10.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/md/raid10.c +0
-0
drivers/md/raid10.c static void raid10_read_request(struct mddev *mddev, struct bio *bio, · line 1146
Quoted 5 lines
drivers/md/raid10.c +1
-1@@ -1143,7 +1143,7 @@ static void raid10_read_request(struct mddev *mddev, struct bio *bio,struct md_rdev *err_rdev =NULL ;gfp_t gfp =GFP_NOIO ; -if (r10_bio->devs[slot].rdev) { +if (slot >=0 && r10_bio->devs[slot].rdev) {
If we set default read_slot = 0, we should not need this change, right?
Quoted 14 lines
drivers/md/raid10.c +1
-1/* * This is an error retry, but we cannot * safely dereference the rdev in the r10_bio, @@ -1508,6 +1508,7 @@ static void __make_request(struct mddev *mddev, struct bio *bio, int sectors) r10_bio->mddev = mddev; r10_bio->sector = bio->bi_iter.bi_sector; r10_bio->state =0 ; + r10_bio->read_slot =-1 ;memset (r10_bio->devs,0 ,sizeof (r10_bio->devs[0 ]) * conf->copies);if (bio_data_dir (bio) ==READ ) --2.26.2
PATCH v2 1/1 md/raid10: initialize r10_bio->read_slot before use.
In __make_request() a new r10bio is allocated and passed to raid10_read_request(). The read_slot member of the bio is not initialized, and the raid10_read_request() uses it to index an array. This leads to occasional panics.
Fix by initializing the field to invalid value and checking for valid value in raid10_read_request().
---
v2:
- rebase onto md-next
--- drivers/md/raid10.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/raid10.c +2 -1
@@ -1127,7 +1127,7 @@ static void raid10_read_request(struct mddev *mddev, struct bio *bio,struct md_rdev *err_rdev =NULL ;gfp_t gfp =GFP_NOIO ; -if (r10_bio->devs[slot].rdev) { +if (slot >=0 && r10_bio->devs[slot].rdev) {/* * This is an error retry, but we cannot * safely dereference the rdev in the r10_bio,
@@ -1508,6 +1508,7 @@ static void __make_request(struct mddev *mddev, struct bio *bio, int sectors) r10_bio->mddev = mddev; r10_bio->sector = bio->bi_iter.bi_sector; r10_bio->state =0 ; + r10_bio->read_slot =-1 ;memset (r10_bio->devs,0 ,sizeof (r10_bio->devs[0 ]) * conf->geo.raid_disks);if (bio_data_dir (bio) ==READ )
Signature · 1 line
2.26.2
Song Liu
maintainerQuoted 22 lines · Kevin Vigor
In
__make_request()a new r10bio is allocated and passed toraid10_read_request(). Theread_slotmember of the bio is not initialized, and theraid10_read_request()uses it to index an array. This leads to occasional panics.Fix by initializing the field to invalid value and checking for valid value in
raid10_read_request().Signed-off-by Kevin Vigor <[email protected]>---
v2:
- rebase onto md-next--- drivers/md/raid10.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/md/raid10.c +0
-0
drivers/md/raid10.c static void raid10_read_request(struct mddev *mddev, struct bio *bio, · line 1130
Quoted 5 lines
drivers/md/raid10.c +1
-1@@ -1127,7 +1127,7 @@ static void raid10_read_request(struct mddev *mddev, struct bio *bio,struct md_rdev *err_rdev =NULL ;gfp_t gfp =GFP_NOIO ; -if (r10_bio->devs[slot].rdev) { +if (slot >=0 && r10_bio->devs[slot].rdev) {
How about we initialize read_slot to 0, and get rid of this check?
Thanks,
Song
A message that is not in the archive (sent off-list or not yet received): CAFVaERqog8s80npb-w2g9He50=8D4-qYdCr9GicN_PU=Q5mt=Q@mail.gmail.com
Song Liu
maintainerQuoted 6 lines · Kevin Vigor
Quoted 2 lines
How about we initialize
read_slotto 0, and get rid of this check?That will definitely work properly since we memset the rdev to null in
__make_request. But theread_slotis truly invalid until we callread_balance()successfully and it feels wrong to set it to a valid value even if it os harmless by accident. So I prefer to give it an explicitly invalid value.But your solution saves one test in the issue path and a line of diff, so I will happily change if you prefer the zero solution.
I think initialized to -1 is safer in long run.
Thanks for the fix! Applied to md-next.