netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] can: etas_es58x: Fix potential null pointer dereference on pointer cf
@ 2021-04-15  8:55 Colin King
  2021-04-15  9:03 ` Marc Kleine-Budde
  0 siblings, 1 reply; 3+ messages in thread
From: Colin King @ 2021-04-15  8:55 UTC (permalink / raw)
  To: Wolfgang Grandegger, Marc Kleine-Budde, David S . Miller,
	Jakub Kicinski, Vincent Mailhol, Arunachalam Santhanam,
	linux-can, netdev
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The pointer cf is being null checked earlier in the code, however the
update of the rx_bytes statistics is dereferencing cf without null
checking cf.  Fix this by moving the statement into the following code
block that has a null cf check.

Addresses-Coverity: ("Dereference after null check")
Fixes: 8537257874e9 ("can: etas_es58x: add core support for ETAS ES58X CAN USB interfaces")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/net/can/usb/etas_es58x/es58x_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/usb/etas_es58x/es58x_core.c b/drivers/net/can/usb/etas_es58x/es58x_core.c
index 7222b3b6ca46..5198e1d6b6ad 100644
--- a/drivers/net/can/usb/etas_es58x/es58x_core.c
+++ b/drivers/net/can/usb/etas_es58x/es58x_core.c
@@ -856,9 +856,10 @@ int es58x_rx_err_msg(struct net_device *netdev, enum es58x_err error,
 	 * consistency.
 	 */
 	netdev->stats.rx_packets++;
-	netdev->stats.rx_bytes += cf->can_dlc;
 
 	if (cf) {
+		netdev->stats.rx_bytes += cf->can_dlc;
+
 		if (cf->data[1])
 			cf->can_id |= CAN_ERR_CRTL;
 		if (cf->data[2] || cf->data[3]) {
-- 
2.30.2


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

* Re: [PATCH][next] can: etas_es58x: Fix potential null pointer dereference on pointer cf
  2021-04-15  8:55 [PATCH][next] can: etas_es58x: Fix potential null pointer dereference on pointer cf Colin King
@ 2021-04-15  9:03 ` Marc Kleine-Budde
  2021-04-15  9:12   ` Colin Ian King
  0 siblings, 1 reply; 3+ messages in thread
From: Marc Kleine-Budde @ 2021-04-15  9:03 UTC (permalink / raw)
  To: Colin King
  Cc: Wolfgang Grandegger, David S . Miller, Jakub Kicinski,
	Vincent Mailhol, Arunachalam Santhanam, linux-can, netdev,
	kernel-janitors, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1025 bytes --]

On 15.04.2021 09:55:35, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The pointer cf is being null checked earlier in the code, however the
> update of the rx_bytes statistics is dereferencing cf without null
> checking cf.  Fix this by moving the statement into the following code
> block that has a null cf check.
> 
> Addresses-Coverity: ("Dereference after null check")
> Fixes: 8537257874e9 ("can: etas_es58x: add core support for ETAS ES58X CAN USB interfaces")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

A somewhat different fix is already in net-next/master

https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=e2b1e4b532abdd39bfb7313146153815e370d60c

Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH][next] can: etas_es58x: Fix potential null pointer dereference on pointer cf
  2021-04-15  9:03 ` Marc Kleine-Budde
@ 2021-04-15  9:12   ` Colin Ian King
  0 siblings, 0 replies; 3+ messages in thread
From: Colin Ian King @ 2021-04-15  9:12 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: Wolfgang Grandegger, David S . Miller, Jakub Kicinski,
	Vincent Mailhol, Arunachalam Santhanam, linux-can, netdev,
	kernel-janitors, linux-kernel

On 15/04/2021 10:03, Marc Kleine-Budde wrote:
> On 15.04.2021 09:55:35, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> The pointer cf is being null checked earlier in the code, however the
>> update of the rx_bytes statistics is dereferencing cf without null
>> checking cf.  Fix this by moving the statement into the following code
>> block that has a null cf check.
>>
>> Addresses-Coverity: ("Dereference after null check")
>> Fixes: 8537257874e9 ("can: etas_es58x: add core support for ETAS ES58X CAN USB interfaces")
>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> 
> A somewhat different fix is already in net-next/master
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=e2b1e4b532abdd39bfb7313146153815e370d60c

+1 on that

> 
> Marc
> 


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

end of thread, other threads:[~2021-04-15  9:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-15  8:55 [PATCH][next] can: etas_es58x: Fix potential null pointer dereference on pointer cf Colin King
2021-04-15  9:03 ` Marc Kleine-Budde
2021-04-15  9:12   ` Colin Ian King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).