Skip to content

Commit

Permalink
mdstat: fix list detach issues
Browse files Browse the repository at this point in the history
Move ent = ent->next; to while. It was outside the loop so if there
are more than 2 elements and we are looking for 3rd element it causes
infinite loop..

Fix el->next zeroing. It causes segfault in mdstat_free(). Theses
issues were not visible in my testing because I had only 2 MD devices.

Fixes: 4b3644a ("mdstat: Rework mdstat external arrays handling")
Signed-off-by: Mariusz Tkaczyk <[email protected]>
  • Loading branch information
mtkaczyk committed Aug 6, 2024
1 parent c653054 commit 4b04187
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mdstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,15 @@ static void mdstat_ent_list_detach_element(struct mdstat_ent **list_head, struct
ent->next = el->next;
break;
}

ent = ent->next;
}

ent = ent->next;
}

/* Guard if not found or list is empty - not allowed */
assert(ent);
ent->next = NULL;
el->next = NULL;
}

void free_mdstat(struct mdstat_ent *ms)
Expand Down

0 comments on commit 4b04187

Please sign in to comment.