Blame SOURCES/0018-Fix-possible-NULL-ptr-dereferences-and-memory-leaks.patch

fdf7c0
From 626bc45396c4959f2c4685c2faa7c4f553f4efdf Mon Sep 17 00:00:00 2001
fdf7c0
From: Mateusz Grzonka <mateusz.grzonka@intel.com>
fdf7c0
Date: Mon, 13 Jun 2022 11:59:34 +0200
01ff50
Subject: [PATCH 18/83] Fix possible NULL ptr dereferences and memory leaks
fdf7c0
fdf7c0
In Assemble there was a NULL check for sra variable,
fdf7c0
which effectively didn't stop the execution in every case.
fdf7c0
That might have resulted in a NULL pointer dereference.
fdf7c0
fdf7c0
Also in super-ddf, mu variable was set to NULL for some condition,
fdf7c0
and then immidiately dereferenced.
fdf7c0
Additionally some memory wasn't freed as well.
fdf7c0
fdf7c0
Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com>
fdf7c0
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
fdf7c0
---
fdf7c0
 Assemble.c  | 7 ++++++-
fdf7c0
 super-ddf.c | 9 +++++++--
fdf7c0
 2 files changed, 13 insertions(+), 3 deletions(-)
fdf7c0
fdf7c0
diff --git a/Assemble.c b/Assemble.c
fdf7c0
index 9eac9ce0..4b213560 100644
fdf7c0
--- a/Assemble.c
fdf7c0
+++ b/Assemble.c
fdf7c0
@@ -1982,7 +1982,12 @@ int assemble_container_content(struct supertype *st, int mdfd,
fdf7c0
 	}
fdf7c0
 
fdf7c0
 	sra = sysfs_read(mdfd, NULL, GET_VERSION|GET_DEVS);
fdf7c0
-	if (sra == NULL || strcmp(sra->text_version, content->text_version) != 0) {
fdf7c0
+	if (sra == NULL) {
fdf7c0
+		pr_err("Failed to read sysfs parameters\n");
fdf7c0
+		return 1;
fdf7c0
+	}
fdf7c0
+
fdf7c0
+	if (strcmp(sra->text_version, content->text_version) != 0) {
fdf7c0
 		if (content->array.major_version == -1 &&
fdf7c0
 		    content->array.minor_version == -2 &&
fdf7c0
 		    c->readonly &&
fdf7c0
diff --git a/super-ddf.c b/super-ddf.c
fdf7c0
index 8cda23a7..abbc8b09 100644
fdf7c0
--- a/super-ddf.c
fdf7c0
+++ b/super-ddf.c
fdf7c0
@@ -5125,13 +5125,16 @@ static struct mdinfo *ddf_activate_spare(struct active_array *a,
fdf7c0
 	 */
fdf7c0
 	vc = find_vdcr(ddf, a->info.container_member, rv->disk.raid_disk,
fdf7c0
 		       &n_bvd, &vcl;;
fdf7c0
-	if (vc == NULL)
fdf7c0
+	if (vc == NULL) {
fdf7c0
+		free(rv);
fdf7c0
 		return NULL;
fdf7c0
+	}
fdf7c0
 
fdf7c0
 	mu = xmalloc(sizeof(*mu));
fdf7c0
 	if (posix_memalign(&mu->space, 512, sizeof(struct vcl)) != 0) {
fdf7c0
 		free(mu);
fdf7c0
-		mu = NULL;
fdf7c0
+		free(rv);
fdf7c0
+		return NULL;
fdf7c0
 	}
fdf7c0
 
fdf7c0
 	mu->len = ddf->conf_rec_len * 512 * vcl->conf.sec_elmnt_count;
fdf7c0
@@ -5161,6 +5164,8 @@ static struct mdinfo *ddf_activate_spare(struct active_array *a,
fdf7c0
 			pr_err("BUG: can't find disk %d (%d/%d)\n",
fdf7c0
 			       di->disk.raid_disk,
fdf7c0
 			       di->disk.major, di->disk.minor);
fdf7c0
+			free(mu);
fdf7c0
+			free(rv);
fdf7c0
 			return NULL;
fdf7c0
 		}
fdf7c0
 		vc->phys_refnum[i_prim] = ddf->phys->entries[dl->pdnum].refnum;
fdf7c0
-- 
01ff50
2.38.1
fdf7c0