Skip to content

Commit

Permalink
can: dev: can_restart: fix use after free bug
Browse files Browse the repository at this point in the history
After calling netif_rx_ni(skb), dereferencing skb is unsafe.
Especially, the can_frame cf which aliases skb memory is accessed
after the netif_rx_ni() in:
      stats->rx_bytes += cf->len;

Reordering the lines solves the issue.

Fixes: 39549ee ("can: CAN Network device driver and Netlink interface")
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Vincent Mailhol <[email protected]>
Signed-off-by: Marc Kleine-Budde <[email protected]>
  • Loading branch information
vincent-mailhol authored and marckleinebudde committed Jan 20, 2021
1 parent 9c30ae8 commit 03f16c5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/net/can/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,11 +592,11 @@ static void can_restart(struct net_device *dev)

cf->can_id |= CAN_ERR_RESTARTED;

netif_rx_ni(skb);

stats->rx_packets++;
stats->rx_bytes += cf->len;

netif_rx_ni(skb);

restart:
netdev_dbg(dev, "restarted\n");
priv->can_stats.restarts++;
Expand Down

0 comments on commit 03f16c5

Please sign in to comment.