Skip to content

Commit

Permalink
bonding: Fix corrupted queue_mapping
Browse files Browse the repository at this point in the history
[ 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>
  • Loading branch information
Eric Dumazet authored and bwhacks committed Jul 12, 2012
1 parent a4b58f9 commit 75d5e3d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
9 changes: 5 additions & 4 deletions drivers/net/bonding/bond_main.c
Expand Up @@ -77,6 +77,7 @@
#include <net/route.h> #include <net/route.h>
#include <net/net_namespace.h> #include <net/net_namespace.h>
#include <net/netns/generic.h> #include <net/netns/generic.h>
#include <net/pkt_sched.h>
#include "bonding.h" #include "bonding.h"
#include "bond_3ad.h" #include "bond_3ad.h"
#include "bond_alb.h" #include "bond_alb.h"
Expand Down Expand Up @@ -382,8 +383,6 @@ struct vlan_entry *bond_next_vlan(struct bonding *bond, struct vlan_entry *curr)
return next; return next;
} }


#define bond_queue_mapping(skb) (*(u16 *)((skb)->cb))

/** /**
* bond_dev_queue_xmit - Prepare skb for xmit. * bond_dev_queue_xmit - Prepare skb for xmit.
* *
Expand All @@ -396,7 +395,9 @@ int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb,
{ {
skb->dev = slave_dev; skb->dev = slave_dev;


skb->queue_mapping = bond_queue_mapping(skb); BUILD_BUG_ON(sizeof(skb->queue_mapping) !=
sizeof(qdisc_skb_cb(skb)->bond_queue_mapping));
skb->queue_mapping = qdisc_skb_cb(skb)->bond_queue_mapping;


if (unlikely(netpoll_tx_running(slave_dev))) if (unlikely(netpoll_tx_running(slave_dev)))
bond_netpoll_send_skb(bond_get_slave_by_dev(bond, slave_dev), skb); bond_netpoll_send_skb(bond_get_slave_by_dev(bond, slave_dev), skb);
Expand Down Expand Up @@ -4151,7 +4152,7 @@ static u16 bond_select_queue(struct net_device *dev, struct sk_buff *skb)
/* /*
* Save the original txq to restore before passing to the driver * Save the original txq to restore before passing to the driver
*/ */
bond_queue_mapping(skb) = skb->queue_mapping; qdisc_skb_cb(skb)->bond_queue_mapping = skb->queue_mapping;


if (unlikely(txq >= dev->real_num_tx_queues)) { if (unlikely(txq >= dev->real_num_tx_queues)) {
do { do {
Expand Down
7 changes: 5 additions & 2 deletions include/net/sch_generic.h
Expand Up @@ -220,13 +220,16 @@ struct tcf_proto {


struct qdisc_skb_cb { struct qdisc_skb_cb {
unsigned int pkt_len; unsigned int pkt_len;
unsigned char data[24]; u16 bond_queue_mapping;
u16 _pad;
unsigned char data[20];
}; };


static inline void qdisc_cb_private_validate(const struct sk_buff *skb, int sz) static inline void qdisc_cb_private_validate(const struct sk_buff *skb, int sz)
{ {
struct qdisc_skb_cb *qcb; struct qdisc_skb_cb *qcb;
BUILD_BUG_ON(sizeof(skb->cb) < sizeof(unsigned int) + sz);
BUILD_BUG_ON(sizeof(skb->cb) < offsetof(struct qdisc_skb_cb, data) + sz);
BUILD_BUG_ON(sizeof(qcb->data) < sz); BUILD_BUG_ON(sizeof(qcb->data) < sz);
} }


Expand Down

0 comments on commit 75d5e3d

Please sign in to comment.