packet: fix reserve calculation
Subsystems (3)
Willem de Bruijn
maintainerPATCH 1/1 packet: fix reserve calculation
From: Willem de Bruijn <[email protected]>
Commit b84bbaf7a6c8 ("packet: in packet_snd start writing at link layer allocation") ensures that packet_snd always starts writing the link layer header in reserved headroom allocated for this purpose.
This is needed because packets may be shorter than hard_header_len, in which case the space up to hard_header_len may be zeroed. But that necessary padding is not accounted for in skb->len.
The fix, however, is buggy. It calls skb_push, which grows skb->len when moving skb->data back. But in this case packet length should not change.
Instead, call skb_reserve, which moves both skb->data and skb->tail back, without changing length.
--- net/packet/af_packet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/packet/af_packet.c +1 -1
@@ -2911,7 +2911,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)if (unlikely (offset <0 )) goto out_free; }else if (reserve) { -skb_push (skb, reserve); +skb_reserve (skb, -reserve); }/* Returns -EFAULT on error */
Signature · 1 line
2.17.0.921.gf22659ad46-goog
David Miller
maintainerFrom: Willem de Bruijn <[email protected]>
Date: Thu, 24 May 2018 18:10:30 -0400
Quoted 15 lines
From: Willem de Bruijn <[email protected]>
Commit
b84bbaf7a6c8("packet: inpacket_sndstart writing at link layer allocation") ensures thatpacket_sndalways starts writing the link layer header in reserved headroom allocated for this purpose.This is needed because packets may be shorter than
hard_header_len, in which case the space up tohard_header_lenmay be zeroed. But that necessary padding is not accounted for inskb->len.The fix, however, is buggy. It calls
skb_push, which growsskb->lenwhen movingskb->databack. But in this case packet length should not change.
Quoted 7 lines
Instead, call
skb_reserve, which moves bothskb->dataandskb->tailback, without changing length.Fixes b84bbaf7a6c8 ("packet: in packet_snd start writing at link layer allocation")Reported-by Tariq Toukan <[email protected]>Signed-off-by Willem de Bruijn <[email protected]>
Applied and queued up for -stable.
Quoted 15 lines · Willem de Bruijn
From: Willem de Bruijn <[email protected]>
Commit
b84bbaf7a6c8("packet: inpacket_sndstart writing at link layer allocation") ensures thatpacket_sndalways starts writing the link layer header in reserved headroom allocated for this purpose.This is needed because packets may be shorter than
hard_header_len, in which case the space up tohard_header_lenmay be zeroed. But that necessary padding is not accounted for inskb->len.The fix, however, is buggy. It calls
skb_push, which growsskb->lenwhen movingskb->databack. But in this case packet length should not change.
Quoted 7 lines
Instead, call
skb_reserve, which moves bothskb->dataandskb->tailback, without changing length.Fixes b84bbaf7a6c8 ("packet: in packet_snd start writing at link layer allocation")Reported-by Tariq Toukan <[email protected]>Signed-off-by Willem de Bruijn <[email protected]>
After upgrading my router from 4.16.11 to 4.16.12, it is failing to obtain a DHCP lease from my ISP, as it started sending out DHCP queries with 14 bytes of junk at the end (which is presumably causing RX csum failures on the DHCP server end):
13:08:39.292667 IP (tos 0x10, ttl 128, id 0, offset 0, flags [none], proto UDP (17), length 328)
0.0.0.0.68 > 255.255.255.255.67: [udp sum ok] BOOTP/DHCP, Request from xx:xx:xx:xx:xx:xx, length 300, xid 0xxxxxxxxx, Flags [none] (0x0000) [...] - 0x0150: 0000 0000 0000 + 0x0150: 0000 0000 0000 e802 0000 0000 0000 e802 + 0x0160: 0000 0000
This seems to be caused by (the -stable backport of) b84bbaf7a6c8 ("packet: in packet_snd start writing at link layer allocation") and appears to have been fixed by this patch, as applying this patch to 4.16.12 makes DHCP work for me again.
Quoted 19 lines
--- net/packet/af_packet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/packet/af_packet.c +1
-1@@ -2911,7 +2911,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)if (unlikely (offset <0 )) goto out_free; }else if (reserve) { -skb_push (skb, reserve); +skb_reserve (skb, -reserve); }/* Returns -EFAULT on error */ Signature · 1 line
2.17.0.921.gf22659ad46-goog