Commit 92bb73ea authored by Jason Wang's avatar Jason Wang Committed by David S. Miller

tuntap: fix a possible race between queue selection and changing queues

Complier may generate codes that re-read the tun->numqueues during
tun_select_queue(). This may be a race if vlan->numqueues were changed in the
same time and can lead unexpected result (e.g. very huge value).

We need prevent the compiler from generating such codes by adding an
ACCESS_ONCE() to make sure tun->numqueues were only read once.

Bug were introduced by commit c8d68e6b
(tuntap: multiqueue support).
Reported-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Cc: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: default avatarJason Wang <jasowang@redhat.com>
Acked-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4364d5f9
...@@ -352,7 +352,7 @@ static u16 tun_select_queue(struct net_device *dev, struct sk_buff *skb) ...@@ -352,7 +352,7 @@ static u16 tun_select_queue(struct net_device *dev, struct sk_buff *skb)
u32 numqueues = 0; u32 numqueues = 0;
rcu_read_lock(); rcu_read_lock();
numqueues = tun->numqueues; numqueues = ACCESS_ONCE(tun->numqueues);
txq = skb_get_rxhash(skb); txq = skb_get_rxhash(skb);
if (txq) { if (txq) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment