Skip to content

Commit

Permalink
can: peak_usb: fix use after free bugs
Browse files Browse the repository at this point in the history
After calling peak_usb_netif_rx_ni(skb), dereferencing skb is unsafe.
Especially, the can_frame cf which aliases skb memory is accessed
after the peak_usb_netif_rx_ni().

Reordering the lines solves the issue.

Fixes: 0a25e1f ("can: peak_usb: add support for PEAK new CANFD USB adapters")
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 75854ca commit 50aca89
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions drivers/net/can/usb/peak_usb/pcan_usb_fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,11 @@ static int pcan_usb_fd_decode_canmsg(struct pcan_usb_fd_if *usb_if,
else
memcpy(cfd->data, rm->d, cfd->len);

peak_usb_netif_rx(skb, &usb_if->time_ref, le32_to_cpu(rm->ts_low));

netdev->stats.rx_packets++;
netdev->stats.rx_bytes += cfd->len;

peak_usb_netif_rx(skb, &usb_if->time_ref, le32_to_cpu(rm->ts_low));

return 0;
}

Expand Down Expand Up @@ -580,11 +580,11 @@ static int pcan_usb_fd_decode_status(struct pcan_usb_fd_if *usb_if,
if (!skb)
return -ENOMEM;

peak_usb_netif_rx(skb, &usb_if->time_ref, le32_to_cpu(sm->ts_low));

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

peak_usb_netif_rx(skb, &usb_if->time_ref, le32_to_cpu(sm->ts_low));

return 0;
}

Expand Down

0 comments on commit 50aca89

Please sign in to comment.