packet: fix reserve calculation
authorWillem de Bruijn <willemb@google.com>
Thu, 24 May 2018 22:10:30 +0000 (18:10 -0400)
committerDavid S. Miller <davem@davemloft.net>
Fri, 25 May 2018 01:55:20 +0000 (21:55 -0400)
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.

Fixes: b84bbaf7a6c8 ("packet: in packet_snd start writing at link layer allocation")
Reported-by: Tariq Toukan <tariqt@mellanox.com>
Signed-off-by: Willem de Bruijn <willemb@google.com>
Acked-by: Soheil Hassas Yeganeh <soheil@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/packet/af_packet.c

index e9422fe45179363ef1d7a1c5c406a6d058f61e29..acb7b86574cd3d6f13790550c00f11616caff2e3 100644 (file)
@@ -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 */