diff mbox series

[net,v3] net: bridge: Fix ethernet header pointer before check skb forwardable

Message ID 1547643861-15340-1-git-send-email-wangyunjian@huawei.com
State Superseded
Delegated to: David Miller
Headers show
Series [net,v3] net: bridge: Fix ethernet header pointer before check skb forwardable | expand

Commit Message

wangyunjian Jan. 16, 2019, 1:04 p.m. UTC
From: Yunjian Wang <wangyunjian@huawei.com>

The skb header should be set to ethernet header before using
is_skb_forwardable. Because the ethernet header length has been
considered in is_skb_forwardable(including dev->hard_header_len
length).

To reproduce the issue:
1, add 2 ports on linux bridge br using following commands:
$ brctl addbr br
$ brctl addif br eth0
$ brctl addif br eth1
2, the MTU of eth0 and eth1 is 1500
3, send a packet(Data 1480, UDP 8, IP 20, Ethernet 14, VLAN 4)
from eth0 to eth1

So the expect result is packet larger than 1500 cannot pass through
eth0 and eth1. But currently, the packet passes through success, it
means eth1's MTU limit doesn't take effect.

Fixes: f6367b4660dd ("bridge: use is_skb_forwardable in forward path")
Cc: bridge@lists.linux-foundation.org
Cc: Nkolay Aleksandrov <nikolay@cumulusnetworks.com>
Cc: Roopa Prabhu <roopa@cumulusnetworks.com>
Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
v2:
 -fix commit log and cc the bridge maintainers with fixes tags
v3:
 -add detailed description of packet len and construction
---
 net/bridge/br_forward.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Stephen Hemminger Jan. 16, 2019, 5:33 p.m. UTC | #1
On Wed, 16 Jan 2019 21:04:21 +0800
wangyunjian <wangyunjian@huawei.com> wrote:

>  		if (unlikely(netpoll_tx_running(to->br->dev))) {
> +			skb_push(skb, ETH_HLEN);
>  			if (!is_skb_forwardable(skb->dev, skb)) {
>  				kfree_skb(skb);
>  			} else {
> -				skb_push(skb, ETH_HLEN);
>  				br_netpoll_send_skb(to, skb);
>  			}
>  			return;

The patch looks correct.

On minor style issue is that after moving skb_push out of the if statement,
both branches of the statement now contain a single line and therefore
the brackets are no longer necessary.  Suprised that checkpatch did
not complain about this.
wangyunjian Jan. 17, 2019, 1:40 a.m. UTC | #2
> -----Original Message-----
> From: Stephen Hemminger [mailto:stephen@networkplumber.org]
> Sent: Thursday, January 17, 2019 1:33 AM
> To: wangyunjian <wangyunjian@huawei.com>
> Cc: netdev@vger.kernel.org; xudingke <xudingke@huawei.com>;
> bridge@lists.linux-foundation.org; Nkolay Aleksandrov
> <nikolay@cumulusnetworks.com>; Roopa Prabhu
> <roopa@cumulusnetworks.com>
> Subject: Re: [PATCH net v3] net: bridge: Fix ethernet header pointer before
> check skb forwardable
> 
> On Wed, 16 Jan 2019 21:04:21 +0800
> wangyunjian <wangyunjian@huawei.com> wrote:
> 
> >  		if (unlikely(netpoll_tx_running(to->br->dev))) {
> > +			skb_push(skb, ETH_HLEN);
> >  			if (!is_skb_forwardable(skb->dev, skb)) {
> >  				kfree_skb(skb);
> >  			} else {
> > -				skb_push(skb, ETH_HLEN);
> >  				br_netpoll_send_skb(to, skb);
> >  			}
> >  			return;
> 
> The patch looks correct.
> 
> On minor style issue is that after moving skb_push out of the if statement,
> both branches of the statement now contain a single line and therefore the
> brackets are no longer necessary.  Suprised that checkpatch did not complain
> about this.

OK, I'll fix it and send the v4 later.

Thanks
	Yunjian
diff mbox series

Patch

diff --git a/net/bridge/br_forward.c b/net/bridge/br_forward.c
index 5372e20..74b688b 100644
--- a/net/bridge/br_forward.c
+++ b/net/bridge/br_forward.c
@@ -36,10 +36,10 @@  static inline int should_deliver(const struct net_bridge_port *p,
 
 int br_dev_queue_push_xmit(struct net *net, struct sock *sk, struct sk_buff *skb)
 {
+	skb_push(skb, ETH_HLEN);
 	if (!is_skb_forwardable(skb->dev, skb))
 		goto drop;
 
-	skb_push(skb, ETH_HLEN);
 	br_drop_fake_rtable(skb);
 
 	if (skb->ip_summed == CHECKSUM_PARTIAL &&
@@ -97,10 +97,10 @@  static void __br_forward(const struct net_bridge_port *to,
 		net = dev_net(indev);
 	} else {
 		if (unlikely(netpoll_tx_running(to->br->dev))) {
+			skb_push(skb, ETH_HLEN);
 			if (!is_skb_forwardable(skb->dev, skb)) {
 				kfree_skb(skb);
 			} else {
-				skb_push(skb, ETH_HLEN);
 				br_netpoll_send_skb(to, skb);
 			}
 			return;