Skip to contentSkip to conversation

mdadm: fix grow segfault for IMSM

PATCH Applied Mariusz Tkaczyk 1 participant 2 messages Mar 18, 2024 – Mar 22, 2024 MD RAID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mdadm: fix grow segfault for IMSM

If sc is not initialized, there is possibility that sc.pols is not zeroed and it causes segfault.

Add missing initialization.
Add missing dev_policy_free() in two places.

Fixes f656201188d7 ("mdadm: drop get_required_spare_criteria()")
---
 Incremental.c | 1 +
 super-intel.c | 9 +++++++--
 2 files changed, 8 insertions(+), 2 deletions(-)
Incremental.c +1 -0
index 958ba9ba7851..83db071214ee 100644
@@ -874,6 +874,7 @@ mdadm_status_t incremental_external_test_spare_criteria(struct supertype *st, ch
 	rv = MDADM_STATUS_SUCCESS;
 
 out:
+	dev_policy_free(sc.pols);
 	dup->ss->free_super(dup);
 	free(dup);
 
super-intel.c +7 -2
index 7714045575b2..32eceb155886 100644
@@ -11518,10 +11518,15 @@ static int imsm_reshape_is_allowed_on_container(struct supertype *st,
  */
 static struct mdinfo *get_spares_for_grow(struct supertype *st)
 {
-	struct spare_criteria sc;
+	struct spare_criteria sc = {0};
+	struct mdinfo *spares;
 
 	get_spare_criteria_imsm(st, NULL, &sc);
-	return container_choose_spares(st, &sc, NULL, NULL, NULL, 0);
+	spares = container_choose_spares(st, &sc, NULL, NULL, NULL, 0);
+
+	dev_policy_free(sc.pols);
+
+	return spares;
 }
 
 /******************************************************************************
Signature · 1 line
2.35.3
author Applied
#1 lore raw
Quoted 9 lines · On Mon, 18 Mar 2024 17:28:42 +0100 Mariusz Tkaczyk…

If sc is not initialized, there is possibility that sc.pols is not zeroed and it causes segfault.

Add missing initialization.
Add missing dev_policy_free() in two places.

Fixes f656201188d7 ("mdadm: drop get_required_spare_criteria()")

---

Applied!

Thanks,
Mariusz