net: usb: smsc75xx: Move packet length check to prevent kernel panic in skb_pull
Packet length check needs to be located after size and align_count
calculation to prevent kernel panic in skb_pull() in case
rx_cmd_a & RX_CMD_A_RED evaluates to true.
Fixes: d8b2283189
("net: usb: smsc75xx: Limit packet length to skb->len")
Signed-off-by: Szymon Heidrich <szymon.heidrich@gmail.com>
Link: https://lore.kernel.org/r/20230316110540.77531-1-szymon.heidrich@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Родитель
8a2618e14f
Коммит
43ffe6cacc
|
@ -2200,6 +2200,13 @@ static int smsc75xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
|
||||||
size = (rx_cmd_a & RX_CMD_A_LEN) - RXW_PADDING;
|
size = (rx_cmd_a & RX_CMD_A_LEN) - RXW_PADDING;
|
||||||
align_count = (4 - ((size + RXW_PADDING) % 4)) % 4;
|
align_count = (4 - ((size + RXW_PADDING) % 4)) % 4;
|
||||||
|
|
||||||
|
if (unlikely(size > skb->len)) {
|
||||||
|
netif_dbg(dev, rx_err, dev->net,
|
||||||
|
"size err rx_cmd_a=0x%08x\n",
|
||||||
|
rx_cmd_a);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (unlikely(rx_cmd_a & RX_CMD_A_RED)) {
|
if (unlikely(rx_cmd_a & RX_CMD_A_RED)) {
|
||||||
netif_dbg(dev, rx_err, dev->net,
|
netif_dbg(dev, rx_err, dev->net,
|
||||||
"Error rx_cmd_a=0x%08x\n", rx_cmd_a);
|
"Error rx_cmd_a=0x%08x\n", rx_cmd_a);
|
||||||
|
@ -2212,8 +2219,7 @@ static int smsc75xx_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
|
||||||
dev->net->stats.rx_frame_errors++;
|
dev->net->stats.rx_frame_errors++;
|
||||||
} else {
|
} else {
|
||||||
/* MAX_SINGLE_PACKET_SIZE + 4(CRC) + 2(COE) + 4(Vlan) */
|
/* MAX_SINGLE_PACKET_SIZE + 4(CRC) + 2(COE) + 4(Vlan) */
|
||||||
if (unlikely(size > (MAX_SINGLE_PACKET_SIZE + ETH_HLEN + 12) ||
|
if (unlikely(size > (MAX_SINGLE_PACKET_SIZE + ETH_HLEN + 12))) {
|
||||||
size > skb->len)) {
|
|
||||||
netif_dbg(dev, rx_err, dev->net,
|
netif_dbg(dev, rx_err, dev->net,
|
||||||
"size err rx_cmd_a=0x%08x\n",
|
"size err rx_cmd_a=0x%08x\n",
|
||||||
rx_cmd_a);
|
rx_cmd_a);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче