diff options
author | Eric Dumazet <edumazet@google.com> | 2018-09-28 17:51:49 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-10-02 02:27:28 -0400 |
commit | af3fb24eecb2c59246e03c99386037fd5ad84ffd (patch) | |
tree | 6500acce41557f78f2ec3f984195337ce9781b33 /drivers/net/tun.c | |
parent | c7256f579f8302ce2c038181c30060d0b40017b2 (diff) |
tun: napi flags belong to tfile
Since tun->flags might be shared by multiple tfile structures,
it is better to make sure tun_get_user() is using the flags
for the current tfile.
Presence of the READ_ONCE() in tun_napi_frags_enabled() gave a hint
of what could happen, but we need something stronger to please
syzbot.
kasan: CONFIG_KASAN_INLINE enabled
kasan: GPF could be caused by NULL-ptr deref or user memory access
general protection fault: 0000 [#1] PREEMPT SMP KASAN
CPU: 0 PID: 13647 Comm: syz-executor5 Not tainted 4.19.0-rc5+ #59
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
RIP: 0010:dev_gro_receive+0x132/0x2720 net/core/dev.c:5427
Code: 48 c1 ea 03 80 3c 02 00 0f 85 6e 20 00 00 48 b8 00 00 00 00 00 fc ff df 4d 8b 6e 10 49 8d bd d0 00 00 00 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f 85 59 20 00 00 4d 8b a5 d0 00 00 00 31 ff 41 81 e4
RSP: 0018:ffff8801c400f410 EFLAGS: 00010202
RAX: dffffc0000000000 RBX: 0000000000000000 RCX: ffffffff8618d325
RDX: 000000000000001a RSI: ffffffff86189f97 RDI: 00000000000000d0
RBP: ffff8801c400f608 R08: ffff8801c8fb4300 R09: 0000000000000000
R10: ffffed0038801ed7 R11: 0000000000000003 R12: ffff8801d327d358
R13: 0000000000000000 R14: ffff8801c16dd8c0 R15: 0000000000000004
FS: 00007fe003615700(0000) GS:ffff8801dac00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fe1f3c43db8 CR3: 00000001bebb2000 CR4: 00000000001406f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
napi_gro_frags+0x3f4/0xc90 net/core/dev.c:5715
tun_get_user+0x31d5/0x42a0 drivers/net/tun.c:1922
tun_chr_write_iter+0xb9/0x154 drivers/net/tun.c:1967
call_write_iter include/linux/fs.h:1808 [inline]
new_sync_write fs/read_write.c:474 [inline]
__vfs_write+0x6b8/0x9f0 fs/read_write.c:487
vfs_write+0x1fc/0x560 fs/read_write.c:549
ksys_write+0x101/0x260 fs/read_write.c:598
__do_sys_write fs/read_write.c:610 [inline]
__se_sys_write fs/read_write.c:607 [inline]
__x64_sys_write+0x73/0xb0 fs/read_write.c:607
do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x457579
Code: 1d b4 fb ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 0f 83 eb b3 fb ff c3 66 2e 0f 1f 84 00 00 00 00
RSP: 002b:00007fe003614c78 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 0000000000457579
RDX: 0000000000000012 RSI: 0000000020000000 RDI: 000000000000000a
RBP: 000000000072c040 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00007fe0036156d4
R13: 00000000004c5574 R14: 00000000004d8e98 R15: 00000000ffffffff
Modules linked in:
RIP: 0010:dev_gro_receive+0x132/0x2720 net/core/dev.c:5427
Code: 48 c1 ea 03 80 3c 02 00 0f 85 6e 20 00 00 48 b8 00 00 00 00 00 fc ff df 4d 8b 6e 10 49 8d bd d0 00 00 00 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f 85 59 20 00 00 4d 8b a5 d0 00 00 00 31 ff 41 81 e4
RSP: 0018:ffff8801c400f410 EFLAGS: 00010202
RAX: dffffc0000000000 RBX: 0000000000000000 RCX: ffffffff8618d325
RDX: 000000000000001a RSI: ffffffff86189f97 RDI: 00000000000000d0
RBP: ffff8801c400f608 R08: ffff8801c8fb4300 R09: 0000000000000000
R10: ffffed0038801ed7 R11: 0000000000000003 R12: ffff8801d327d358
R13: 0000000000000000 R14: ffff8801c16dd8c0 R15: 0000000000000004
FS: 00007fe003615700(0000) GS:ffff8801dac00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fe1f3c43db8 CR3: 00000001bebb2000 CR4: 00000000001406f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Fixes: 90e33d459407 ("tun: enable napi_gro_frags() for TUN/TAP driver")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: syzbot <syzkaller@googlegroups.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/tun.c')
-rw-r--r-- | drivers/net/tun.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 729686babbf3..50e9cc19023a 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c | |||
@@ -181,6 +181,7 @@ struct tun_file { | |||
181 | }; | 181 | }; |
182 | struct napi_struct napi; | 182 | struct napi_struct napi; |
183 | bool napi_enabled; | 183 | bool napi_enabled; |
184 | bool napi_frags_enabled; | ||
184 | struct mutex napi_mutex; /* Protects access to the above napi */ | 185 | struct mutex napi_mutex; /* Protects access to the above napi */ |
185 | struct list_head next; | 186 | struct list_head next; |
186 | struct tun_struct *detached; | 187 | struct tun_struct *detached; |
@@ -313,9 +314,10 @@ static int tun_napi_poll(struct napi_struct *napi, int budget) | |||
313 | } | 314 | } |
314 | 315 | ||
315 | static void tun_napi_init(struct tun_struct *tun, struct tun_file *tfile, | 316 | static void tun_napi_init(struct tun_struct *tun, struct tun_file *tfile, |
316 | bool napi_en) | 317 | bool napi_en, bool napi_frags) |
317 | { | 318 | { |
318 | tfile->napi_enabled = napi_en; | 319 | tfile->napi_enabled = napi_en; |
320 | tfile->napi_frags_enabled = napi_en && napi_frags; | ||
319 | if (napi_en) { | 321 | if (napi_en) { |
320 | netif_napi_add(tun->dev, &tfile->napi, tun_napi_poll, | 322 | netif_napi_add(tun->dev, &tfile->napi, tun_napi_poll, |
321 | NAPI_POLL_WEIGHT); | 323 | NAPI_POLL_WEIGHT); |
@@ -335,9 +337,9 @@ static void tun_napi_del(struct tun_file *tfile) | |||
335 | netif_napi_del(&tfile->napi); | 337 | netif_napi_del(&tfile->napi); |
336 | } | 338 | } |
337 | 339 | ||
338 | static bool tun_napi_frags_enabled(const struct tun_struct *tun) | 340 | static bool tun_napi_frags_enabled(const struct tun_file *tfile) |
339 | { | 341 | { |
340 | return READ_ONCE(tun->flags) & IFF_NAPI_FRAGS; | 342 | return tfile->napi_frags_enabled; |
341 | } | 343 | } |
342 | 344 | ||
343 | #ifdef CONFIG_TUN_VNET_CROSS_LE | 345 | #ifdef CONFIG_TUN_VNET_CROSS_LE |
@@ -792,7 +794,7 @@ static void tun_detach_all(struct net_device *dev) | |||
792 | } | 794 | } |
793 | 795 | ||
794 | static int tun_attach(struct tun_struct *tun, struct file *file, | 796 | static int tun_attach(struct tun_struct *tun, struct file *file, |
795 | bool skip_filter, bool napi) | 797 | bool skip_filter, bool napi, bool napi_frags) |
796 | { | 798 | { |
797 | struct tun_file *tfile = file->private_data; | 799 | struct tun_file *tfile = file->private_data; |
798 | struct net_device *dev = tun->dev; | 800 | struct net_device *dev = tun->dev; |
@@ -865,7 +867,7 @@ static int tun_attach(struct tun_struct *tun, struct file *file, | |||
865 | tun_enable_queue(tfile); | 867 | tun_enable_queue(tfile); |
866 | } else { | 868 | } else { |
867 | sock_hold(&tfile->sk); | 869 | sock_hold(&tfile->sk); |
868 | tun_napi_init(tun, tfile, napi); | 870 | tun_napi_init(tun, tfile, napi, napi_frags); |
869 | } | 871 | } |
870 | 872 | ||
871 | tun_set_real_num_queues(tun); | 873 | tun_set_real_num_queues(tun); |
@@ -1708,7 +1710,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, | |||
1708 | int err; | 1710 | int err; |
1709 | u32 rxhash = 0; | 1711 | u32 rxhash = 0; |
1710 | int skb_xdp = 1; | 1712 | int skb_xdp = 1; |
1711 | bool frags = tun_napi_frags_enabled(tun); | 1713 | bool frags = tun_napi_frags_enabled(tfile); |
1712 | 1714 | ||
1713 | if (!(tun->dev->flags & IFF_UP)) | 1715 | if (!(tun->dev->flags & IFF_UP)) |
1714 | return -EIO; | 1716 | return -EIO; |
@@ -2533,7 +2535,8 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) | |||
2533 | return err; | 2535 | return err; |
2534 | 2536 | ||
2535 | err = tun_attach(tun, file, ifr->ifr_flags & IFF_NOFILTER, | 2537 | err = tun_attach(tun, file, ifr->ifr_flags & IFF_NOFILTER, |
2536 | ifr->ifr_flags & IFF_NAPI); | 2538 | ifr->ifr_flags & IFF_NAPI, |
2539 | ifr->ifr_flags & IFF_NAPI_FRAGS); | ||
2537 | if (err < 0) | 2540 | if (err < 0) |
2538 | return err; | 2541 | return err; |
2539 | 2542 | ||
@@ -2631,7 +2634,8 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) | |||
2631 | (ifr->ifr_flags & TUN_FEATURES); | 2634 | (ifr->ifr_flags & TUN_FEATURES); |
2632 | 2635 | ||
2633 | INIT_LIST_HEAD(&tun->disabled); | 2636 | INIT_LIST_HEAD(&tun->disabled); |
2634 | err = tun_attach(tun, file, false, ifr->ifr_flags & IFF_NAPI); | 2637 | err = tun_attach(tun, file, false, ifr->ifr_flags & IFF_NAPI, |
2638 | ifr->ifr_flags & IFF_NAPI_FRAGS); | ||
2635 | if (err < 0) | 2639 | if (err < 0) |
2636 | goto err_free_flow; | 2640 | goto err_free_flow; |
2637 | 2641 | ||
@@ -2780,7 +2784,8 @@ static int tun_set_queue(struct file *file, struct ifreq *ifr) | |||
2780 | ret = security_tun_dev_attach_queue(tun->security); | 2784 | ret = security_tun_dev_attach_queue(tun->security); |
2781 | if (ret < 0) | 2785 | if (ret < 0) |
2782 | goto unlock; | 2786 | goto unlock; |
2783 | ret = tun_attach(tun, file, false, tun->flags & IFF_NAPI); | 2787 | ret = tun_attach(tun, file, false, tun->flags & IFF_NAPI, |
2788 | tun->flags & IFF_NAPI_FRAGS); | ||
2784 | } else if (ifr->ifr_flags & IFF_DETACH_QUEUE) { | 2789 | } else if (ifr->ifr_flags & IFF_DETACH_QUEUE) { |
2785 | tun = rtnl_dereference(tfile->tun); | 2790 | tun = rtnl_dereference(tfile->tun); |
2786 | if (!tun || !(tun->flags & IFF_MULTI_QUEUE) || tfile->detached) | 2791 | if (!tun || !(tun->flags & IFF_MULTI_QUEUE) || tfile->detached) |