mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] can: etas_es58x: Add check for alloc_can_err_skb
@ 2023-09-01  8:27 Jiasheng Jiang
  2023-09-01 10:53 ` Vincent MAILHOL
  2023-09-01 11:12 ` Denis Kirjanov
  0 siblings, 2 replies; 3+ messages in thread
From: Jiasheng Jiang @ 2023-09-01  8:27 UTC (permalink / raw)
  To: mailhol.vincent, wg, mkl, davem, edumazet, kuba, pabeni,
	arunachalam.santhanam
  Cc: linux-can, netdev, linux-kernel, Jiasheng Jiang

Add check for the return value of alloc_can_err_skb in order to
avoid NULL pointer dereference.

Fixes: 8537257874e9 ("can: etas_es58x: add core support for ETAS ES58X CAN USB interfaces")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
 drivers/net/can/usb/etas_es58x/es58x_core.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/can/usb/etas_es58x/es58x_core.c b/drivers/net/can/usb/etas_es58x/es58x_core.c
index 0c7f7505632c..d694cb22d9f4 100644
--- a/drivers/net/can/usb/etas_es58x/es58x_core.c
+++ b/drivers/net/can/usb/etas_es58x/es58x_core.c
@@ -680,6 +680,8 @@ int es58x_rx_err_msg(struct net_device *netdev, enum es58x_err error,
 	}
 
 	skb = alloc_can_err_skb(netdev, &cf);
+	if (!skb)
+		return -ENOMEM;
 
 	switch (error) {
 	case ES58X_ERR_OK:	/* 0: No error */
-- 
2.25.1


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

* Re: [PATCH] can: etas_es58x: Add check for alloc_can_err_skb
  2023-09-01  8:27 [PATCH] can: etas_es58x: Add check for alloc_can_err_skb Jiasheng Jiang
@ 2023-09-01 10:53 ` Vincent MAILHOL
  2023-09-01 11:12 ` Denis Kirjanov
  1 sibling, 0 replies; 3+ messages in thread
From: Vincent MAILHOL @ 2023-09-01 10:53 UTC (permalink / raw)
  To: Jiasheng Jiang
  Cc: wg, mkl, davem, edumazet, kuba, pabeni, arunachalam.santhanam,
	linux-can, netdev, linux-kernel

On Fri. 1 Sept 2023 at 19:22, Jiasheng Jiang <jiasheng@iscas.ac.cn> wrote:
> Add check for the return value of alloc_can_err_skb in order to
> avoid NULL pointer dereference.
>
> Fixes: 8537257874e9 ("can: etas_es58x: add core support for ETAS ES58X CAN USB interfaces")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---
>  drivers/net/can/usb/etas_es58x/es58x_core.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/net/can/usb/etas_es58x/es58x_core.c b/drivers/net/can/usb/etas_es58x/es58x_core.c
> index 0c7f7505632c..d694cb22d9f4 100644
> --- a/drivers/net/can/usb/etas_es58x/es58x_core.c
> +++ b/drivers/net/can/usb/etas_es58x/es58x_core.c
> @@ -680,6 +680,8 @@ int es58x_rx_err_msg(struct net_device *netdev, enum es58x_err error,
>         }
>
>         skb = alloc_can_err_skb(netdev, &cf);
> +       if (!skb)
> +               return -ENOMEM;

NAK.

The checks on skb or cf are skipped intentionally here in order to
continue the error handling.

Later in this function, all the access to skb or cf and guarded by an:

        if (cf)

And if cf is not NULL, skb is also guaranteed not to be NULL. For
further details, please refer to this commit:

  https://git.kernel.org/torvalds/c/c8129487441e


Yours sincerely,
Vincent Mailhol

>         switch (error) {
>         case ES58X_ERR_OK:      /* 0: No error */
> --
> 2.25.1
>

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

* Re: [PATCH] can: etas_es58x: Add check for alloc_can_err_skb
  2023-09-01  8:27 [PATCH] can: etas_es58x: Add check for alloc_can_err_skb Jiasheng Jiang
  2023-09-01 10:53 ` Vincent MAILHOL
@ 2023-09-01 11:12 ` Denis Kirjanov
  1 sibling, 0 replies; 3+ messages in thread
From: Denis Kirjanov @ 2023-09-01 11:12 UTC (permalink / raw)
  To: Jiasheng Jiang, mailhol.vincent, wg, mkl, davem, edumazet, kuba,
	pabeni, arunachalam.santhanam
  Cc: linux-can, netdev, linux-kernel



On 9/1/23 11:27, Jiasheng Jiang wrote:
> Add check for the return value of alloc_can_err_skb in order to
> avoid NULL pointer dereference.
> 
> Fixes: 8537257874e9 ("can: etas_es58x: add core support for ETAS ES58X CAN USB interfaces")
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---
>  drivers/net/can/usb/etas_es58x/es58x_core.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/net/can/usb/etas_es58x/es58x_core.c b/drivers/net/can/usb/etas_es58x/es58x_core.c
> index 0c7f7505632c..d694cb22d9f4 100644
> --- a/drivers/net/can/usb/etas_es58x/es58x_core.c
> +++ b/drivers/net/can/usb/etas_es58x/es58x_core.c
> @@ -680,6 +680,8 @@ int es58x_rx_err_msg(struct net_device *netdev, enum es58x_err error,
>  	}
>  
>  	skb = alloc_can_err_skb(netdev, &cf);
> +	if (!skb)
> +		return -ENOMEM;

Should you adjust the stats for dropped packets as well?

>  
>  	switch (error) {
>  	case ES58X_ERR_OK:	/* 0: No error */

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

end of thread, other threads:[~2023-09-01 11:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-01  8:27 [PATCH] can: etas_es58x: Add check for alloc_can_err_skb Jiasheng Jiang
2023-09-01 10:53 ` Vincent MAILHOL
2023-09-01 11:12 ` Denis Kirjanov

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®