Commit 14037c2d authored by Yufen Yu's avatar Yufen Yu Committed by Khalid Elmously

md raid10: fix NULL deference in handle_write_completed()

BugLink: https://bugs.launchpad.net/bugs/1775771

[ Upstream commit 01a69cab ]

In the case of 'recover', an r10bio with R10BIO_WriteError &
R10BIO_IsRecover will be progressed by handle_write_completed().
This function traverses all r10bio->devs[copies].
If devs[m].repl_bio != NULL, it thinks conf->mirrors[dev].replacement
is also not NULL. However, this is not always true.

When there is an rdev of raid10 has replacement, then each r10bio
->devs[m].repl_bio != NULL in conf->r10buf_pool. However, in 'recover',
even if corresponded replacement is NULL, it doesn't clear r10bio
->devs[m].repl_bio, resulting in replacement NULL deference.

This bug was introduced when replacement support for raid10 was
added in Linux 3.3.

As NeilBrown suggested:
	Elsewhere the determination of "is this device part of the
	resync/recovery" is made by resting bio->bi_end_io.
	If this is end_sync_write, then we tried to write here.
	If it is NULL, then we didn't try to write.

Fixes: 9ad1aefc ("md/raid10:  Handle replacement devices during resync.")
Cc: stable (V3.3+)
Suggested-by: default avatarNeilBrown <neilb@suse.com>
Signed-off-by: default avatarYufen Yu <yuyufen@huawei.com>
Signed-off-by: default avatarShaohua Li <sh.li@alibaba-inc.com>
Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarJuerg Haefliger <juergh@canonical.com>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
parent 02f17c09
...@@ -2630,7 +2630,8 @@ static void handle_write_completed(struct r10conf *conf, struct r10bio *r10_bio) ...@@ -2630,7 +2630,8 @@ static void handle_write_completed(struct r10conf *conf, struct r10bio *r10_bio)
for (m = 0; m < conf->copies; m++) { for (m = 0; m < conf->copies; m++) {
int dev = r10_bio->devs[m].devnum; int dev = r10_bio->devs[m].devnum;
rdev = conf->mirrors[dev].rdev; rdev = conf->mirrors[dev].rdev;
if (r10_bio->devs[m].bio == NULL) if (r10_bio->devs[m].bio == NULL ||
r10_bio->devs[m].bio->bi_end_io == NULL)
continue; continue;
if (!r10_bio->devs[m].bio->bi_error) { if (!r10_bio->devs[m].bio->bi_error) {
rdev_clear_badblocks( rdev_clear_badblocks(
...@@ -2645,7 +2646,8 @@ static void handle_write_completed(struct r10conf *conf, struct r10bio *r10_bio) ...@@ -2645,7 +2646,8 @@ static void handle_write_completed(struct r10conf *conf, struct r10bio *r10_bio)
md_error(conf->mddev, rdev); md_error(conf->mddev, rdev);
} }
rdev = conf->mirrors[dev].replacement; rdev = conf->mirrors[dev].replacement;
if (r10_bio->devs[m].repl_bio == NULL) if (r10_bio->devs[m].repl_bio == NULL ||
r10_bio->devs[m].repl_bio->bi_end_io == NULL)
continue; continue;
if (!r10_bio->devs[m].repl_bio->bi_error) { if (!r10_bio->devs[m].repl_bio->bi_error) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment