ppdev: Add an error check in register_device
Subsystems (2)
PATCH v2 1/1 ppdev: Add an error check in register_device
In register_device, the return value of ida_simple_get is unchecked, in witch ida_simple_get will use an invalid index value.
To address this issue, index should be checked after ida_simple_get. When the index value is abnormal, a warning message should be printed, the port should be dropped, and the value should be recorded, then jump to 'err'.
---
V2:
* In patch V2, we found that parport_find_number implicitly calls parport_get_port(). So when dealing with abnormal index values, we should call parport_put_port() to throw away the reference to the port.
--- drivers/char/ppdev.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/char/ppdev.c +7 -0
@@ -300,6 +300,13 @@ static int register_device(int minor, struct pp_struct *pp) } index =ida_simple_get (&ida_index,0 ,0 ,GFP_KERNEL ); +if (index <0 ) { +pr_warn ("%s: failed to get index!\n" , name); +parport_put_port (port); + rc = index; + goto err; + } +memset (&ppdev_cb,0 ,sizeof (ppdev_cb)); ppdev_cb.irq_func = pp_irq; ppdev_cb.flags = (pp->flags &PP_EXCL ) ?PARPORT_FLAG_EXCL :0 ;
Signature · 1 line
2.34.1
Le 07/04/2024 à 10:03, Huai-Yuan Liu a écrit :
Quoted 23 lines
In
register_device, the return value ofida_simple_getis unchecked, in witchida_simple_getwill use an invalid index value.To address this issue, index should be checked after
ida_simple_get. When the index value is abnormal, a warning message should be printed, the port should be dropped, and the value should be recorded, then jump to 'err'.Fixes 9a69645dde11 ("ppdev: fix registering same device name")Signed-off-by Huai-Yuan Liu <[email protected]>---
V2:
* In patch V2, we found thatparport_find_numberimplicitly callsparport_get_port(). So when dealing with abnormal index values, we should callparport_put_port()to throw away the reference to the port.--- drivers/char/ppdev.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/char/ppdev.c +0
-0
drivers/char/ppdev.c static int register_device(int minor, struct pp_struct *pp) · line 305
Quoted 6 lines
drivers/char/ppdev.c +3
-0@@ -300,6 +300,13 @@ static int register_device(int minor, struct pp_struct *pp) } index =ida_simple_get (&ida_index,0 ,0 ,GFP_KERNEL ); +if (index <0 ) { +pr_warn ("%s: failed to get index!\n" , name); +parport_put_port (port);
Hi,
I think that a new label should be added, just before the 'err' label, and move this parport_put_port() call there, as well as the one just after parport_register_dev_model().
CJ
Quoted 7 lines
drivers/char/ppdev.c +4
-0+ rc = index; + goto err; + } +memset (&ppdev_cb,0 ,sizeof (ppdev_cb)); ppdev_cb.irq_func = pp_irq; ppdev_cb.flags = (pp->flags &PP_EXCL ) ?PARPORT_FLAG_EXCL :0 ;
Hi,
Thanks for CJ's suggestion. I have modified and sent the [PATCH V3] email.
Best regards,
Liu.