netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] packet: tpacket_snd(): fix signed/unsigned comparison
@ 2015-07-28 10:57 Alexander Drozdov
  2015-07-28 11:07 ` Daniel Borkmann
  2015-07-29  7:10 ` David Miller
  0 siblings, 2 replies; 4+ messages in thread
From: Alexander Drozdov @ 2015-07-28 10:57 UTC (permalink / raw)
  To: David S. Miller, Daniel Borkmann
  Cc: Eric Dumazet, Willem de Bruijn, Al Viro, Eyal Birger,
	Michael S. Tsirkin, netdev, linux-kernel, Alexander Drozdov

tpacket_fill_skb() can return a negative value (-errno) which
is stored in tp_len variable. In that case the following
condition will be (but shouldn't be) true:

tp_len > dev->mtu + dev->hard_header_len

as dev->mtu and dev->hard_header_len are both unsigned.

That may lead to just returning an incorrect EMSGSIZE errno
to the user.

Signed-off-by: Alexander Drozdov <al.drozdov@gmail.com>
---
 net/packet/af_packet.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index c9e8741..d1d3625 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -2403,7 +2403,8 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
 		}
 		tp_len = tpacket_fill_skb(po, skb, ph, dev, size_max, proto,
 					  addr, hlen);
-		if (tp_len > dev->mtu + dev->hard_header_len) {
+		if (likely(tp_len >= 0) &&
+		    tp_len > dev->mtu + dev->hard_header_len) {
 			struct ethhdr *ehdr;
 			/* Earlier code assumed this would be a VLAN pkt,
 			 * double-check this now that we have the actual
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-07-29  7:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-28 10:57 [PATCH] packet: tpacket_snd(): fix signed/unsigned comparison Alexander Drozdov
2015-07-28 11:07 ` Daniel Borkmann
2015-07-28 11:38   ` Eric Dumazet
2015-07-29  7:10 ` David Miller

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).