Skip to contentSkip to conversation

HID: core: fix NULL pointer dereference

PATCH Applied Gustavo A. R. Silva 3 participants 3 messages Aug 29, 2018 – Sep 5, 2018 HID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 HID: core: fix NULL pointer dereference

There is a NULL pointer dereference in case memory resources for *parse* are not successfully allocated.

Fix this by adding a new goto label and make the execution path jump to it in case vzalloc() fails.

Addresses-Coverity-ID: 1473081 ("Dereference after null check")

Fixes b2dd9f2e5a8a ("HID: core: fix memory leak on probe")
---
 drivers/hid/hid-core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hid/hid-core.c +2 -1
index 4548dae..5bec924 100644
@@ -1000,7 +1000,7 @@ int hid_open_report(struct hid_device *device)
 	parser = vzalloc(sizeof(struct hid_parser));
 	if (!parser) {
 		ret = -ENOMEM;
-		goto err;
+		goto alloc_err;
 	}
 
 	parser->device = device;
@@ -1049,6 +1049,7 @@ int hid_open_report(struct hid_device *device)
 	hid_err(device, "item fetching failed at offset %d\n", (int)(end - start));
 err:
 	kfree(parser->collection_stack);
+alloc_err:
 	vfree(parser);
 	hid_close_report(device);
 	return ret;
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Gustavo A. R. Silva

There is a NULL pointer dereference in case memory resources for *parse* are not successfully allocated.

Fix this by adding a new goto label and make the execution path jump to it in case vzalloc() fails.

Addresses-Coverity-ID: 1473081 ("Dereference after null check")

Fixes b2dd9f2e5a8a ("HID: core: fix memory leak on probe")

--
Stefan

Quoted 25 lines
---
 drivers/hid/hid-core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hid/hid-core.c +2 -1
index 4548dae..5bec924 100644
@@ -1000,7 +1000,7 @@ int hid_open_report(struct hid_device *device)
 	parser = vzalloc(sizeof(struct hid_parser));
 	if (!parser) {
 		ret = -ENOMEM;
-		goto err;
+		goto alloc_err;
 	}
 
 	parser->device = device;
@@ -1049,6 +1049,7 @@ int hid_open_report(struct hid_device *device)
 	hid_err(device, "item fetching failed at offset %d\n", (int)(end - start));
 err:
 	kfree(parser->collection_stack);
+alloc_err:
 	vfree(parser);
 	hid_close_report(device);
 	return ret;
maintainer Applied
#2 lore raw
In reply to Gustavo A. R. Silva
Quoted 27 lines · Gustavo A. R. Silva

There is a NULL pointer dereference in case memory resources for *parse* are not successfully allocated.

Fix this by adding a new goto label and make the execution path jump to it in case vzalloc() fails.

Addresses-Coverity-ID: 1473081 ("Dereference after null check")

Fixes b2dd9f2e5a8a ("HID: core: fix memory leak on probe")
---
 drivers/hid/hid-core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hid/hid-core.c +1 -1
index 4548dae..5bec924 100644
@@ -1000,7 +1000,7 @@ int hid_open_report(struct hid_device *device)
 	parser = vzalloc(sizeof(struct hid_parser));
 	if (!parser) {
 		ret = -ENOMEM;
-		goto err;
+		goto alloc_err;
 	}
 
 	parser->device = device;

drivers/hid/hid-core.c int hid_open_report(struct hid_device *device) · line 1055

Quoted 7 lines
drivers/hid/hid-core.c +1 -0
@@ -1049,6 +1049,7 @@ int hid_open_report(struct hid_device *device)
 	hid_err(device, "item fetching failed at offset %d\n", (int)(end - start));
 err:
 	kfree(parser->collection_stack);
+alloc_err:
 	vfree(parser);
 	hid_close_report(device);
 	return ret;

Queued in for-4.19/fixes. Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs