[net] packet: reset network header if packet shorter than ll reserved space

Message ID 20180711160046.198091-2-willemdebruijn.kernel@gmail.com
State Accepted
Delegated to: David Miller
Headers show
Series
  • [net] packet: reset network header if packet shorter than ll reserved space
Related show

Commit Message

Willem de Bruijn July 11, 2018, 4 p.m.
From: Willem de Bruijn <willemb@google.com>

If variable length link layer headers result in a packet shorter
than dev->hard_header_len, reset the network header offset. Else
skb->mac_len may exceed skb->len after skb_mac_reset_len.

packet_sendmsg_spkt already has similar logic.

Fixes: b84bbaf7a6c8 ("packet: in packet_snd start writing at link layer allocation")
Signed-off-by: Willem de Bruijn <willemb@google.com>
---
 net/packet/af_packet.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

David Miller July 12, 2018, 11:57 p.m. | #1
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Date: Wed, 11 Jul 2018 12:00:45 -0400

> From: Willem de Bruijn <willemb@google.com>
> 
> If variable length link layer headers result in a packet shorter
> than dev->hard_header_len, reset the network header offset. Else
> skb->mac_len may exceed skb->len after skb_mac_reset_len.
> 
> packet_sendmsg_spkt already has similar logic.
> 
> Fixes: b84bbaf7a6c8 ("packet: in packet_snd start writing at link layer allocation")
> Signed-off-by: Willem de Bruijn <willemb@google.com>

Applied and queued up for -stable.

Patch

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 57634bc3da74..9b27d0cd766d 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -2878,6 +2878,8 @@  static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
 			goto out_free;
 	} else if (reserve) {
 		skb_reserve(skb, -reserve);
+		if (len < reserve)
+			skb_reset_network_header(skb);
 	}
 
 	/* Returns -EFAULT on error */