From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752176AbbLUVcy (ORCPT ); Mon, 21 Dec 2015 16:32:54 -0500 Received: from mail.eperm.de ([89.247.134.16]:40734 "EHLO mail.eperm.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751563AbbLUVcw (ORCPT ); Mon, 21 Dec 2015 16:32:52 -0500 From: Stephan Mueller To: Dmitry Vyukov Cc: Herbert Xu , "David S. Miller" , linux-crypto@vger.kernel.org, LKML , syzkaller , Kostya Serebryany , Alexander Potapenko , Eric Dumazet , Sasha Levin , Kees Cook Subject: Re: use-after-free in skcipher_sock_destruct Date: Mon, 21 Dec 2015 22:32:49 +0100 Message-ID: <10592138.duBBLlR1dJ@myon.chronox.de> User-Agent: KMail/4.14.10 (Linux/4.2.6-301.fc23.x86_64; KDE/4.14.14; x86_64; ; ) In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am Donnerstag, 17. Dezember 2015, 13:56:12 schrieb Dmitry Vyukov: Hi Dmitry, > Hello, > > The following program triggers use-after-free in skcipher_sock_destruct: This issue is not evident after applying Herbert's patch converting the algif_skcipher from using ablkcipher to skcipher API. > > // autogenerated by syzkaller (http://github.com/google/syzkaller) > #include > #include > #include > #include > #include > #include > > struct sockaddr_alg { > unsigned short salg_family; > char salg_type[14]; > unsigned salg_feat; > unsigned salg_mask; > char salg_name[64]; > }; > > int fd; > > void *thr0(void *arg) > { > struct sockaddr_alg sa = {}; > sa.salg_family = 0x26; > memcpy(sa.salg_type, > "\x73\x6b\x63\x69\x70\x68\x65\x72\x00\x00\x00\x00\x00\x00", 14); > sa.salg_feat = 0xf; > sa.salg_mask = 0x100; > memcpy(sa.salg_name, > "\x65\x63\x62\x28\x73\x65\x72\x70\x65\x6e\x74\x29\x00\x00\x00\x00\x00\x00\x0 > 0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0 > 0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0 > 0\x00\x00\x00\x00\x00\x00\x00", 64); > bind(fd, (struct sockaddr*)&sa, sizeof(sa)); > return 0; > } > > void *thr1(void *arg) > { > accept4(fd, 0, 0, 0x800ul); > return 0; > } > > int main() > { > fd = socket(PF_ALG, SOCK_SEQPACKET, 0); > pthread_t th[4]; > pthread_create(&th[0], 0, thr0, 0); > pthread_create(&th[1], 0, thr1, 0); > pthread_create(&th[2], 0, thr0, 0); > pthread_create(&th[3], 0, thr1, 0); > pthread_join(th[0], 0); > pthread_join(th[1], 0); > pthread_join(th[2], 0); > pthread_join(th[3], 0); > return 0; > } > > > ================================================================== > BUG: KASAN: use-after-free in skcipher_sock_destruct+0x39c/0x3e0 at > addr ffff8800387a2d38 > Read of size 4 by task executor/27423 > ============================================================================ > = BUG kmalloc-96 (Not tainted): kasan: bad access detected > ---------------------------------------------------------------------------- > - > > Disabling lock debugging due to kernel taint > INFO: Allocated in __crypto_alloc_tfm+0xd9/0x470 age=36 cpu=0 pid=27396 > [< none >] __kmalloc+0x2d9/0x480 mm/slub.c:3532 > [< inline >] kmalloc include/linux/slab.h:463 > [< inline >] kzalloc include/linux/slab.h:602 > [< none >] __crypto_alloc_tfm+0xd9/0x470 crypto/api.c:374 > [< none >] crypto_alloc_ablkcipher+0x7b/0x1f0 > crypto/ablkcipher.c:699 [< none >] skcipher_bind+0x25/0x30 > crypto/algif_skcipher.c:754 [< none >] alg_bind+0x1a9/0x410 > crypto/af_alg.c:155 > [< none >] SYSC_bind+0x20a/0x2c0 net/socket.c:1383 > [< none >] SyS_bind+0x24/0x30 net/socket.c:1369 > [< none >] entry_SYSCALL_64_fastpath+0x16/0x7a > arch/x86/entry/entry_64.S:185 > > INFO: Freed in kzfree+0x28/0x30 age=26 cpu=2 pid=27421 > [< none >] kfree+0x26f/0x3e0 mm/slub.c:3632 > [< none >] kzfree+0x28/0x30 mm/slab_common.c:1270 > [< none >] crypto_destroy_tfm+0xdd/0x1e0 crypto/api.c:596 > [< inline >] crypto_free_tfm include/linux/crypto.h:623 > [< inline >] crypto_free_ablkcipher include/linux/crypto.h:769 > [< none >] skcipher_release+0x18/0x20 crypto/algif_skcipher.c:759 > [< inline >] alg_do_release crypto/af_alg.c:116 > [< none >] alg_bind+0x26a/0x410 crypto/af_alg.c:170 > [< none >] SYSC_bind+0x20a/0x2c0 net/socket.c:1383 > [< none >] SyS_bind+0x24/0x30 net/socket.c:1369 > [< none >] entry_SYSCALL_64_fastpath+0x16/0x7a > arch/x86/entry/entry_64.S:185 > > INFO: Slab 0xffffea0000e1e880 objects=19 used=8 fp=0xffff8800387a3380 > flags=0x1fffc0000004080 > INFO: Object 0xffff8800387a2d00 @offset=3328 fp=0xffff8800387a3520 > CPU: 0 PID: 27423 Comm: executor Tainted: G B 4.4.0-rc3+ #151 > Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011 > 0000000000000000 ffff880035c67700 ffffffff82e0f4b8 0000000041b58ab3 > ffffffff87a9a265 ffffffff82e0f406 ffff880037f15a00 ffffffff87abb3aa > ffff88003e804780 0000000000000008 ffff8800387a2d00 ffff880035c67700 > > Call Trace: > [] __asan_report_load4_noabort+0x54/0x70 > mm/kasan/report.c:294 > [< inline >] crypto_ablkcipher_ivsize include/linux/crypto.h:807 > [] skcipher_sock_destruct+0x39c/0x3e0 > crypto/algif_skcipher.c:787 > [] sk_destruct+0xa5/0x5f0 net/core/sock.c:1446 > [] __sk_free+0x8c/0x260 net/core/sock.c:1474 > [] sk_free+0x30/0x40 net/core/sock.c:1485 > [< inline >] sock_put include/net/sock.h:1625 > [] af_alg_release+0x60/0x90 crypto/af_alg.c:123 > [] sock_release+0x96/0x260 net/socket.c:571 > [] sock_close+0x16/0x20 net/socket.c:1022 > [] __fput+0x244/0x860 fs/file_table.c:208 > [] ____fput+0x15/0x20 fs/file_table.c:244 > [] task_work_run+0x130/0x240 kernel/task_work.c:115 > [< inline >] exit_task_work include/linux/task_work.h:21 > [] do_exit+0x885/0x3050 kernel/exit.c:750 > [] do_group_exit+0xec/0x390 kernel/exit.c:880 > [] get_signal+0x677/0x1bf0 kernel/signal.c:2307 > [] do_signal+0x7e/0x2170 arch/x86/kernel/signal.c:709 > [] exit_to_usermode_loop+0xfe/0x1e0 > arch/x86/entry/common.c:247 > [< inline >] prepare_exit_to_usermode arch/x86/entry/common.c:282 > [] syscall_return_slowpath+0x16b/0x240 > arch/x86/entry/common.c:344 > [] int_ret_from_sys_call+0x25/0x9f > arch/x86/entry/entry_64.S:281 > ================================================================== > > On upstream commit 31ade3b83e1821da5fbb2f11b5b3d4ab2ec39db8 (Nov 29). > -- > To unsubscribe from this list: send the line "unsubscribe linux-crypto" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html -- Ciao Stephan