Skip to contentSkip to conversation

can: remove WARN() statement from list operation sanity check

PATCH In review Oliver Hartkopp 2 participants 4 messages Nov 26, 2020 – Nov 27, 2020

Subsystems (4)
lore
Share & tools
lore

Oliver Hartkopp

author maintainer
#0 lore raw

PATCH 1/1 can: remove WARN() statement from list operation sanity check

To detect potential bugs in CAN protocol implementations (double removal of receiver entries) a WARN() statement has been used if no matching list item was found for removal.

The fault injection issued by syzkaller was able to create a situation where the closing of a socket runs simultaneously to the notifier call chain for removing the CAN network device in use.

This case is very unlikely in real life but it doesn't break anything. Therefore we just replace the WARN() statement with pr_warn() to preserve the notification for the CAN protocol development.

---
 net/can/af_can.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
net/can/af_can.c +5 -2
index 5d124c155904..7c5ccdec89e1 100644
@@ -539,14 +539,17 @@ void can_rx_unregister(struct net *net, struct net_device *dev, canid_t can_id,
 			break;
 	}
 
 	/* Check for bugs in CAN protocol implementations using af_can.c:
 	 * 'rcv' will be NULL if no matching list item was found for removal.
+	 * As this case may potentially happen when closing a socket while
+	 * the notifier for removing the CAN netdev is running we just print
+	 * a warning here. Reported by syskaller (see commit message)
 	 */
 	if (!rcv) {
-		WARN(1, "BUG: receive list entry not found for dev %s, id %03X, mask %03X\n",
-		     DNAME(dev), can_id, mask);
+		pr_warn("can: receive list entry not found for dev %s, id %03X, mask %03X\n",
+			DNAME(dev), can_id, mask);
 		goto out;
 	}
 
 	hlist_del_rcu(&rcv->list);
 	dev_rcv_lists->entries--;
Signature · 1 line
2.29.2
#1 lore raw
Quoted 8 lines · Oliver Hartkopp

To detect potential bugs in CAN protocol implementations (double removal of receiver entries) a WARN() statement has been used if no matching list item was found for removal.

The fault injection issued by syzkaller was able to create a situation where the closing of a socket runs simultaneously to the notifier call chain for removing the CAN network device in use.

Quoted 8 lines

This case is very unlikely in real life but it doesn't break anything. Therefore we just replace the WARN() statement with pr_warn() to preserve the notification for the CAN protocol development.

applied to can/testing.

tnx,
Marc

Signature · 4 lines
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 |
#2 lore raw
In reply to Oliver Hartkopp
Quoted 25 lines · Oliver Hartkopp

To detect potential bugs in CAN protocol implementations (double removal of receiver entries) a WARN() statement has been used if no matching list item was found for removal.

The fault injection issued by syzkaller was able to create a situation where the closing of a socket runs simultaneously to the notifier call chain for removing the CAN network device in use.

This case is very unlikely in real life but it doesn't break anything. Therefore we just replace the WARN() statement with pr_warn() to preserve the notification for the CAN protocol development.

---
 net/can/af_can.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
net/can/af_can.c +0 -0
index 5d124c155904..7c5ccdec89e1 100644

net/can/af_can.c void can_rx_unregister(struct net *net, struct net_device *dev, canid_t can_id, · line 546

Quoted 8 lines
net/can/af_can.c +3 -0
@@ -539,14 +539,17 @@ void can_rx_unregister(struct net *net, struct net_device *dev, canid_t can_id,
 			break;
 	}
 
 	/* Check for bugs in CAN protocol implementations using af_can.c:
 	 * 'rcv' will be NULL if no matching list item was found for removal.
+	 * As this case may potentially happen when closing a socket while
+	 * the notifier for removing the CAN netdev is running we just print
+	 * a warning here. Reported by syskaller (see commit message)

I've removed the "Reported by syskaller (see commit message)" while applying the patch, to keep this comment short and to the point. Use tig/git blame (or any other future tool) to figure out the commit message for details :D

net/can/af_can.c void can_rx_unregister(struct net *net, struct net_device *dev, canid_t can_id, · line 555

Quoted 12 lines
net/can/af_can.c +2 -2
 	 */
 	if (!rcv) {
-		WARN(1, "BUG: receive list entry not found for dev %s, id %03X, mask %03X\n",
-		     DNAME(dev), can_id, mask);
+		pr_warn("can: receive list entry not found for dev %s, id %03X, mask %03X\n",
+			DNAME(dev), can_id, mask);
 		goto out;
 	}
 
 	hlist_del_rcu(&rcv->list);
 	dev_rcv_lists->entries--;

Marc

Signature · 4 lines
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 |
author maintainer
#3 lore raw
Quoted 9 lines · Marc Kleine-Budde

net/can/af_can.c void can_rx_unregister(struct net *net, struct net_device *dev, canid_t can_id, · line 546

Quoted 5 lines

/* Check for bugs in CAN protocol implementations using af_can.c:
* 'rcv' will be NULL if no matching list item was found for removal.

net/can/af_can.c +3 -0
+	 * As this case may potentially happen when closing a socket while
+	 * the notifier for removing the CAN netdev is running we just print
+	 * a warning here. Reported by syskaller (see commit message)

I've removed the "Reported by syskaller (see commit message)" while applying the patch, to keep this comment short and to the point. Use tig/git blame (or any other future tool) to figure out the commit message for details :D

Is fine for me ;-)

Thanks Marc!