mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH V2] ppdev: Add an error check in register_device
@ 2024-04-07  8:03 Huai-Yuan Liu
  2024-04-07  9:49 ` Christophe JAILLET
  0 siblings, 1 reply; 3+ messages in thread
From: Huai-Yuan Liu @ 2024-04-07  8:03 UTC (permalink / raw)
  To: sudipm.mukherjee, arnd, gregkh; +Cc: linux-kernel, baijiaju1990, Huai-Yuan Liu

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'.

Fixes: 9a69645dde11 ("ppdev: fix registering same device name")
Signed-off-by: Huai-Yuan Liu <qq810974084@gmail.com>
---
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(+)

diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c
index 4c188e9e477c..ac5a93d39fbd 100644
--- a/drivers/char/ppdev.c
+++ b/drivers/char/ppdev.c
@@ -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;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH V2] ppdev: Add an error check in register_device
  2024-04-07  8:03 [PATCH V2] ppdev: Add an error check in register_device Huai-Yuan Liu
@ 2024-04-07  9:49 ` Christophe JAILLET
  2024-04-10 10:41   ` Huai-Yuan Liu
  0 siblings, 1 reply; 3+ messages in thread
From: Christophe JAILLET @ 2024-04-07  9:49 UTC (permalink / raw)
  To: Huai-Yuan Liu, sudipm.mukherjee, arnd, gregkh; +Cc: linux-kernel, baijiaju1990

Le 07/04/2024 à 10:03, Huai-Yuan Liu a écrit :
> 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'.
> 
> Fixes: 9a69645dde11 ("ppdev: fix registering same device name")
> Signed-off-by: Huai-Yuan Liu <qq810974084@gmail.com>
> ---
> 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(+)
> 
> diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c
> index 4c188e9e477c..ac5a93d39fbd 100644
> --- a/drivers/char/ppdev.c
> +++ b/drivers/char/ppdev.c
> @@ -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

> +		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;


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH V2] ppdev: Add an error check in register_device
  2024-04-07  9:49 ` Christophe JAILLET
@ 2024-04-10 10:41   ` Huai-Yuan Liu
  0 siblings, 0 replies; 3+ messages in thread
From: Huai-Yuan Liu @ 2024-04-10 10:41 UTC (permalink / raw)
  To: Christophe JAILLET; +Cc: sudipm.mukherjee, arnd, gregkh, linux-kernel

Hi,

Thanks for CJ's suggestion. I have modified and sent the
[PATCH V3] email.

Best regards,

Liu.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-10 10:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-07  8:03 [PATCH V2] ppdev: Add an error check in register_device Huai-Yuan Liu
2024-04-07  9:49 ` Christophe JAILLET
2024-04-10 10:41   ` Huai-Yuan Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®