Browse code

socket: close race condition between sock_close() and sockfs_setattr() to fix CVE-2019-8912

Change-Id: I2121ce299b206ec3a5c6e902b9e255272b81ae26
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/6776
Reviewed-by: Anish Swaminathan <anishs@vmware.com>
Tested-by: Anish Swaminathan <anishs@vmware.com>

Him Kalyan Bordoloi authored on 2019/02/22 00:16:55
Showing 5 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,115 @@
0
+KASAN has found use-after-free in sockfs_setattr.
1
+The existed commit 6d8c50dcb029 ("socket: close race condition between sock_close()
2
+and sockfs_setattr()") is to fix this simillar issue, but it seems to ignore
3
+that crypto module forgets to set the sk to NULL after af_alg_release.
4
+
5
+KASAN report details as below:
6
+BUG: KASAN: use-after-free in sockfs_setattr+0x120/0x150
7
+Write of size 4 at addr ffff88837b956128 by task syz-executor0/4186
8
+
9
+CPU: 2 PID: 4186 Comm: syz-executor0 Not tainted xxx + #1
10
+Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
11
+1.10.2-1ubuntu1 04/01/2014
12
+Call Trace:
13
+ dump_stack+0xca/0x13e
14
+ print_address_description+0x79/0x330
15
+ ? vprintk_func+0x5e/0xf0
16
+ kasan_report+0x18a/0x2e0
17
+ ? sockfs_setattr+0x120/0x150
18
+ sockfs_setattr+0x120/0x150
19
+ ? sock_register+0x2d0/0x2d0
20
+ notify_change+0x90c/0xd40
21
+ ? chown_common+0x2ef/0x510
22
+ chown_common+0x2ef/0x510
23
+ ? chmod_common+0x3b0/0x3b0
24
+ ? __lock_is_held+0xbc/0x160
25
+ ? __sb_start_write+0x13d/0x2b0
26
+ ? __mnt_want_write+0x19a/0x250
27
+ do_fchownat+0x15c/0x190
28
+ ? __ia32_sys_chmod+0x80/0x80
29
+ ? trace_hardirqs_on_thunk+0x1a/0x1c
30
+ __x64_sys_fchownat+0xbf/0x160
31
+ ? lockdep_hardirqs_on+0x39a/0x5e0
32
+ do_syscall_64+0xc8/0x580
33
+ entry_SYSCALL_64_after_hwframe+0x49/0xbe
34
+RIP: 0033:0x462589
35
+Code: f7 d8 64 89 02 b8 ff ff ff ff c3 66 0f 1f 44 00 00 48 89 f8 48 89
36
+f7 48 89 d6 48 89
37
+ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3
38
+48 c7 c1 bc ff ff
39
+ff f7 d8 64 89 01 48
40
+RSP: 002b:00007fb4b2c83c58 EFLAGS: 00000246 ORIG_RAX: 0000000000000104
41
+RAX: ffffffffffffffda RBX: 000000000072bfa0 RCX: 0000000000462589
42
+RDX: 0000000000000000 RSI: 00000000200000c0 RDI: 0000000000000007
43
+RBP: 0000000000000005 R08: 0000000000001000 R09: 0000000000000000
44
+R10: 0000000000000000 R11: 0000000000000246 R12: 00007fb4b2c846bc
45
+R13: 00000000004bc733 R14: 00000000006f5138 R15: 00000000ffffffff
46
+
47
+Allocated by task 4185:
48
+ kasan_kmalloc+0xa0/0xd0
49
+ __kmalloc+0x14a/0x350
50
+ sk_prot_alloc+0xf6/0x290
51
+ sk_alloc+0x3d/0xc00
52
+ af_alg_accept+0x9e/0x670
53
+ hash_accept+0x4a3/0x650
54
+ __sys_accept4+0x306/0x5c0
55
+ __x64_sys_accept4+0x98/0x100
56
+ do_syscall_64+0xc8/0x580
57
+ entry_SYSCALL_64_after_hwframe+0x49/0xbe
58
+
59
+Freed by task 4184:
60
+ __kasan_slab_free+0x12e/0x180
61
+ kfree+0xeb/0x2f0
62
+ __sk_destruct+0x4e6/0x6a0
63
+ sk_destruct+0x48/0x70
64
+ __sk_free+0xa9/0x270
65
+ sk_free+0x2a/0x30
66
+ af_alg_release+0x5c/0x70
67
+ __sock_release+0xd3/0x280
68
+ sock_close+0x1a/0x20
69
+ __fput+0x27f/0x7f0
70
+ task_work_run+0x136/0x1b0
71
+ exit_to_usermode_loop+0x1a7/0x1d0
72
+ do_syscall_64+0x461/0x580
73
+ entry_SYSCALL_64_after_hwframe+0x49/0xbe
74
+
75
+Syzkaller reproducer:
76
+r0 = perf_event_open(&(0x7f0000000000)={0x0, 0x70, 0x0, 0x0, 0x0, 0x0,
77
+0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
78
+0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
79
+0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, @perf_config_ext}, 0x0, 0x0,
80
+0xffffffffffffffff, 0x0)
81
+r1 = socket$alg(0x26, 0x5, 0x0)
82
+getrusage(0x0, 0x0)
83
+bind(r1, &(0x7f00000001c0)=@alg={0x26, 'hash\x00', 0x0, 0x0,
84
+'sha256-ssse3\x00'}, 0x80)
85
+r2 = accept(r1, 0x0, 0x0)
86
+r3 = accept4$unix(r2, 0x0, 0x0, 0x0)
87
+r4 = dup3(r3, r0, 0x0)
88
+fchownat(r4, &(0x7f00000000c0)='\x00', 0x0, 0x0, 0x1000)
89
+
90
+Fixes: 6d8c50dcb029 ("socket: close race condition between sock_close() and sockfs_setattr()")
91
+Signed-off-by: Mao Wenan <maowenan@huawei.com>
92
+---
93
+ crypto/af_alg.c | 4 +++-
94
+ 1 file changed, 3 insertions(+), 1 deletion(-)
95
+
96
+diff --git a/crypto/af_alg.c b/crypto/af_alg.c
97
+index 17eb09d..ec78a04 100644
98
+--- a/crypto/af_alg.c
99
+@@ -122,8 +122,10 @@ static void alg_do_release(const struct af_alg_type *type, void *private)
100
+ 
101
+ int af_alg_release(struct socket *sock)
102
+ {
103
+-	if (sock->sk)
104
++	if (sock->sk) {
105
+ 		sock_put(sock->sk);
106
++		sock->sk = NULL;
107
++	}
108
+ 	return 0;
109
+ }
110
+ EXPORT_SYMBOL_GPL(af_alg_release);
111
+-- 
112
+2.7.4
113
+
... ...
@@ -2,7 +2,7 @@
2 2
 Summary:        Kernel
3 3
 Name:           linux-aws
4 4
 Version:        4.9.154
5
-Release:        1%{?kat_build:.%kat_build}%{?dist}
5
+Release:        2%{?kat_build:.%kat_build}%{?dist}
6 6
 License:    	GPLv2
7 7
 URL:        	http://www.kernel.org/
8 8
 Group:        	System Environment/Kernel
... ...
@@ -61,7 +61,8 @@ Patch45:        0001-xfs-set-format-back-to-extents-if-xfs_bmap_extents_t.patch
61 61
 Patch46:        0001-xfs-move-inode-fork-verifiers-to-xfs-dinode-verify.patch
62 62
 Patch47:        0002-xfs-verify-dinode-header-first.patch
63 63
 Patch48:        0003-xfs-enhance-dinode-verifier.patch
64
-
64
+#Fix CVE-2019-8912
65
+Patch49:        fix_use_after_free_in_sockfs_setattr.patch
65 66
 # Out-of-tree patches from AppArmor:
66 67
 Patch71: 0001-UBUNTU-SAUCE-AppArmor-basic-networking-rules.patch
67 68
 Patch72: 0002-apparmor-Fix-quieting-of-audit-messages-for-network-.patch
... ...
@@ -225,6 +226,7 @@ This package contains the 'perf' performance analysis tools for Linux kernel.
225 225
 %patch46 -p1
226 226
 %patch47 -p1
227 227
 %patch48 -p1
228
+%patch49 -p1
228 229
 
229 230
 %patch71 -p1
230 231
 %patch72 -p1
... ...
@@ -434,6 +436,8 @@ ln -sf %{name}-%{uname_r}.cfg /boot/photon.cfg
434 434
 /usr/share/doc/*
435 435
 
436 436
 %changelog
437
+*   Thu Feb 21 2019 Him Kalyan Bordoloi <bordoloih@vmware.com> 4.9.154-2
438
+-   Fix CVE-2019-8912
437 439
 *   Mon Feb 04 2019 Ajay Kaher <akaher@vmware.com> 4.9.154-1
438 440
 -   Update to version 4.9.154
439 441
 *   Tue Jan 15 2019 Alexey Makhalov <amakhalov@vmware.com> 4.9.140-2
... ...
@@ -2,7 +2,7 @@
2 2
 Summary:        Kernel
3 3
 Name:           linux-esx
4 4
 Version:        4.9.154
5
-Release:        1%{?dist}
5
+Release:        2%{?dist}
6 6
 License:        GPLv2
7 7
 URL:            http://www.kernel.org/
8 8
 Group:          System Environment/Kernel
... ...
@@ -57,6 +57,8 @@ Patch45:        0001-xfs-set-format-back-to-extents-if-xfs_bmap_extents_t.patch
57 57
 Patch46:        0001-xfs-move-inode-fork-verifiers-to-xfs-dinode-verify.patch
58 58
 Patch47:        0002-xfs-verify-dinode-header-first.patch
59 59
 Patch48:        0003-xfs-enhance-dinode-verifier.patch
60
+#Fix CVE-2019-8912
61
+Patch49:        fix_use_after_free_in_sockfs_setattr.patch
60 62
 
61 63
 BuildRequires: bc
62 64
 BuildRequires: kbd
... ...
@@ -132,7 +134,7 @@ The Linux package contains the Linux kernel doc files
132 132
 %patch46 -p1
133 133
 %patch47 -p1
134 134
 %patch48 -p1
135
-
135
+%patch49 -p1
136 136
 
137 137
 %build
138 138
 
... ...
@@ -227,6 +229,8 @@ ln -sf linux-%{uname_r}.cfg /boot/photon.cfg
227 227
 /usr/src/linux-headers-%{uname_r}
228 228
 
229 229
 %changelog
230
+*   Thu Feb 21 2019 Him Kalyan Bordoloi <bordoloih@vmware.com> 4.9.154-2
231
+-   Fix CVE-2019-8912
230 232
 *   Mon Feb 04 2019 Ajay Kaher <akaher@vmware.com> 4.9.154-1
231 233
 -   Update to version 4.9.154
232 234
 *   Tue Jan 08 2019 Srivatsa S. Bhat (VMware) <srivatsa@csail.mit.edu> 4.9.140-3
... ...
@@ -2,7 +2,7 @@
2 2
 Summary:        Kernel
3 3
 Name:           linux-secure
4 4
 Version:        4.9.154
5
-Release:        1%{?kat_build:.%kat_build}%{?dist}
5
+Release:        2%{?kat_build:.%kat_build}%{?dist}
6 6
 License:        GPLv2
7 7
 URL:            http://www.kernel.org/
8 8
 Group:          System Environment/Kernel
... ...
@@ -67,6 +67,8 @@ Patch47:        0001-xfs-set-format-back-to-extents-if-xfs_bmap_extents_t.patch
67 67
 Patch48:        0001-xfs-move-inode-fork-verifiers-to-xfs-dinode-verify.patch
68 68
 Patch49:        0002-xfs-verify-dinode-header-first.patch
69 69
 Patch50:        0003-xfs-enhance-dinode-verifier.patch
70
+#Fix CVE-2019-8912
71
+Patch51:        fix_use_after_free_in_sockfs_setattr.patch
70 72
 
71 73
 # Out-of-tree patches from AppArmor:
72 74
 Patch71: 0001-UBUNTU-SAUCE-AppArmor-basic-networking-rules.patch
... ...
@@ -191,7 +193,7 @@ EOF
191 191
 %patch48 -p1
192 192
 %patch49 -p1
193 193
 %patch50 -p1
194
-
194
+%patch51 -p1
195 195
 
196 196
 %patch71 -p1
197 197
 %patch72 -p1
... ...
@@ -325,6 +327,8 @@ ln -sf linux-%{uname_r}.cfg /boot/photon.cfg
325 325
 /usr/src/linux-headers-%{uname_r}
326 326
 
327 327
 %changelog
328
+*   Thu Feb 21 2019 Him Kalyan Bordoloi <bordoloih@vmware.com> 4.9.154-2
329
+-   Fix CVE-2019-8912
328 330
 *   Mon Feb 04 2019 Ajay Kaher <akaher@vmware.com> 4.9.154-1
329 331
 -   Update to version 4.9.154
330 332
 *   Tue Jan 15 2019 Alexey Makhalov <amakhalov@vmware.com> 4.9.140-3
... ...
@@ -2,7 +2,7 @@
2 2
 Summary:        Kernel
3 3
 Name:           linux
4 4
 Version:        4.9.154
5
-Release:        1%{?kat_build:.%kat_build}%{?dist}
5
+Release:        2%{?kat_build:.%kat_build}%{?dist}
6 6
 License:    	GPLv2
7 7
 URL:        	http://www.kernel.org/
8 8
 Group:        	System Environment/Kernel
... ...
@@ -74,12 +74,15 @@ Patch53:        0003_PCI_hv_Use_vPCI_protocol_version_1.2_v4.9.patch
74 74
 # HyperV PCI patches to solve IRQ no handler problem
75 75
 Patch54:        0004-PCI-hv-Use-effective-affinity-mask.patch
76 76
 Patch55:        0005-x86-irq-implement-irq_data_get_effective_affinity.patch
77
+#Fix CVE-2019-8912
78
+Patch56:        fix_use_after_free_in_sockfs_setattr.patch
77 79
 
78 80
 # Out-of-tree patches from AppArmor:
79 81
 Patch71: 0001-UBUNTU-SAUCE-AppArmor-basic-networking-rules.patch
80 82
 Patch72: 0002-apparmor-Fix-quieting-of-audit-messages-for-network-.patch
81 83
 Patch73: 0003-UBUNTU-SAUCE-apparmor-Add-the-ability-to-mediate-mou.patch
82 84
 
85
+
83 86
 %if 0%{?kat_build:1}
84 87
 Patch1000:	%{kat_build}.patch
85 88
 %endif
... ...
@@ -197,6 +200,7 @@ This package contains the 'perf' performance analysis tools for Linux kernel.
197 197
 %patch53 -p1
198 198
 %patch54 -p1
199 199
 %patch55 -p1
200
+%patch56 -p1
200 201
 
201 202
 %patch71 -p1
202 203
 %patch72 -p1
... ...
@@ -371,6 +375,8 @@ ln -sf %{name}-%{uname_r}.cfg /boot/photon.cfg
371 371
 /usr/share/doc/*
372 372
 
373 373
 %changelog
374
+*   Thu Feb 21 2019 Him Kalyan Bordoloi <bordoloih@vmware.com> 4.9.154-2
375
+-   Fix CVE-2019-8912
374 376
 *   Mon Feb 04 2019 Ajay Kaher <akaher@vmware.com> 4.9.154-1
375 377
 -   Update to version 4.9.154
376 378
 *   Wed Jan 23 2019 Ajay Kaher <akaher@vmware.com> 4.9.140-6