android_kernel_samsung_msm8226/crypto
Mao Wenan 02add32ab8 net: crypto set sk to NULL when af_alg_release.
KASAN has found use-after-free in sockfs_setattr.
The existed commit 6d8c50dcb029 ("socket: close race condition between sock_close()
and sockfs_setattr()") is to fix this simillar issue, but it seems to ignore
that crypto module forgets to set the sk to NULL after af_alg_release.

KASAN report details as below:
BUG: KASAN: use-after-free in sockfs_setattr+0x120/0x150
Write of size 4 at addr ffff88837b956128 by task syz-executor0/4186

CPU: 2 PID: 4186 Comm: syz-executor0 Not tainted xxx + #1
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
1.10.2-1ubuntu1 04/01/2014
Call Trace:
 dump_stack+0xca/0x13e
 print_address_description+0x79/0x330
 ? vprintk_func+0x5e/0xf0
 kasan_report+0x18a/0x2e0
 ? sockfs_setattr+0x120/0x150
 sockfs_setattr+0x120/0x150
 ? sock_register+0x2d0/0x2d0
 notify_change+0x90c/0xd40
 ? chown_common+0x2ef/0x510
 chown_common+0x2ef/0x510
 ? chmod_common+0x3b0/0x3b0
 ? __lock_is_held+0xbc/0x160
 ? __sb_start_write+0x13d/0x2b0
 ? __mnt_want_write+0x19a/0x250
 do_fchownat+0x15c/0x190
 ? __ia32_sys_chmod+0x80/0x80
 ? trace_hardirqs_on_thunk+0x1a/0x1c
 __x64_sys_fchownat+0xbf/0x160
 ? lockdep_hardirqs_on+0x39a/0x5e0
 do_syscall_64+0xc8/0x580
 entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x462589
Code: f7 d8 64 89 02 b8 ff ff ff ff c3 66 0f 1f 44 00 00 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 73 01 c3
48 c7 c1 bc ff ff
ff f7 d8 64 89 01 48
RSP: 002b:00007fb4b2c83c58 EFLAGS: 00000246 ORIG_RAX: 0000000000000104
RAX: ffffffffffffffda RBX: 000000000072bfa0 RCX: 0000000000462589
RDX: 0000000000000000 RSI: 00000000200000c0 RDI: 0000000000000007
RBP: 0000000000000005 R08: 0000000000001000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00007fb4b2c846bc
R13: 00000000004bc733 R14: 00000000006f5138 R15: 00000000ffffffff

Allocated by task 4185:
 kasan_kmalloc+0xa0/0xd0
 __kmalloc+0x14a/0x350
 sk_prot_alloc+0xf6/0x290
 sk_alloc+0x3d/0xc00
 af_alg_accept+0x9e/0x670
 hash_accept+0x4a3/0x650
 __sys_accept4+0x306/0x5c0
 __x64_sys_accept4+0x98/0x100
 do_syscall_64+0xc8/0x580
 entry_SYSCALL_64_after_hwframe+0x49/0xbe

Freed by task 4184:
 __kasan_slab_free+0x12e/0x180
 kfree+0xeb/0x2f0
 __sk_destruct+0x4e6/0x6a0
 sk_destruct+0x48/0x70
 __sk_free+0xa9/0x270
 sk_free+0x2a/0x30
 af_alg_release+0x5c/0x70
 __sock_release+0xd3/0x280
 sock_close+0x1a/0x20
 __fput+0x27f/0x7f0
 task_work_run+0x136/0x1b0
 exit_to_usermode_loop+0x1a7/0x1d0
 do_syscall_64+0x461/0x580
 entry_SYSCALL_64_after_hwframe+0x49/0xbe

Syzkaller reproducer:
r0 = perf_event_open(&(0x7f0000000000)={0x0, 0x70, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, @perf_config_ext}, 0x0, 0x0,
0xffffffffffffffff, 0x0)
r1 = socket$alg(0x26, 0x5, 0x0)
getrusage(0x0, 0x0)
bind(r1, &(0x7f00000001c0)=@alg={0x26, 'hash\x00', 0x0, 0x0,
'sha256-ssse3\x00'}, 0x80)
r2 = accept(r1, 0x0, 0x0)
r3 = accept4$unix(r2, 0x0, 0x0, 0x0)
r4 = dup3(r3, r0, 0x0)
fchownat(r4, &(0x7f00000000c0)='\x00', 0x0, 0x0, 0x1000)

Fixes: 6d8c50dcb029 ("socket: close race condition between sock_close() and sockfs_setattr()")
Signed-off-by: Mao Wenan <maowenan@huawei.com>
CVE-2019-8912
Signed-off-by: Kevin F. Haggerty <haggertk@lineageos.org>

Change-Id: Iabf23d6dc8fe1c656d78e09ac787800016659d40
2020-03-07 14:01:45 +01:00
..
async_tx crypto: remove the second argument of k[un]map_atomic() 2012-03-20 21:48:16 +08:00
Kconfig crypto: add lz4 Cryptographic API 2019-08-06 08:17:38 +02:00
Makefile crypto: crypto_memneq - add equality testing of memory regions w/o timing leaks 2019-10-05 13:41:36 +02:00
ablk_helper.c crypto: create generic version of ablk_helper 2015-12-23 16:54:28 +05:30
ablkcipher.c Merge tag 'v3.4.113' into lineage-16.0 2019-08-05 14:20:47 +02:00
aead.c Merge tag 'v3.4.113' into lineage-16.0 2019-08-05 14:20:47 +02:00
aes_generic.c
af_alg.c net: crypto set sk to NULL when af_alg_release. 2020-03-07 14:01:45 +01:00
ahash.c crypto: ahash - Fix EINPROGRESS notification callback 2019-08-06 12:26:39 +02:00
algapi.c Merge tag 'v3.4.113' into lineage-16.0 2019-08-05 14:20:47 +02:00
algboss.c misc: Import SM-G900H kernel source code 2019-08-02 15:14:10 +02:00
algif_hash.c Merge tag 'v3.4.113' into lineage-16.0 2019-08-05 14:20:47 +02:00
algif_skcipher.c Merge tag 'v3.4.113' into lineage-16.0 2019-08-05 14:20:47 +02:00
ansi_cprng.c misc: Import SM-G900H kernel source code 2019-08-02 15:14:10 +02:00
anubis.c
api.c Merge tag 'v3.4.113' into lineage-16.0 2019-08-05 14:20:47 +02:00
arc4.c crypto: arc4 - Fixed coding style issues 2011-06-30 07:44:05 +08:00
authenc.c crypto: crypto_memneq - add equality testing of memory regions w/o timing leaks 2019-10-05 13:41:36 +02:00
authencesn.c crypto: crypto_memneq - add equality testing of memory regions w/o timing leaks 2019-10-05 13:41:36 +02:00
blkcipher.c Merge tag 'v3.4.113' into lineage-16.0 2019-08-05 14:20:47 +02:00
blowfish_common.c crypto: blowfish - split generic and common c code 2011-09-22 21:25:25 +10:00
blowfish_generic.c crypto: blowfish - rename C-version to blowfish_generic 2011-09-22 21:25:26 +10:00
camellia_generic.c crypto: camellia - rename camellia.c to camellia_generic.c 2012-03-14 17:25:55 +08:00
cast5.c crypto: cast5 - simplify if-statements 2010-11-13 21:47:55 +09:00
cast6.c
cbc.c misc: Import SM-G900H kernel source code 2019-08-02 15:14:10 +02:00
ccm.c crypto: crypto_memneq - add equality testing of memory regions w/o timing leaks 2019-10-05 13:41:36 +02:00
chainiv.c misc: Import SM-G900H kernel source code 2019-08-02 15:14:10 +02:00
cipher.c misc: Import SM-G900H kernel source code 2019-08-02 15:14:10 +02:00
compress.c
crc32c.c crypto: crc32c should use library implementation 2012-03-23 16:58:38 -07:00
cryptd.c Merge tag 'v3.4.113' into lineage-16.0 2019-08-05 14:20:47 +02:00
crypto_null.c
crypto_user.c Merge tag 'v3.4.113' into lineage-16.0 2019-08-05 14:20:47 +02:00
crypto_wq.c Merge tag 'v3.4.113' into lineage-16.0 2019-08-05 14:20:47 +02:00
ctr.c
cts.c
deflate.c net+crypto: Use vmalloc for zlib inflate buffers. 2011-06-29 05:48:41 -07:00
des_generic.c
drbg.c misc: Import SM-G900H kernel source code 2019-08-02 15:14:10 +02:00
ecb.c
eseqiv.c misc: Import SM-G900H kernel source code 2019-08-02 15:14:10 +02:00
fcrypt.c
fips.c misc: Import SM-G900H kernel source code 2019-08-02 15:14:10 +02:00
fips_integrity.c misc: Import SM-G900H kernel source code 2019-08-02 15:14:10 +02:00
first_file.c misc: Import SM-G900H kernel source code 2019-08-02 15:14:10 +02:00
gcm.c crypto: crypto_memneq - add equality testing of memory regions w/o timing leaks 2019-10-05 13:41:36 +02:00
gf128mul.c crypto: gf128mul - fix call to memset() 2011-07-08 17:21:21 +08:00
ghash-generic.c crypto: ghash - Avoid null pointer dereference if no key is set 2011-10-21 13:18:42 +02:00
hmac.c misc: Import SM-G900H kernel source code 2019-08-02 15:14:10 +02:00
internal.h crypto: Allow kernel to compile without CONFIG_CRYPTO_FIPS 2019-08-09 11:49:10 +02:00
khazad.c
krng.c
last_file.c misc: Import SM-G900H kernel source code 2019-08-02 15:14:10 +02:00
lrw.c crypto: lrw - add interface for parallelized cipher implementions 2011-11-09 11:50:31 +08:00
lz4.c crypto: lz4,lz4hc - fix decompression 2019-08-06 08:17:38 +02:00
lz4hc.c crypto: lz4,lz4hc - fix decompression 2019-08-06 08:17:38 +02:00
lzo.c
md4.c crypto: add module.h to those files that are explicitly using it 2011-10-31 19:31:11 -04:00
md5.c crypto: Move md5_transform to lib/md5.c 2011-08-06 18:32:45 -07:00
memneq.c crypto: crypto_memneq - add equality testing of memory regions w/o timing leaks 2019-10-05 13:41:36 +02:00
michael_mic.c
pcbc.c
pcompress.c Merge tag 'v3.4.113' into lineage-16.0 2019-08-05 14:20:47 +02:00
pcrypt.c crypto: pcrypt - Use the online cpumask as the default 2012-03-29 19:52:47 +08:00
proc.c crypto: Allow kernel to compile without CONFIG_CRYPTO_FIPS 2019-08-09 11:49:10 +02:00
ripemd.h
rmd128.c crypto: ripemd - Set module author and update email address 2011-01-04 23:34:03 +11:00
rmd160.c crypto: ripemd - Set module author and update email address 2011-01-04 23:34:03 +11:00
rmd256.c crypto: ripemd - Set module author and update email address 2011-01-04 23:34:03 +11:00
rmd320.c crypto: ripemd - Set module author and update email address 2011-01-04 23:34:03 +11:00
rng.c Merge tag 'v3.4.113' into lineage-16.0 2019-08-05 14:20:47 +02:00
salsa20_generic.c
scatterwalk.c crypto: remove the second argument of k[un]map_atomic() 2012-03-20 21:48:16 +08:00
seed.c
seqiv.c misc: Import SM-G900H kernel source code 2019-08-02 15:14:10 +02:00
serpent_generic.c crypto: serpent - rename serpent.c to serpent_generic.c 2011-11-30 16:12:44 +08:00
sha1_generic.c crypto: sha1 - export sha1_update for reuse 2011-08-10 19:00:28 +08:00
sha256_generic.c crypto: sha256 - Expose SHA256 generic routine to be callable externally. 2015-12-23 17:09:15 +05:30
sha512_generic.c crypto: sha512 - Expose generic sha512 routine to be callable from other modules 2015-12-23 17:11:14 +05:30
shash.c Merge tag 'v3.4.113' into lineage-16.0 2019-08-05 14:20:47 +02:00
tcrypt.c crypto: Allow kernel to compile without CONFIG_CRYPTO_FIPS 2019-08-09 11:49:10 +02:00
tcrypt.h crypto: tcrypt - add xts(serpent) tests 2011-11-09 11:57:56 +08:00
tea.c
testmgr.c misc: Import SM-G900H kernel source code 2019-08-02 15:14:10 +02:00
testmgr.h Merge tag 'v3.4.113' into lineage-16.0 2019-08-05 14:20:47 +02:00
tgr192.c
twofish_common.c crypto: twofish-x86_64-3way - add lrw support 2011-11-09 11:53:32 +08:00
twofish_generic.c
vmac.c crypto: add module.h to those files that are explicitly using it 2011-10-31 19:31:11 -04:00
wp512.c crypto: whirlpool - count rounds from 0 2011-10-21 14:24:16 +02:00
xcbc.c crypto: add module.h to those files that are explicitly using it 2011-10-31 19:31:11 -04:00
xor.c
xts.c crypto: xts: add interface for parallelized cipher implementations 2011-11-09 11:56:06 +08:00
zlib.c net+crypto: Use vmalloc for zlib inflate buffers. 2011-06-29 05:48:41 -07:00