Eric Dumazet
b90f87c641
net/packet: fix a race in packet_bind() and packet_notifier()
...
[ Upstream commit 15fe076edea787807a7cdc168df832544b58eba6 ]
syzbot reported crashes [1] and provided a C repro easing bug hunting.
When/if packet_do_bind() calls __unregister_prot_hook() and releases
po->bind_lock, another thread can run packet_notifier() and process an
NETDEV_UP event.
This calls register_prot_hook() and hooks again the socket right before
first thread is able to grab again po->bind_lock.
Fixes this issue by temporarily setting po->num to 0, as suggested by
David Miller.
[1]
dev_remove_pack: ffff8801bf16fa80 not found
------------[ cut here ]------------
kernel BUG at net/core/dev.c:7945! ( BUG_ON(!list_empty(&dev->ptype_all)); )
invalid opcode: 0000 [#1 ] SMP KASAN
Dumping ftrace buffer:
(ftrace buffer empty)
Modules linked in:
device syz0 entered promiscuous mode
CPU: 0 PID: 3161 Comm: syzkaller404108 Not tainted 4.14.0+ #190
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
task: ffff8801cc57a500 task.stack: ffff8801cc588000
RIP: 0010:netdev_run_todo+0x772/0xae0 net/core/dev.c:7945
RSP: 0018:ffff8801cc58f598 EFLAGS: 00010293
RAX: ffff8801cc57a500 RBX: dffffc0000000000 RCX: ffffffff841f75b2
RDX: 0000000000000000 RSI: 1ffff100398b1ede RDI: ffff8801bf1f8810
device syz0 entered promiscuous mode
RBP: ffff8801cc58f898 R08: 0000000000000001 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000000 R12: ffff8801bf1f8cd8
R13: ffff8801cc58f870 R14: ffff8801bf1f8780 R15: ffff8801cc58f7f0
FS: 0000000001716880(0000) GS:ffff8801db400000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000020b13000 CR3: 0000000005e25000 CR4: 00000000001406f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
rtnl_unlock+0xe/0x10 net/core/rtnetlink.c:106
tun_detach drivers/net/tun.c:670 [inline]
tun_chr_close+0x49/0x60 drivers/net/tun.c:2845
__fput+0x333/0x7f0 fs/file_table.c:210
____fput+0x15/0x20 fs/file_table.c:244
task_work_run+0x199/0x270 kernel/task_work.c:113
exit_task_work include/linux/task_work.h:22 [inline]
do_exit+0x9bb/0x1ae0 kernel/exit.c:865
do_group_exit+0x149/0x400 kernel/exit.c:968
SYSC_exit_group kernel/exit.c:979 [inline]
SyS_exit_group+0x1d/0x20 kernel/exit.c:977
entry_SYSCALL_64_fastpath+0x1f/0x96
RIP: 0033:0x44ad19
Fixes: 30f7ea1c2b5f ("packet: race condition in packet_bind")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: syzbot <syzkaller@googlegroups.com>
Cc: Francesco Ruggeri <fruggeri@aristanetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-12-16 10:33:56 +01:00
..
2015-10-21 00:49:25 +02:00
2017-11-30 08:37:25 +00:00
2017-11-24 08:32:24 +01:00
2015-09-17 22:13:32 -07:00
2017-02-04 09:45:09 +01:00
2016-12-15 08:49:23 -08:00
2017-09-13 14:09:46 -07:00
2017-10-08 10:14:19 +02:00
2017-07-05 14:37:14 +02:00
2017-02-18 16:39:26 +01:00
2017-04-08 09:53:30 +02:00
2017-11-24 08:32:24 +01:00
2015-10-09 07:52:27 -07:00
2017-11-18 11:11:07 +01:00
2017-07-05 14:37:14 +02:00
2017-10-27 10:23:18 +02:00
2017-11-15 17:13:11 +01:00
2017-02-18 16:39:27 +01:00
2015-11-23 14:56:15 -05:00
2017-09-27 11:00:11 +02:00
2017-12-16 10:33:54 +01:00
2017-12-16 10:33:56 +01:00
2017-05-25 14:30:13 +02:00
2017-08-30 10:19:21 +02:00
2016-03-03 15:07:03 -08:00
2017-08-30 10:19:18 +02:00
2017-11-18 11:11:05 +01:00
2015-10-07 04:27:43 -07:00
2017-02-26 11:07:49 +01:00
2017-11-30 08:37:27 +00:00
2015-10-21 00:49:24 +02:00
2017-03-22 12:04:16 +01:00
2017-11-30 08:37:27 +00:00
2016-08-20 18:09:22 +02:00
2017-12-05 11:22:49 +01:00
2017-11-30 08:37:23 +00:00
2017-08-11 09:08:53 -07:00
2017-12-16 10:33:56 +01:00
2016-01-31 11:29:00 -08:00
2017-12-16 10:33:56 +01:00
2016-03-03 15:07:26 -08:00
2017-06-29 12:48:52 +02:00
2017-08-30 10:19:21 +02:00
2017-12-16 10:33:55 +01:00
2017-12-16 10:33:55 +01:00
2016-06-24 10:18:16 -07:00
2017-12-16 10:33:56 +01:00
2017-11-18 11:11:06 +01:00
2017-11-30 08:37:19 +00:00
2015-08-09 22:43:52 -07:00
2017-10-18 09:20:41 +02:00
2016-05-18 17:06:43 -07:00
2017-12-16 10:33:55 +01:00
2017-10-08 10:14:18 +02:00
2015-09-29 20:40:32 -07:00
2015-09-29 20:40:32 -07:00
2017-02-26 11:07:50 +01:00
2016-09-15 08:27:50 +02:00