netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Jaeger <cj@linux.com>
To: davem@davemloft.net
Cc: willemb@google.com, edumazet@google.com, dborkman@redhat.com,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Christoph Jaeger <cj@linux.com>
Subject: [PATCH net] packet: bail out of packet_snd() if L2 header creation fails
Date: Sun, 11 Jan 2015 13:01:16 -0500	[thread overview]
Message-ID: <1420999276-28225-1-git-send-email-cj@linux.com> (raw)

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: 9c7077622dd9 ("packet: make packet_snd fail on len smaller than l2 header")
Signed-off-by: Christoph Jaeger <cj@linux.com>
---
 net/packet/af_packet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 6880f34..9cfe2e1 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -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))
-- 
2.1.0

             reply	other threads:[~2015-01-11 18:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-11 18:01 Christoph Jaeger [this message]
2015-01-11 18:35 ` [PATCH net] packet: bail out of packet_snd() if L2 header creation fails Eric Dumazet
2015-01-11 18:49   ` Willem de Bruijn
2015-01-11 18:52 ` Joe Perches
2015-01-11 19:34   ` Christoph Jaeger
2015-01-11 19:49     ` [PATCH] checkpatch: Add likely/unlikely comparison misuse test Joe Perches
2015-01-11 21:38 ` [PATCH net] packet: bail out of packet_snd() if L2 header creation fails Daniel Borkmann
2015-01-12  2:54 ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1420999276-28225-1-git-send-email-cj@linux.com \
    --to=cj@linux.com \
    --cc=davem@davemloft.net \
    --cc=dborkman@redhat.com \
    --cc=edumazet@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).