Skip to contentSkip to conversation

Fix null pointer deref

PATCH In review Alexander Grund 2 participants 3 messages Mar 23, 2025 – Mar 27, 2025 CAN network drivers

lore
Share & tools
lore
#0 lore raw

cover Fix null pointer deref

From: Alexander Grund <[email protected]>

The patch
"can: sun4i_can: sun4i_can_err(): call can_change_state() even if cf is NULL" assumes the following patch which isn't applied yet to cip-4.4

Marc Kleine-Budde (1):
can: dev: make can_change_state() robust to be called with cf == NULL

 drivers/net/can/dev.c | 3 +++
 1 file changed, 3 insertions(+)
Signature · 1 line
2.40.1
#1 lore raw

PATCH 1/1 can: dev: make can_change_state() robust to be called with cf == NULL

From: Marc Kleine-Budde <[email protected]>

In OOM situations where no skb can be allocated, can_change_state() may be called with cf == NULL. As this function updates the state and error statistics it's not an option to skip the call to can_change_state() in OOM situations.

This patch makes can_change_state() robust, so that it can be called with cf == NULL.

---
 drivers/net/can/dev.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/can/dev.c +3 -0
index 2835aeb11c9f..eeeba3f5c8b4 100644
@@ -341,6 +341,9 @@ void can_change_state(struct net_device *dev, struct can_frame *cf,
 	can_update_state_error_stats(dev, new_state);
 	priv->state = new_state;
 
+	if (!cf)
+		return;
+
 	if (unlikely(new_state == CAN_STATE_BUS_OFF)) {
 		cf->can_id |= CAN_ERR_BUSOFF;
 		return;
Signature · 1 line
2.40.1
#2 lore raw
In reply to Alexander Grund
Quoted 7 lines · CET Alexander Grund

The patch
"can: sun4i_can: sun4i_can_err(): call can_change_state() even if cf is NULL" assumes the following patch which isn't applied yet to cip-4.4

Marc Kleine-Budde (1):
can: dev: make can_change_state() robust to be called with cf == NULL

Picked it, thanks!

CU
Uli