Skip to contentSkip to conversation

dlpar: Fix a missing-check bug in dlpar_parse_cc_property()

PATCH Applied Gen Zhang 3 participants 3 messages May 26, 2019 – Jun 3, 2019 PowerPC

lore
Share & tools
lore

Gen Zhang

author
#0 lore raw

PATCH 1/1 dlpar: Fix a missing-check bug in dlpar_parse_cc_property()

In dlpar_parse_cc_property(), 'prop->name' is allocated by kstrdup(). kstrdup() may return NULL, so it should be checked and handle error. And prop should be freed if 'prop->name' is NULL.

---

arch/powerpc/platforms/pseries/dlpar.c +4 -0
index 1795804..c852024 100644
@@ -61,6 +61,10 @@ static struct property *dlpar_parse_cc_property(struct cc_workarea *ccwa)
 
 	name = (char *)ccwa + be32_to_cpu(ccwa->name_offset);
 	prop->name = kstrdup(name, GFP_KERNEL);
+	if (!prop->name) {
+		dlpar_free_cc_property(prop);
+		return NULL;
+	}
 
 	prop->length = be32_to_cpu(ccwa->prop_length);
 	value = (char *)ccwa + be32_to_cpu(ccwa->prop_offset);

---

Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Gen Zhang

In dlpar_parse_cc_property(), 'prop->name' is allocated by kstrdup(). kstrdup() may return NULL, so it should be checked and handle error. And prop should be freed if 'prop->name' is NULL.

---

arch/powerpc/platforms/pseries/dlpar.c +0 -0
index 1795804..c852024 100644

arch/powerpc/platforms/pseries/dlpar.c static struct property *dlpar_parse_cc_property(struct cc_workarea *ccwa) · line 67

Quoted 7 lines
arch/powerpc/platforms/pseries/dlpar.c +4 -0
@@ -61,6 +61,10 @@ static struct property *dlpar_parse_cc_property(struct cc_workarea *ccwa)
 
 	name = (char *)ccwa + be32_to_cpu(ccwa->name_offset);
 	prop->name = kstrdup(name, GFP_KERNEL);
+	if (!prop->name) {
+		dlpar_free_cc_property(prop);
+		return NULL;
+	}