Skip to content

Commit 9117c89

Browse files
wdebruijgregkh
authored andcommitted
packet: round up linear to header len
[ Upstream commit 57031eb ] Link layer protocols may unconditionally pull headers, as Ethernet does in eth_type_trans. Ensure that the entire link layer header always lies in the skb linear segment. tpacket_snd has such a check. Extend this to packet_snd. Variable length link layer headers complicate the computation somewhat. Here skb->len may be smaller than dev->hard_header_len. Round up the linear length to be at least as long as the smallest of the two. Reported-by: Dmitry Vyukov <[email protected]> Signed-off-by: Willem de Bruijn <[email protected]> Acked-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 58691e5 commit 9117c89

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

net/packet/af_packet.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2637,7 +2637,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
26372637
int vnet_hdr_len;
26382638
struct packet_sock *po = pkt_sk(sk);
26392639
unsigned short gso_type = 0;
2640-
int hlen, tlen;
2640+
int hlen, tlen, linear;
26412641
int extra_len = 0;
26422642
ssize_t n;
26432643

@@ -2741,8 +2741,9 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
27412741
err = -ENOBUFS;
27422742
hlen = LL_RESERVED_SPACE(dev);
27432743
tlen = dev->needed_tailroom;
2744-
skb = packet_alloc_skb(sk, hlen + tlen, hlen, len,
2745-
__virtio16_to_cpu(vio_le(), vnet_hdr.hdr_len),
2744+
linear = __virtio16_to_cpu(vio_le(), vnet_hdr.hdr_len);
2745+
linear = max(linear, min_t(int, len, dev->hard_header_len));
2746+
skb = packet_alloc_skb(sk, hlen + tlen, hlen, len, linear,
27462747
msg->msg_flags & MSG_DONTWAIT, &err);
27472748
if (skb == NULL)
27482749
goto out_unlock;

0 commit comments

Comments
 (0)