1 From foo@baz Thu Mar 28 21:57:57 CET 2019
2 From: Eric Dumazet <edumazet@google.com>
3 Date: Thu, 14 Mar 2019 20:19:47 -0700
4 Subject: tun: properly test for IFF_UP
6 From: Eric Dumazet <edumazet@google.com>
8 [ Upstream commit 4477138fa0ae4e1b699786ef0600863ea6e6c61c ]
10 Same reasons than the ones explained in commit 4179cb5a4c92
11 ("vxlan: test dev->flags & IFF_UP before calling netif_rx()")
13 netif_rx_ni() or napi_gro_frags() must be called under a strict contract.
15 At device dismantle phase, core networking clears IFF_UP
16 and flush_all_backlogs() is called after rcu grace period
17 to make sure no incoming packet might be in a cpu backlog
18 and still referencing the device.
20 A similar protocol is used for gro layer.
22 Most drivers call netif_rx() from their interrupt handler,
23 and since the interrupts are disabled at device dismantle,
24 netif_rx() does not have to check dev->flags & IFF_UP
26 Virtual drivers do not have this guarantee, and must
27 therefore make the check themselves.
29 Fixes: 1bd4978a88ac ("tun: honor IFF_UP in tun_get_user()")
30 Signed-off-by: Eric Dumazet <edumazet@google.com>
31 Reported-by: syzbot <syzkaller@googlegroups.com>
32 Signed-off-by: David S. Miller <davem@davemloft.net>
33 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
35 drivers/net/tun.c | 15 +++++++++++----
36 1 file changed, 11 insertions(+), 4 deletions(-)
38 --- a/drivers/net/tun.c
39 +++ b/drivers/net/tun.c
40 @@ -1194,9 +1194,6 @@ static ssize_t tun_get_user(struct tun_s
44 - if (!(tun->dev->flags & IFF_UP))
47 if (!(tun->flags & IFF_NO_PI)) {
50 @@ -1273,9 +1270,11 @@ static ssize_t tun_get_user(struct tun_s
51 err = skb_copy_datagram_from_iter(skb, 0, from, len);
56 this_cpu_inc(tun->pcpu_stats->rx_dropped);
62 err = virtio_net_hdr_to_skb(skb, &gso, tun_is_little_endian(tun));
63 @@ -1327,7 +1326,15 @@ static ssize_t tun_get_user(struct tun_s
64 skb_probe_transport_header(skb, 0);
66 rxhash = skb_get_hash(skb);
69 + if (unlikely(!(tun->dev->flags & IFF_UP))) {
77 stats = get_cpu_ptr(tun->pcpu_stats);
78 u64_stats_update_begin(&stats->syncp);