]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.19/ipv6-fix-races-in-ip6_dst_destroy.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / queue-4.19 / ipv6-fix-races-in-ip6_dst_destroy.patch
1 From foo@baz Sat 04 May 2019 09:23:44 AM CEST
2 From: Eric Dumazet <edumazet@google.com>
3 Date: Sun, 28 Apr 2019 12:22:25 -0700
4 Subject: ipv6: fix races in ip6_dst_destroy()
5
6 From: Eric Dumazet <edumazet@google.com>
7
8 [ Upstream commit 0e2338749192ce0e52e7174c5352f627632f478a ]
9
10 We had many syzbot reports that seem to be caused by use-after-free
11 of struct fib6_info.
12
13 ip6_dst_destroy(), fib6_drop_pcpu_from() and rt6_remove_exception()
14 are writers vs rt->from, and use non consistent synchronization among
15 themselves.
16
17 Switching to xchg() will solve the issues with no possible
18 lockdep issues.
19
20 BUG: KASAN: user-memory-access in atomic_dec_and_test include/asm-generic/atomic-instrumented.h:747 [inline]
21 BUG: KASAN: user-memory-access in fib6_info_release include/net/ip6_fib.h:294 [inline]
22 BUG: KASAN: user-memory-access in fib6_info_release include/net/ip6_fib.h:292 [inline]
23 BUG: KASAN: user-memory-access in fib6_drop_pcpu_from net/ipv6/ip6_fib.c:927 [inline]
24 BUG: KASAN: user-memory-access in fib6_purge_rt+0x4f6/0x670 net/ipv6/ip6_fib.c:960
25 Write of size 4 at addr 0000000000ffffb4 by task syz-executor.1/7649
26
27 CPU: 0 PID: 7649 Comm: syz-executor.1 Not tainted 5.1.0-rc6+ #183
28 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
29 Call Trace:
30 __dump_stack lib/dump_stack.c:77 [inline]
31 dump_stack+0x172/0x1f0 lib/dump_stack.c:113
32 kasan_report.cold+0x5/0x40 mm/kasan/report.c:321
33 check_memory_region_inline mm/kasan/generic.c:185 [inline]
34 check_memory_region+0x123/0x190 mm/kasan/generic.c:191
35 kasan_check_write+0x14/0x20 mm/kasan/common.c:108
36 atomic_dec_and_test include/asm-generic/atomic-instrumented.h:747 [inline]
37 fib6_info_release include/net/ip6_fib.h:294 [inline]
38 fib6_info_release include/net/ip6_fib.h:292 [inline]
39 fib6_drop_pcpu_from net/ipv6/ip6_fib.c:927 [inline]
40 fib6_purge_rt+0x4f6/0x670 net/ipv6/ip6_fib.c:960
41 fib6_del_route net/ipv6/ip6_fib.c:1813 [inline]
42 fib6_del+0xac2/0x10a0 net/ipv6/ip6_fib.c:1844
43 fib6_clean_node+0x3a8/0x590 net/ipv6/ip6_fib.c:2006
44 fib6_walk_continue+0x495/0x900 net/ipv6/ip6_fib.c:1928
45 fib6_walk+0x9d/0x100 net/ipv6/ip6_fib.c:1976
46 fib6_clean_tree+0xe0/0x120 net/ipv6/ip6_fib.c:2055
47 __fib6_clean_all+0x118/0x2a0 net/ipv6/ip6_fib.c:2071
48 fib6_clean_all+0x2b/0x40 net/ipv6/ip6_fib.c:2082
49 rt6_sync_down_dev+0x134/0x150 net/ipv6/route.c:4057
50 rt6_disable_ip+0x27/0x5f0 net/ipv6/route.c:4062
51 addrconf_ifdown+0xa2/0x1220 net/ipv6/addrconf.c:3705
52 addrconf_notify+0x19a/0x2260 net/ipv6/addrconf.c:3630
53 notifier_call_chain+0xc7/0x240 kernel/notifier.c:93
54 __raw_notifier_call_chain kernel/notifier.c:394 [inline]
55 raw_notifier_call_chain+0x2e/0x40 kernel/notifier.c:401
56 call_netdevice_notifiers_info+0x3f/0x90 net/core/dev.c:1753
57 call_netdevice_notifiers_extack net/core/dev.c:1765 [inline]
58 call_netdevice_notifiers net/core/dev.c:1779 [inline]
59 dev_close_many+0x33f/0x6f0 net/core/dev.c:1522
60 rollback_registered_many+0x43b/0xfd0 net/core/dev.c:8177
61 rollback_registered+0x109/0x1d0 net/core/dev.c:8242
62 unregister_netdevice_queue net/core/dev.c:9289 [inline]
63 unregister_netdevice_queue+0x1ee/0x2c0 net/core/dev.c:9282
64 unregister_netdevice include/linux/netdevice.h:2658 [inline]
65 __tun_detach+0xd5b/0x1000 drivers/net/tun.c:727
66 tun_detach drivers/net/tun.c:744 [inline]
67 tun_chr_close+0xe0/0x180 drivers/net/tun.c:3443
68 __fput+0x2e5/0x8d0 fs/file_table.c:278
69 ____fput+0x16/0x20 fs/file_table.c:309
70 task_work_run+0x14a/0x1c0 kernel/task_work.c:113
71 exit_task_work include/linux/task_work.h:22 [inline]
72 do_exit+0x90a/0x2fa0 kernel/exit.c:876
73 do_group_exit+0x135/0x370 kernel/exit.c:980
74 __do_sys_exit_group kernel/exit.c:991 [inline]
75 __se_sys_exit_group kernel/exit.c:989 [inline]
76 __x64_sys_exit_group+0x44/0x50 kernel/exit.c:989
77 do_syscall_64+0x103/0x610 arch/x86/entry/common.c:290
78 entry_SYSCALL_64_after_hwframe+0x49/0xbe
79 RIP: 0033:0x458da9
80 Code: ad b8 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 7b b8 fb ff c3 66 2e 0f 1f 84 00 00 00 00
81 RSP: 002b:00007ffeafc2a6a8 EFLAGS: 00000246 ORIG_RAX: 00000000000000e7
82 RAX: ffffffffffffffda RBX: 000000000000001c RCX: 0000000000458da9
83 RDX: 0000000000412a80 RSI: 0000000000a54ef0 RDI: 0000000000000043
84 RBP: 00000000004be552 R08: 000000000000000c R09: 000000000004c0d1
85 R10: 0000000002341940 R11: 0000000000000246 R12: 00000000ffffffff
86 R13: 00007ffeafc2a7f0 R14: 000000000004c065 R15: 00007ffeafc2a800
87
88 Fixes: a68886a69180 ("net/ipv6: Make from in rt6_info rcu protected")
89 Signed-off-by: Eric Dumazet <edumazet@google.com>
90 Reported-by: syzbot <syzkaller@googlegroups.com>
91 Cc: David Ahern <dsahern@gmail.com>
92 Reviewed-by: David Ahern <dsahern@gmail.com>
93 Acked-by: Martin KaFai Lau <kafai@fb.com>
94 Acked-by: Wei Wang <weiwan@google.com>
95 Signed-off-by: David S. Miller <davem@davemloft.net>
96 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
97 ---
98 net/ipv6/ip6_fib.c | 4 +---
99 net/ipv6/route.c | 9 ++-------
100 2 files changed, 3 insertions(+), 10 deletions(-)
101
102 --- a/net/ipv6/ip6_fib.c
103 +++ b/net/ipv6/ip6_fib.c
104 @@ -889,9 +889,7 @@ static void fib6_drop_pcpu_from(struct f
105 if (pcpu_rt) {
106 struct fib6_info *from;
107
108 - from = rcu_dereference_protected(pcpu_rt->from,
109 - lockdep_is_held(&table->tb6_lock));
110 - rcu_assign_pointer(pcpu_rt->from, NULL);
111 + from = xchg((__force struct fib6_info **)&pcpu_rt->from, NULL);
112 fib6_info_release(from);
113 }
114 }
115 --- a/net/ipv6/route.c
116 +++ b/net/ipv6/route.c
117 @@ -382,11 +382,8 @@ static void ip6_dst_destroy(struct dst_e
118 in6_dev_put(idev);
119 }
120
121 - rcu_read_lock();
122 - from = rcu_dereference(rt->from);
123 - rcu_assign_pointer(rt->from, NULL);
124 + from = xchg((__force struct fib6_info **)&rt->from, NULL);
125 fib6_info_release(from);
126 - rcu_read_unlock();
127 }
128
129 static void ip6_dst_ifdown(struct dst_entry *dst, struct net_device *dev,
130 @@ -1296,9 +1293,7 @@ static void rt6_remove_exception(struct
131 /* purge completely the exception to allow releasing the held resources:
132 * some [sk] cache may keep the dst around for unlimited time
133 */
134 - from = rcu_dereference_protected(rt6_ex->rt6i->from,
135 - lockdep_is_held(&rt6_exception_lock));
136 - rcu_assign_pointer(rt6_ex->rt6i->from, NULL);
137 + from = xchg((__force struct fib6_info **)&rt6_ex->rt6i->from, NULL);
138 fib6_info_release(from);
139 dst_dev_put(&rt6_ex->rt6i->dst);
140