提交 46d2cfb1 编写于 作者: C Christoph Jaeger 提交者: David S. Miller

packet: bail out of packet_snd() if L2 header creation fails

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: 9c707762 ("packet: make packet_snd fail on len smaller than l2 header")
Signed-off-by: NChristoph Jaeger <cj@linux.com>
Acked-by: NEric Dumazet <edumazet@google.com>
Acked-by: NWillem de Bruijn <willemb@google.com>
Acked-by: NDaniel Borkmann <dborkman@redhat.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 7a05dc64
...@@ -2517,7 +2517,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len) ...@@ -2517,7 +2517,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
err = -EINVAL; err = -EINVAL;
if (sock->type == SOCK_DGRAM) { if (sock->type == SOCK_DGRAM) {
offset = dev_hard_header(skb, dev, ntohs(proto), addr, NULL, len); offset = dev_hard_header(skb, dev, ntohs(proto), addr, NULL, len);
if (unlikely(offset) < 0) if (unlikely(offset < 0))
goto out_free; goto out_free;
} else { } else {
if (ll_header_truncated(dev, len)) if (ll_header_truncated(dev, len))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册