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

* Re: [PATCH] packet: tpacket_snd(): fix signed/unsigned comparison
  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
  1 sibling, 1 reply; 4+ messages in thread
From: Daniel Borkmann @ 2015-07-28 11:07 UTC (permalink / raw)
  To: Alexander Drozdov, David S. Miller, Daniel Borkmann
  Cc: Eric Dumazet, Willem de Bruijn, Al Viro, Eyal Birger,
	Michael S. Tsirkin, netdev, linux-kernel

On 07/28/2015 12:57 PM, Alexander Drozdov wrote:
> 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>

Looks good to me, thanks!

Acked-by: Daniel Borkmann <daniel@iogearbox.net>

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

* Re: [PATCH] packet: tpacket_snd(): fix signed/unsigned comparison
  2015-07-28 11:07 ` Daniel Borkmann
@ 2015-07-28 11:38   ` Eric Dumazet
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2015-07-28 11:38 UTC (permalink / raw)
  To: Daniel Borkmann
  Cc: Alexander Drozdov, David S. Miller, Daniel Borkmann, Eric Dumazet,
	Willem de Bruijn, Al Viro, Eyal Birger, Michael S. Tsirkin,
	netdev, linux-kernel

On Tue, 2015-07-28 at 13:07 +0200, Daniel Borkmann wrote:
> On 07/28/2015 12:57 PM, Alexander Drozdov wrote:
> > 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>
> 
> Looks good to me, thanks!
> 
> Acked-by: Daniel Borkmann <daniel@iogearbox.net>
> --

Fixes: 52f1454f629fa ("packet: allow to transmit +4 byte in TX_RING slot for VLAN case")

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

* Re: [PATCH] packet: tpacket_snd(): fix signed/unsigned comparison
  2015-07-28 10:57 [PATCH] packet: tpacket_snd(): fix signed/unsigned comparison Alexander Drozdov
  2015-07-28 11:07 ` Daniel Borkmann
@ 2015-07-29  7:10 ` David Miller
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2015-07-29  7:10 UTC (permalink / raw)
  To: al.drozdov
  Cc: dborkman, edumazet, willemb, viro, eyal.birger, mst, netdev,
	linux-kernel

From: Alexander Drozdov <al.drozdov@gmail.com>
Date: Tue, 28 Jul 2015 13:57:01 +0300

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

Applied, thanks.

^ permalink raw reply	[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).