Skip to contentSkip to conversation

Input: egalax: potential NULL dereference on error

PATCH In review Dan Carpenter 3 participants 4 messages Dec 19, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Input: egalax: potential NULL dereference on error

We didn't check input_allocate_device() for failures so it could lead to a NULL deref.

Fixes 6b0f8f9c52ef ('Input: add eGalaxTouch serial touchscreen driver')
drivers/input/touchscreen/egalax_ts_serial.c +6 -3
index a078c1c..8becd26 100644
@@ -104,10 +104,13 @@ static int egalax_connect(struct serio *serio, struct serio_driver *drv)
 	int error;
 
 	egalax = kzalloc(sizeof(struct egalax), GFP_KERNEL);
+	if (!egalax)
+		return -ENOMEM;
+
 	input_dev = input_allocate_device();
-	if (!egalax) {
+	if (!input_dev) {
 		error = -ENOMEM;
-		goto err_free_mem;
+		goto err_free_egalax;
 	}
 
 	egalax->serio = serio;
@@ -145,8 +148,8 @@ err_close_serio:
 	serio_close(serio);
 err_reset_drvdata:
 	serio_set_drvdata(serio, NULL);
-err_free_mem:
 	input_free_device(input_dev);
+err_free_egalax:
 	kfree(egalax);
 	return error;
 }
#1 lore raw
Quoted 2 lines · Dan Carpenter

We didn't check input_allocate_device() for failures so it could lead to a NULL deref.

The patch does several other things...

julia

Quoted 39 lines
Fixes 6b0f8f9c52ef ('Input: add eGalaxTouch serial touchscreen driver')
drivers/input/touchscreen/egalax_ts_serial.c +6 -4
index a078c1c..8becd26 100644
@@ -104,10 +104,13 @@ static int egalax_connect(struct serio *serio, struct serio_driver *drv)
 	int error;
 
 	egalax = kzalloc(sizeof(struct egalax), GFP_KERNEL);
+	if (!egalax)
+		return -ENOMEM;
+
 	input_dev = input_allocate_device();
-	if (!egalax) {
+	if (!input_dev) {
 		error = -ENOMEM;
-		goto err_free_mem;
+		goto err_free_egalax;
 	}
 
 	egalax->serio = serio;
@@ -145,8 +148,8 @@ err_close_serio:
 	serio_close(serio);
 err_reset_drvdata:
 	serio_set_drvdata(serio, NULL);
-err_free_mem:
 	input_free_device(input_dev);
+err_free_egalax:
 	kfree(egalax);
 	return error;
 }
--

To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#3 lore raw
In reply to Dan Carpenter

Hi Dan,

Quoted 27 lines · Dan Carpenter

We didn't check input_allocate_device() for failures so it could lead to a NULL deref.

Fixes 6b0f8f9c52ef ('Input: add eGalaxTouch serial touchscreen driver')
drivers/input/touchscreen/egalax_ts_serial.c +5 -2
index a078c1c..8becd26 100644
@@ -104,10 +104,13 @@ static int egalax_connect(struct serio *serio, struct serio_driver *drv)
 	int error;
 
 	egalax = kzalloc(sizeof(struct egalax), GFP_KERNEL);
+	if (!egalax)
+		return -ENOMEM;
+
 	input_dev = input_allocate_device();
-	if (!egalax) {
+	if (!input_dev) {
 		error = -ENOMEM;
-		goto err_free_mem;
+		goto err_free_egalax;
 	}
 
 	egalax->serio = serio;

drivers/input/touchscreen/egalax_ts_serial.c err_close_serio: · line 155

Quoted 9 lines
drivers/input/touchscreen/egalax_ts_serial.c +1 -1
@@ -145,8 +148,8 @@ err_close_serio:
 	serio_close(serio);
 err_reset_drvdata:
 	serio_set_drvdata(serio, NULL);
-err_free_mem:
 	input_free_device(input_dev);
+err_free_egalax:
 	kfree(egalax);
 	return error;
 }

This is my screwup. The original code had the "if (!egalax || !input_dev)" check but I was considering using devm (but then decided against it) but forget to adjust the check back. I'll put it back in.

Thank you for noticing!

Signature · 1 line
Dmitry
#2 lore raw
In reply to Julia Lawall
Quoted 6 lines · Julia Lawall
Quoted 2 lines · Dan Carpenter

We didn't check input_allocate_device() for failures so it could lead to a NULL deref.

The patch does several other things...

Not really. It's all part of fixing the input_allocate_device() check.

regards,
dan carpenter