diff mbox series

can: af_can: fix NULL pointer dereference in can_rcv_filter

Message ID 20221206200851.2825-1-socketcan@hartkopp.net (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series can: af_can: fix NULL pointer dereference in can_rcv_filter | expand

Checks

Context Check Description
netdev/tree_selection success Series ignored based on subject

Commit Message

Oliver Hartkopp Dec. 6, 2022, 8:08 p.m. UTC
Analogue to commit 8aa59e355949 ("can: af_can: fix NULL pointer dereference
in can_rx_register()") we need to check for a missing initialization of
ml_priv in the receieve path of CAN frames. Since commit 4e096a18867a
("net: introduce CAN specific pointer in the struct net_device") the check
for dev->type to be ARPHRD_CAN is not sufficient anymore since bonding or
tun netdevices claim to be CAN devices but do not initialize ml_priv
accordingly.

Fixes: 4e096a18867a ("net: introduce CAN specific pointer in the struct net_device")
Reported-by: syzbot+2d7f58292cb5b29eb5ad@syzkaller.appspotmail.com
Reported-by: Wei Chen <harperchen1110@gmail.com>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
 net/can/af_can.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/net/can/af_can.c b/net/can/af_can.c
index 27dcdcc0b808..c69168f11e44 100644
--- a/net/can/af_can.c
+++ b/net/can/af_can.c
@@ -675,11 +675,11 @@  static void can_receive(struct sk_buff *skb, struct net_device *dev)
 }
 
 static int can_rcv(struct sk_buff *skb, struct net_device *dev,
 		   struct packet_type *pt, struct net_device *orig_dev)
 {
-	if (unlikely(dev->type != ARPHRD_CAN || (!can_is_can_skb(skb)))) {
+	if (unlikely(dev->type != ARPHRD_CAN || !can_get_ml_priv(dev) || !can_is_can_skb(skb))) {
 		pr_warn_once("PF_CAN: dropped non conform CAN skbuff: dev type %d, len %d\n",
 			     dev->type, skb->len);
 
 		kfree_skb(skb);
 		return NET_RX_DROP;
@@ -690,11 +690,11 @@  static int can_rcv(struct sk_buff *skb, struct net_device *dev,
 }
 
 static int canfd_rcv(struct sk_buff *skb, struct net_device *dev,
 		     struct packet_type *pt, struct net_device *orig_dev)
 {
-	if (unlikely(dev->type != ARPHRD_CAN || (!can_is_canfd_skb(skb)))) {
+	if (unlikely(dev->type != ARPHRD_CAN || !can_get_ml_priv(dev) || !can_is_canfd_skb(skb))) {
 		pr_warn_once("PF_CAN: dropped non conform CAN FD skbuff: dev type %d, len %d\n",
 			     dev->type, skb->len);
 
 		kfree_skb(skb);
 		return NET_RX_DROP;
@@ -705,11 +705,11 @@  static int canfd_rcv(struct sk_buff *skb, struct net_device *dev,
 }
 
 static int canxl_rcv(struct sk_buff *skb, struct net_device *dev,
 		     struct packet_type *pt, struct net_device *orig_dev)
 {
-	if (unlikely(dev->type != ARPHRD_CAN || (!can_is_canxl_skb(skb)))) {
+	if (unlikely(dev->type != ARPHRD_CAN || !can_get_ml_priv(dev) || !can_is_canxl_skb(skb))) {
 		pr_warn_once("PF_CAN: dropped non conform CAN XL skbuff: dev type %d, len %d\n",
 			     dev->type, skb->len);
 
 		kfree_skb(skb);
 		return NET_RX_DROP;