]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.9.169/net-rds-force-to-destroy-connection-if-t_sock-is-null-in-rds_tcp_kill_sock.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.9.169 / net-rds-force-to-destroy-connection-if-t_sock-is-null-in-rds_tcp_kill_sock.patch
1 From foo@baz Mon Apr 15 09:15:08 CEST 2019
2 From: Mao Wenan <maowenan@huawei.com>
3 Date: Thu, 28 Mar 2019 17:10:56 +0800
4 Subject: net: rds: force to destroy connection if t_sock is NULL in rds_tcp_kill_sock().
5
6 From: Mao Wenan <maowenan@huawei.com>
7
8 [ Upstream commit cb66ddd156203daefb8d71158036b27b0e2caf63 ]
9
10 When it is to cleanup net namespace, rds_tcp_exit_net() will call
11 rds_tcp_kill_sock(), if t_sock is NULL, it will not call
12 rds_conn_destroy(), rds_conn_path_destroy() and rds_tcp_conn_free() to free
13 connection, and the worker cp_conn_w is not stopped, afterwards the net is freed in
14 net_drop_ns(); While cp_conn_w rds_connect_worker() will call rds_tcp_conn_path_connect()
15 and reference 'net' which has already been freed.
16
17 In rds_tcp_conn_path_connect(), rds_tcp_set_callbacks() will set t_sock = sock before
18 sock->ops->connect, but if connect() is failed, it will call
19 rds_tcp_restore_callbacks() and set t_sock = NULL, if connect is always
20 failed, rds_connect_worker() will try to reconnect all the time, so
21 rds_tcp_kill_sock() will never to cancel worker cp_conn_w and free the
22 connections.
23
24 Therefore, the condition !tc->t_sock is not needed if it is going to do
25 cleanup_net->rds_tcp_exit_net->rds_tcp_kill_sock, because tc->t_sock is always
26 NULL, and there is on other path to cancel cp_conn_w and free
27 connection. So this patch is to fix this.
28
29 rds_tcp_kill_sock():
30 ...
31 if (net != c_net || !tc->t_sock)
32 ...
33 Acked-by: Santosh Shilimkar <santosh.shilimkar@oracle.com>
34
35 ==================================================================
36 BUG: KASAN: use-after-free in inet_create+0xbcc/0xd28
37 net/ipv4/af_inet.c:340
38 Read of size 4 at addr ffff8003496a4684 by task kworker/u8:4/3721
39
40 CPU: 3 PID: 3721 Comm: kworker/u8:4 Not tainted 5.1.0 #11
41 Hardware name: linux,dummy-virt (DT)
42 Workqueue: krdsd rds_connect_worker
43 Call trace:
44 dump_backtrace+0x0/0x3c0 arch/arm64/kernel/time.c:53
45 show_stack+0x28/0x38 arch/arm64/kernel/traps.c:152
46 __dump_stack lib/dump_stack.c:77 [inline]
47 dump_stack+0x120/0x188 lib/dump_stack.c:113
48 print_address_description+0x68/0x278 mm/kasan/report.c:253
49 kasan_report_error mm/kasan/report.c:351 [inline]
50 kasan_report+0x21c/0x348 mm/kasan/report.c:409
51 __asan_report_load4_noabort+0x30/0x40 mm/kasan/report.c:429
52 inet_create+0xbcc/0xd28 net/ipv4/af_inet.c:340
53 __sock_create+0x4f8/0x770 net/socket.c:1276
54 sock_create_kern+0x50/0x68 net/socket.c:1322
55 rds_tcp_conn_path_connect+0x2b4/0x690 net/rds/tcp_connect.c:114
56 rds_connect_worker+0x108/0x1d0 net/rds/threads.c:175
57 process_one_work+0x6e8/0x1700 kernel/workqueue.c:2153
58 worker_thread+0x3b0/0xdd0 kernel/workqueue.c:2296
59 kthread+0x2f0/0x378 kernel/kthread.c:255
60 ret_from_fork+0x10/0x18 arch/arm64/kernel/entry.S:1117
61
62 Allocated by task 687:
63 save_stack mm/kasan/kasan.c:448 [inline]
64 set_track mm/kasan/kasan.c:460 [inline]
65 kasan_kmalloc+0xd4/0x180 mm/kasan/kasan.c:553
66 kasan_slab_alloc+0x14/0x20 mm/kasan/kasan.c:490
67 slab_post_alloc_hook mm/slab.h:444 [inline]
68 slab_alloc_node mm/slub.c:2705 [inline]
69 slab_alloc mm/slub.c:2713 [inline]
70 kmem_cache_alloc+0x14c/0x388 mm/slub.c:2718
71 kmem_cache_zalloc include/linux/slab.h:697 [inline]
72 net_alloc net/core/net_namespace.c:384 [inline]
73 copy_net_ns+0xc4/0x2d0 net/core/net_namespace.c:424
74 create_new_namespaces+0x300/0x658 kernel/nsproxy.c:107
75 unshare_nsproxy_namespaces+0xa0/0x198 kernel/nsproxy.c:206
76 ksys_unshare+0x340/0x628 kernel/fork.c:2577
77 __do_sys_unshare kernel/fork.c:2645 [inline]
78 __se_sys_unshare kernel/fork.c:2643 [inline]
79 __arm64_sys_unshare+0x38/0x58 kernel/fork.c:2643
80 __invoke_syscall arch/arm64/kernel/syscall.c:35 [inline]
81 invoke_syscall arch/arm64/kernel/syscall.c:47 [inline]
82 el0_svc_common+0x168/0x390 arch/arm64/kernel/syscall.c:83
83 el0_svc_handler+0x60/0xd0 arch/arm64/kernel/syscall.c:129
84 el0_svc+0x8/0xc arch/arm64/kernel/entry.S:960
85
86 Freed by task 264:
87 save_stack mm/kasan/kasan.c:448 [inline]
88 set_track mm/kasan/kasan.c:460 [inline]
89 __kasan_slab_free+0x114/0x220 mm/kasan/kasan.c:521
90 kasan_slab_free+0x10/0x18 mm/kasan/kasan.c:528
91 slab_free_hook mm/slub.c:1370 [inline]
92 slab_free_freelist_hook mm/slub.c:1397 [inline]
93 slab_free mm/slub.c:2952 [inline]
94 kmem_cache_free+0xb8/0x3a8 mm/slub.c:2968
95 net_free net/core/net_namespace.c:400 [inline]
96 net_drop_ns.part.6+0x78/0x90 net/core/net_namespace.c:407
97 net_drop_ns net/core/net_namespace.c:406 [inline]
98 cleanup_net+0x53c/0x6d8 net/core/net_namespace.c:569
99 process_one_work+0x6e8/0x1700 kernel/workqueue.c:2153
100 worker_thread+0x3b0/0xdd0 kernel/workqueue.c:2296
101 kthread+0x2f0/0x378 kernel/kthread.c:255
102 ret_from_fork+0x10/0x18 arch/arm64/kernel/entry.S:1117
103
104 The buggy address belongs to the object at ffff8003496a3f80
105 which belongs to the cache net_namespace of size 7872
106 The buggy address is located 1796 bytes inside of
107 7872-byte region [ffff8003496a3f80, ffff8003496a5e40)
108 The buggy address belongs to the page:
109 page:ffff7e000d25a800 count:1 mapcount:0 mapping:ffff80036ce4b000
110 index:0x0 compound_mapcount: 0
111 flags: 0xffffe0000008100(slab|head)
112 raw: 0ffffe0000008100 dead000000000100 dead000000000200 ffff80036ce4b000
113 raw: 0000000000000000 0000000080040004 00000001ffffffff 0000000000000000
114 page dumped because: kasan: bad access detected
115
116 Memory state around the buggy address:
117 ffff8003496a4580: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
118 ffff8003496a4600: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
119 >ffff8003496a4680: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
120 ^
121 ffff8003496a4700: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
122 ffff8003496a4780: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
123 ==================================================================
124
125 Fixes: 467fa15356ac("RDS-TCP: Support multiple RDS-TCP listen endpoints, one per netns.")
126 Reported-by: Hulk Robot <hulkci@huawei.com>
127 Signed-off-by: Mao Wenan <maowenan@huawei.com>
128 Signed-off-by: David S. Miller <davem@davemloft.net>
129 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
130 ---
131 net/rds/tcp.c | 2 +-
132 1 file changed, 1 insertion(+), 1 deletion(-)
133
134 --- a/net/rds/tcp.c
135 +++ b/net/rds/tcp.c
136 @@ -527,7 +527,7 @@ static void rds_tcp_kill_sock(struct net
137 list_for_each_entry_safe(tc, _tc, &rds_tcp_conn_list, t_tcp_node) {
138 struct net *c_net = read_pnet(&tc->t_cpath->cp_conn->c_net);
139
140 - if (net != c_net || !tc->t_sock)
141 + if (net != c_net)
142 continue;
143 if (!list_has_conn(&tmp_list, tc->t_cpath->cp_conn)) {
144 list_move_tail(&tc->t_tcp_node, &tmp_list);