Skip to content

Commit 75d5e3d

Browse files
edumazetbwhacks
authored andcommitted
bonding: Fix corrupted queue_mapping
[ Upstream commit 5ee31c6 ] In the transmit path of the bonding driver, skb->cb is used to stash the skb->queue_mapping so that the bonding device can set its own queue mapping. This value becomes corrupted since the skb->cb is also used in __dev_xmit_skb. When transmitting through bonding driver, bond_select_queue is called from dev_queue_xmit. In bond_select_queue the original skb->queue_mapping is copied into skb->cb (via bond_queue_mapping) and skb->queue_mapping is overwritten with the bond driver queue. Subsequently in dev_queue_xmit, __dev_xmit_skb is called which writes the packet length into skb->cb, thereby overwriting the stashed queue mappping. In bond_dev_queue_xmit (called from hard_start_xmit), the queue mapping for the skb is set to the stashed value which is now the skb length and hence is an invalid queue for the slave device. If we want to save skb->queue_mapping into skb->cb[], best place is to add a field in struct qdisc_skb_cb, to make sure it wont conflict with other layers (eg : Qdiscc, Infiniband...) This patchs also makes sure (struct qdisc_skb_cb)->data is aligned on 8 bytes : netem qdisc for example assumes it can store an u64 in it, without misalignment penalty. Note : we only have 20 bytes left in (struct qdisc_skb_cb)->data[]. The largest user is CHOKe and it fills it. Based on a previous patch from Tom Herbert. Signed-off-by: Eric Dumazet <edumazet@google.com> Reported-by: Tom Herbert <therbert@google.com> Cc: John Fastabend <john.r.fastabend@intel.com> Cc: Roland Dreier <roland@kernel.org> Acked-by: Neil Horman <nhorman@tuxdriver.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
1 parent a4b58f9 commit 75d5e3d

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

‎drivers/net/bonding/bond_main.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
#include <net/route.h>
7878
#include <net/net_namespace.h>
7979
#include <net/netns/generic.h>
80+
#include <net/pkt_sched.h>
8081
#include "bonding.h"
8182
#include "bond_3ad.h"
8283
#include "bond_alb.h"
@@ -382,8 +383,6 @@ struct vlan_entry *bond_next_vlan(struct bonding *bond, struct vlan_entry *curr)
382383
return next;
383384
}
384385

385-
#define bond_queue_mapping(skb) (*(u16 *)((skb)->cb))
386-
387386
/**
388387
* bond_dev_queue_xmit - Prepare skb for xmit.
389388
*
@@ -396,7 +395,9 @@ int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb,
396395
{
397396
skb->dev = slave_dev;
398397

399-
skb->queue_mapping = bond_queue_mapping(skb);
398+
BUILD_BUG_ON(sizeof(skb->queue_mapping) !=
399+
sizeof(qdisc_skb_cb(skb)->bond_queue_mapping));
400+
skb->queue_mapping = qdisc_skb_cb(skb)->bond_queue_mapping;
400401

401402
if (unlikely(netpoll_tx_running(slave_dev)))
402403
bond_netpoll_send_skb(bond_get_slave_by_dev(bond, slave_dev), skb);
@@ -4151,7 +4152,7 @@ static u16 bond_select_queue(struct net_device *dev, struct sk_buff *skb)
41514152
/*
41524153
* Save the original txq to restore before passing to the driver
41534154
*/
4154-
bond_queue_mapping(skb) = skb->queue_mapping;
4155+
qdisc_skb_cb(skb)->bond_queue_mapping = skb->queue_mapping;
41554156

41564157
if (unlikely(txq >= dev->real_num_tx_queues)) {
41574158
do {

‎include/net/sch_generic.h‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,16 @@ struct tcf_proto {
220220

221221
struct qdisc_skb_cb {
222222
unsigned int pkt_len;
223-
unsigned char data[24];
223+
u16 bond_queue_mapping;
224+
u16 _pad;
225+
unsigned char data[20];
224226
};
225227

226228
static inline void qdisc_cb_private_validate(const struct sk_buff *skb, int sz)
227229
{
228230
struct qdisc_skb_cb *qcb;
229-
BUILD_BUG_ON(sizeof(skb->cb) < sizeof(unsigned int) + sz);
231+
232+
BUILD_BUG_ON(sizeof(skb->cb) < offsetof(struct qdisc_skb_cb, data) + sz);
230233
BUILD_BUG_ON(sizeof(qcb->data) < sz);
231234
}
232235

0 commit comments

Comments
 (0)