In Assemble(), after context reload, best[i] can be -1 in some cases, and before checking if this value is negative we use it to access devices[j].i.disk.raid_disk, potentially causing a segfault. Check if best[i] is negative before using it to prevent this potential segfault. Regression was causes by commit 69a481166be6 ("Assemble array with write journal"). Reviewed-by: NeilBrown <neilb@xxxxxxxx> Signed-off-by: Andrea Righi <andrea@xxxxxxxxxxxxxxx> Signed-off-by: Robert LeBlanc <robert@xxxxxxxxxxxxx> --- Assemble.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Assemble.c b/Assemble.c index 3da0903..fc681eb 100644 --- a/Assemble.c +++ b/Assemble.c @@ -1669,6 +1669,8 @@ try_again: int j = best[i]; unsigned int desired_state; + if (j < 0) + continue; if (devices[j].i.disk.raid_disk == MD_DISK_ROLE_JOURNAL) desired_state = (1<<MD_DISK_JOURNAL); else if (i >= content->array.raid_disks * 2) @@ -1678,8 +1680,6 @@ try_again: else desired_state = (1<<MD_DISK_ACTIVE) | (1<<MD_DISK_SYNC); - if (j<0) - continue; if (!devices[j].uptodate) continue; -- To unsubscribe from this list: send the line "unsubscribe linux-raid" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html