Browse code

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

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

Him Kalyan Bordoloi authored on 2019/02/21 22:46:01
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.19.15
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
... ...
@@ -35,6 +35,8 @@ Patch29:        4.17-0001-apparmor-patch-to-provide-compatibility-with-v2.x-ne.p
35 35
 Patch30:        4.17-0002-apparmor-af_unix-mediation.patch
36 36
 Patch31:        4.17-0003-apparmor-fix-use-after-free-in-sk_peer_label.patch
37 37
 Patch32:        4.18-0001-hwrng-rdrand-Add-RNG-driver-based-on-x86-rdrand-inst.patch
38
+#Fix CVE-2019-8912
39
+Patch33:        fix_use_after_free_in_sockfs_setattr.patch
38 40
 
39 41
 # Amazon AWS
40 42
 Patch101: 0002-watchdog-Disable-watchdog-on-virtual-machines.patch
... ...
@@ -152,6 +154,7 @@ This package contains the 'perf' performance analysis tools for Linux kernel.
152 152
 %patch30 -p1
153 153
 %patch31 -p1
154 154
 %patch32 -p1
155
+%patch33 -p1
155 156
 
156 157
 %patch101 -p1
157 158
 %patch102 -p1
... ...
@@ -356,6 +359,8 @@ ln -sf %{name}-%{uname_r}.cfg /boot/photon.cfg
356 356
 %{_libdir}/perf/include/bpf/*
357 357
 
358 358
 %changelog
359
+*   Thu Feb 21 2019 Him Kalyan Bordoloi <bordoloih@vmware.com> 4.19.15-2
360
+-   Fix CVE-2019-8912
359 361
 *   Tue Jan 15 2019 Srivatsa S. Bhat (VMware) <srivatsa@csail.mit.edu> 4.19.15-1
360 362
 -   Update to version 4.19.15
361 363
 *   Mon Jan 07 2019 Srivatsa S. Bhat (VMware) <srivatsa@csail.mit.edu> 4.19.6-2
... ...
@@ -2,7 +2,7 @@
2 2
 Summary:        Kernel
3 3
 Name:           linux-esx
4 4
 Version:        4.19.15
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
... ...
@@ -39,6 +39,8 @@ Patch25:        4.18-0001-hwrng-rdrand-Add-RNG-driver-based-on-x86-rdrand-inst.p
39 39
 Patch26:        4.17-0001-apparmor-patch-to-provide-compatibility-with-v2.x-ne.patch
40 40
 Patch27:        4.17-0002-apparmor-af_unix-mediation.patch
41 41
 Patch28:        4.17-0003-apparmor-fix-use-after-free-in-sk_peer_label.patch
42
+#Fix CVE-2019-8912
43
+Patch29:        fix_use_after_free_in_sockfs_setattr.patch
42 44
 
43 45
 BuildArch:     x86_64
44 46
 BuildRequires: bc
... ...
@@ -97,6 +99,7 @@ The Linux package contains the Linux kernel doc files
97 97
 %patch26 -p1
98 98
 %patch27 -p1
99 99
 %patch28 -p1
100
+%patch29 -p1
100 101
 
101 102
 %build
102 103
 # patch vmw_balloon driver
... ...
@@ -193,6 +196,8 @@ ln -sf linux-%{uname_r}.cfg /boot/photon.cfg
193 193
 /usr/src/linux-headers-%{uname_r}
194 194
 
195 195
 %changelog
196
+*   Thu Feb 21 2019 Him Kalyan Bordoloi <bordoloih@vmware.com> 4.19.15-2
197
+-   Fix CVE-2019-8912
196 198
 *   Tue Jan 15 2019 Srivatsa S. Bhat (VMware) <srivatsa@csail.mit.edu> 4.19.15-1
197 199
 -   Update to version 4.19.15
198 200
 -   .config: Enable USB_SERIAL and USB_ACM
... ...
@@ -2,7 +2,7 @@
2 2
 Summary:        Kernel
3 3
 Name:           linux-secure
4 4
 Version:        4.19.15
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
... ...
@@ -38,6 +38,10 @@ Patch32:        4.17-0001-apparmor-patch-to-provide-compatibility-with-v2.x-ne.p
38 38
 Patch33:        4.17-0002-apparmor-af_unix-mediation.patch
39 39
 Patch34:        4.17-0003-apparmor-fix-use-after-free-in-sk_peer_label.patch
40 40
 Patch35:        4.18-0001-hwrng-rdrand-Add-RNG-driver-based-on-x86-rdrand-inst.patch
41
+#Fix CVE-2019-8912
42
+Patch36:        fix_use_after_free_in_sockfs_setattr.patch
43
+
44
+
41 45
 # NSX requirements (should be removed)
42 46
 Patch99:        LKCM.patch
43 47
 
... ...
@@ -107,6 +111,7 @@ The Linux package contains the Linux kernel doc files
107 107
 %patch33 -p1
108 108
 %patch34 -p1
109 109
 %patch35 -p1
110
+%patch36 -p1
110 111
 
111 112
 pushd ..
112 113
 %patch99 -p0
... ...
@@ -234,6 +239,8 @@ ln -sf linux-%{uname_r}.cfg /boot/photon.cfg
234 234
 /usr/src/linux-headers-%{uname_r}
235 235
 
236 236
 %changelog
237
+*   Thu Feb 21 2019 Him Kalyan Bordoloi <bordoloih@vmware.com> 4.19.15-2
238
+-   Fix CVE-2019-8912
237 239
 *   Tue Jan 15 2019 Srivatsa S. Bhat (VMware) <srivatsa@csail.mit.edu> 4.19.15-1
238 240
 -   Update to version 4.19.15
239 241
 *   Thu Jan 10 2019 Alexey Makhalov <amakhalov@vmware.com> 4.19.6-4
... ...
@@ -2,7 +2,7 @@
2 2
 Summary:        Kernel
3 3
 Name:           linux
4 4
 Version:        4.19.15
5
-Release:        2%{?kat_build:.%kat_build}%{?dist}
5
+Release:        3%{?kat_build:.%kat_build}%{?dist}
6 6
 License:    	GPLv2
7 7
 URL:        	http://www.kernel.org/
8 8
 Group:        	System Environment/Kernel
... ...
@@ -43,6 +43,9 @@ Patch29:        4.17-0001-apparmor-patch-to-provide-compatibility-with-v2.x-ne.p
43 43
 Patch30:        4.17-0002-apparmor-af_unix-mediation.patch
44 44
 Patch31:        4.17-0003-apparmor-fix-use-after-free-in-sk_peer_label.patch
45 45
 Patch32:        4.18-0001-hwrng-rdrand-Add-RNG-driver-based-on-x86-rdrand-inst.patch
46
+#Fix CVE-2019-8912
47
+Patch33:	fix_use_after_free_in_sockfs_setattr.patch
48
+
46 49
 %ifarch aarch64
47 50
 # NXP LS1012a FRWY patches
48 51
 Patch51:        0001-staging-fsl_ppfe-eth-header-files-for-pfe-driver.patch
... ...
@@ -179,6 +182,7 @@ Kernel Device Tree Blob files for NXP ls1012a FRWY board
179 179
 %patch30 -p1
180 180
 %patch31 -p1
181 181
 %patch32 -p1
182
+%patch33 -p1
182 183
 
183 184
 %ifarch aarch64
184 185
 # NXP FSL_PPFE Driver patches
... ...
@@ -437,6 +441,8 @@ ln -sf %{name}-%{uname_r}.cfg /boot/photon.cfg
437 437
 %endif
438 438
 
439 439
 %changelog
440
+*   Thu Feb 21 2019 Him Kalyan Bordoloi <bordoloih@vmware.com> 4.19.15-3
441
+-   Fix CVE-2019-8912
440 442
 *   Thu Jan 24 2019 Alexey Makhalov <amakhalov@vmware.com> 4.19.15-2
441 443
 -   Add WiFi (ath10k), sensors (i2c,spi), usb support for NXP LS1012A board.
442 444
 *   Tue Jan 15 2019 Srivatsa S. Bhat (VMware) <srivatsa@csail.mit.edu> 4.19.15-1