Skip to content

Commit

Permalink
packet: bail out of packet_snd() if L2 header creation fails
Browse files Browse the repository at this point in the history
Due to a misplaced parenthesis, the expression

  (unlikely(offset) < 0),

which expands to

  (__builtin_expect(!!(offset), 0) < 0),

never evaluates to true. Therefore, when sending packets with
PF_PACKET/SOCK_DGRAM, packet_snd() does not abort as intended
if the creation of the layer 2 header fails.

Spotted by Coverity - CID 1259975 ("Operands don't affect result").

Fixes: 9c70776 ("packet: make packet_snd fail on len smaller than l2 header")
Signed-off-by: Christoph Jaeger <[email protected]>
Acked-by: Eric Dumazet <[email protected]>
Acked-by: Willem de Bruijn <[email protected]>
Acked-by: Daniel Borkmann <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
christophjaeger authored and davem330 committed Jan 12, 2015
1 parent 7a05dc6 commit 46d2cfb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion net/packet/af_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -2517,7 +2517,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
err = -EINVAL;
if (sock->type == SOCK_DGRAM) {
offset = dev_hard_header(skb, dev, ntohs(proto), addr, NULL, len);
if (unlikely(offset) < 0)
if (unlikely(offset < 0))
goto out_free;
} else {
if (ll_header_truncated(dev, len))
Expand Down

0 comments on commit 46d2cfb

Please sign in to comment.