Skip to content

Commit 047af9c

Browse files
ebiedermdavem330
authored andcommitted
macvtap: Fix macvtap_open races in the zero copy enable code.
To see if it is appropriate to enable the macvtap zero copy feature don't test the lowerdev network device flags. Instead test the macvtap network device flags which are a direct copy of the lowerdev flags. This is important because nothing holds a reference to lowerdev and on a very bad day we lowerdev could be a pointer to stale memory. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 99f34b3 commit 047af9c

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

‎drivers/net/macvtap.c‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,6 @@ static int macvtap_open(struct inode *inode, struct file *file)
343343
{
344344
struct net *net = current->nsproxy->net_ns;
345345
struct net_device *dev = dev_get_by_index(net, iminor(inode));
346-
struct macvlan_dev *vlan = netdev_priv(dev);
347346
struct macvtap_queue *q;
348347
int err;
349348

@@ -376,12 +375,12 @@ static int macvtap_open(struct inode *inode, struct file *file)
376375
/*
377376
* so far only KVM virtio_net uses macvtap, enable zero copy between
378377
* guest kernel and host kernel when lower device supports zerocopy
378+
*
379+
* The macvlan supports zerocopy iff the lower device supports zero
380+
* copy so we don't have to look at the lower device directly.
379381
*/
380-
if (vlan) {
381-
if ((vlan->lowerdev->features & NETIF_F_HIGHDMA) &&
382-
(vlan->lowerdev->features & NETIF_F_SG))
383-
sock_set_flag(&q->sk, SOCK_ZEROCOPY);
384-
}
382+
if ((dev->features & NETIF_F_HIGHDMA) && (dev->features & NETIF_F_SG))
383+
sock_set_flag(&q->sk, SOCK_ZEROCOPY);
385384

386385
err = macvtap_set_queue(dev, file, q);
387386
if (err)

0 commit comments

Comments
 (0)