Skip to contentSkip to conversation

gpu: amdkfd: fix a missing check of kmemdup

PATCH In review Kangjie Lu 1 participant 2 messages Mar 9, 2019 – Mar 23, 2019

Subsystems (3)
lore
Share & tools
lore

Kangjie Lu

author
#0 lore raw

PATCH 1/1 gpu: amdkfd: fix a missing check of kmemdup

kmemdup could fail and return NULL. To avoid null pointer dereference, the fix checkes its return value and returns ENOMEM upon failures.

---
 drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +3 -0
index 2e7c44955f43..7ef62d4e7598 100644
@@ -404,6 +404,9 @@ static int kfd_parse_subtype_iolink(struct crat_subtype_iolink *iolink,
 			return -ENODEV;
 		/* same everything but the other direction */
 		props2 = kmemdup(props, sizeof(*props2), GFP_KERNEL);
+		if (!props2)
+			return -ENOMEM;
+
 		props2->node_from = id_to;
 		props2->node_to = id_from;
 		props2->kobj = NULL;
Signature · 1 line
2.17.1
author
#1 lore raw
Quoted 7 lines · Kangjie Lu

kmemdup could fail and return NULL. To avoid null pointer dereference, the fix checkes its return value and returns ENOMEM upon failures.

This is a NULL-pointer dereference issue.
Can someone review this patch? Thanks.

Quoted 23 lines

---
drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 3 +++

1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +3 -0
index 2e7c44955f43..7ef62d4e7598 100644
@@ -404,6 +404,9 @@ static int kfd_parse_subtype_iolink(struct crat_subtype_iolink *iolink,
 			return -ENODEV;
 		/* same everything but the other direction */
 		props2 = kmemdup(props, sizeof(*props2), GFP_KERNEL);
+		if (!props2)
+			return -ENOMEM;
+
 		props2->node_from = id_to;
 		props2->node_to = id_from;
 		props2->kobj = NULL;
Signature · 1 line
2.17.1