Skip to content

Commit 6190cce

Browse files
wdebruijgregkh
authored andcommitted
packet: in packet_snd start writing at link layer allocation
[ Upstream commit b84bbaf ] Packet sockets allow construction of packets shorter than dev->hard_header_len to accommodate protocols with variable length link layer headers. These packets are padded to dev->hard_header_len, because some device drivers interpret that as a minimum packet size. packet_snd reserves dev->hard_header_len bytes on allocation. SOCK_DGRAM sockets call skb_push in dev_hard_header() to ensure that link layer headers are stored in the reserved range. SOCK_RAW sockets do the same in tpacket_snd, but not in packet_snd. Syzbot was able to send a zero byte packet to a device with massive 116B link layer header, causing padding to cross over into skb_shinfo. Fix this by writing from the start of the llheader reserved range also in the case of packet_snd/SOCK_RAW. Update skb_set_network_header to the new offset. This also corrects it for SOCK_DGRAM, where it incorrectly double counted reserve due to the skb_push in dev_hard_header. Fixes: 9ed988c ("packet: validate variable length ll headers") Reported-by: [email protected] Signed-off-by: Willem de Bruijn <[email protected]> Signed-off-by: David S. Miller <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 2ef22bd commit 6190cce

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

net/packet/af_packet.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2910,13 +2910,15 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
29102910
if (skb == NULL)
29112911
goto out_unlock;
29122912

2913-
skb_set_network_header(skb, reserve);
2913+
skb_reset_network_header(skb);
29142914

29152915
err = -EINVAL;
29162916
if (sock->type == SOCK_DGRAM) {
29172917
offset = dev_hard_header(skb, dev, ntohs(proto), addr, NULL, len);
29182918
if (unlikely(offset < 0))
29192919
goto out_free;
2920+
} else if (reserve) {
2921+
skb_push(skb, reserve);
29202922
}
29212923

29222924
/* Returns -EFAULT on error */

0 commit comments

Comments
 (0)