linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
To: linux-raid@vger.kernel.org
Cc: jes@trained-monkey.org,
	Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Subject: [PATCH] mdadm: fix grow segfault for IMSM
Date: Mon, 18 Mar 2024 17:28:42 +0100	[thread overview]
Message-ID: <20240318162842.9651-1-mariusz.tkaczyk@linux.intel.com> (raw)

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()")
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
---
 Incremental.c | 1 +
 super-intel.c | 9 +++++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/Incremental.c b/Incremental.c
index 958ba9ba7851..83db071214ee 100644
--- a/Incremental.c
+++ b/Incremental.c
@@ -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);
 
diff --git a/super-intel.c b/super-intel.c
index 7714045575b2..32eceb155886 100644
--- a/super-intel.c
+++ b/super-intel.c
@@ -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;
 }
 
 /******************************************************************************
-- 
2.35.3


             reply	other threads:[~2024-03-18 16:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-18 16:28 Mariusz Tkaczyk [this message]
2024-03-22 11:19 ` [PATCH] mdadm: fix grow segfault for IMSM Mariusz Tkaczyk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240318162842.9651-1-mariusz.tkaczyk@linux.intel.com \
    --to=mariusz.tkaczyk@linux.intel.com \
    --cc=jes@trained-monkey.org \
    --cc=linux-raid@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).