Skip to content

Commit

Permalink
net: fix problem in reading sock TX queue
Browse files Browse the repository at this point in the history
Fix problem in reading the tx_queue recorded in a socket.  In
dev_pick_tx, the TX queue is read by doing a check with
sk_tx_queue_recorded on the socket, followed by a sk_tx_queue_get.
The problem is that there is not mutual exclusion across these
calls in the socket so it it is possible that the queue in the
sock can be invalidated after sk_tx_queue_recorded is called so
that sk_tx_queue get returns -1, which sets 65535 in queue_index
and thus dev_pick_tx returns 65536 which is a bogus queue and
can cause crash in dev_queue_xmit.

We fix this by only calling sk_tx_queue_get which does the proper
checks.  The interface is that sk_tx_queue_get returns the TX queue
if the sock argument is non-NULL and TX queue is recorded, else it
returns -1.  sk_tx_queue_recorded is no longer used so it can be
completely removed.

Signed-off-by: Tom Herbert <therbert@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Tom Herbert authored and David S. Miller committed Jul 15, 2010
1 parent 91a72a7 commit b0f77d0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
7 changes: 1 addition & 6 deletions include/net/sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -1224,12 +1224,7 @@ static inline void sk_tx_queue_clear(struct sock *sk)

static inline int sk_tx_queue_get(const struct sock *sk)
{
return sk->sk_tx_queue_mapping;
}

static inline bool sk_tx_queue_recorded(const struct sock *sk)
{
return (sk && sk->sk_tx_queue_mapping >= 0);
return sk ? sk->sk_tx_queue_mapping : -1;
}

static inline void sk_set_socket(struct sock *sk, struct socket *sock)
Expand Down
7 changes: 3 additions & 4 deletions net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -2029,12 +2029,11 @@ static inline u16 dev_cap_txqueue(struct net_device *dev, u16 queue_index)
static struct netdev_queue *dev_pick_tx(struct net_device *dev,
struct sk_buff *skb)
{
u16 queue_index;
int queue_index;
struct sock *sk = skb->sk;

if (sk_tx_queue_recorded(sk)) {
queue_index = sk_tx_queue_get(sk);
} else {
queue_index = sk_tx_queue_get(sk);
if (queue_index < 0) {
const struct net_device_ops *ops = dev->netdev_ops;

if (ops->ndo_select_queue) {
Expand Down

0 comments on commit b0f77d0

Please sign in to comment.