Skip to content

Commit 0acc442

Browse files
hartkoppmarckleinebudde
authored andcommitted
can: af_can: fix NULL pointer dereference in can_rcv_filter
Analogue to commit 8aa59e3 ("can: af_can: fix NULL pointer dereference in can_rx_register()") we need to check for a missing initialization of ml_priv in the receive path of CAN frames. Since commit 4e096a1 ("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: 4e096a1 ("net: introduce CAN specific pointer in the struct net_device") Reported-by: [email protected] Reported-by: Wei Chen <[email protected]> Signed-off-by: Oliver Hartkopp <[email protected]> Link: https://lore.kernel.org/all/[email protected] Cc: [email protected] Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent 1799c1b commit 0acc442

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

net/can/af_can.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ static void can_receive(struct sk_buff *skb, struct net_device *dev)
677677
static int can_rcv(struct sk_buff *skb, struct net_device *dev,
678678
struct packet_type *pt, struct net_device *orig_dev)
679679
{
680-
if (unlikely(dev->type != ARPHRD_CAN || (!can_is_can_skb(skb)))) {
680+
if (unlikely(dev->type != ARPHRD_CAN || !can_get_ml_priv(dev) || !can_is_can_skb(skb))) {
681681
pr_warn_once("PF_CAN: dropped non conform CAN skbuff: dev type %d, len %d\n",
682682
dev->type, skb->len);
683683

@@ -692,7 +692,7 @@ static int can_rcv(struct sk_buff *skb, struct net_device *dev,
692692
static int canfd_rcv(struct sk_buff *skb, struct net_device *dev,
693693
struct packet_type *pt, struct net_device *orig_dev)
694694
{
695-
if (unlikely(dev->type != ARPHRD_CAN || (!can_is_canfd_skb(skb)))) {
695+
if (unlikely(dev->type != ARPHRD_CAN || !can_get_ml_priv(dev) || !can_is_canfd_skb(skb))) {
696696
pr_warn_once("PF_CAN: dropped non conform CAN FD skbuff: dev type %d, len %d\n",
697697
dev->type, skb->len);
698698

@@ -707,7 +707,7 @@ static int canfd_rcv(struct sk_buff *skb, struct net_device *dev,
707707
static int canxl_rcv(struct sk_buff *skb, struct net_device *dev,
708708
struct packet_type *pt, struct net_device *orig_dev)
709709
{
710-
if (unlikely(dev->type != ARPHRD_CAN || (!can_is_canxl_skb(skb)))) {
710+
if (unlikely(dev->type != ARPHRD_CAN || !can_get_ml_priv(dev) || !can_is_canxl_skb(skb))) {
711711
pr_warn_once("PF_CAN: dropped non conform CAN XL skbuff: dev type %d, len %d\n",
712712
dev->type, skb->len);
713713

0 commit comments

Comments
 (0)