Input: egalax: potential NULL dereference on error
Subsystems (3)
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.
drivers/input/touchscreen/egalax_ts_serial.c +6 -3
@@ -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; }
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')Signed-off-by Dan Carpenter <[email protected]>drivers/input/touchscreen/egalax_ts_serial.c +6
-4@@ -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
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
Dmitry Torokhov
maintainerHi 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')Signed-off-by Dan Carpenter <[email protected]>drivers/input/touchscreen/egalax_ts_serial.c +5
-2@@ -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