]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdstat: fix list detach issues
authorMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Tue, 6 Aug 2024 14:11:18 +0000 (16:11 +0200)
committerMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Tue, 6 Aug 2024 14:41:07 +0000 (16:41 +0200)
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: 4b3644ab4ce6 ("mdstat: Rework mdstat external arrays handling")
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
mdstat.c

index a971a9570856df601d0b2a40e92cf5b8db46513a..29e7836288c3243b7cacc7690c88596e6ab157b3 100644 (file)
--- a/mdstat.c
+++ b/mdstat.c
@@ -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)