linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Vigor <kvigor@gmail.com>
To: song@kernel.org, linux-raid@vger.kernel.org
Cc: Kevin Vigor <kvigor@gmail.com>
Subject: [PATCH v2] md/raid10: initialize r10_bio->read_slot before use.
Date: Fri,  6 Nov 2020 14:20:34 -0800	[thread overview]
Message-ID: <20201106222034.1304830-1-kvigor@gmail.com> (raw)
In-Reply-To: <CAPhsuW6GqEU7BczF2tpgtEJoU5Fdh4M17N9cobhSMdVY4NPD3w@mail.gmail.com>

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().

Signed-off-by: Kevin Vigor <kvigor@gmail.com>
---
v2:
- rebase onto md-next
---
 drivers/md/raid10.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index b7bca6703df8..3153183b7772 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -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)
-- 
2.26.2


  reply	other threads:[~2020-11-06 22:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-05 18:07 [PATCH] md/raid10: initialize r10_bio->read_slot before use Kevin Vigor
2020-11-06 21:56 ` Song Liu
2020-11-06 22:20   ` Kevin Vigor [this message]
2020-11-07  0:26     ` [PATCH v2] " Song Liu
     [not found]       ` <CAFVaERqog8s80npb-w2g9He50=8D4-qYdCr9GicN_PU=Q5mt=Q@mail.gmail.com>
2020-11-09 18:28         ` Song Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201106222034.1304830-1-kvigor@gmail.com \
    --to=kvigor@gmail.com \
    --cc=linux-raid@vger.kernel.org \
    --cc=song@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).