use-after-free in skcipher_sock_destruct

56 views
Skip to first unread message

Dmitry Vyukov

unread,
Dec 17, 2015, 7:56:32 AM12/17/15
to Herbert Xu, David S. Miller, linux-...@vger.kernel.org, LKML, syzkaller, Kostya Serebryany, Alexander Potapenko, Eric Dumazet, Sasha Levin, Kees Cook
Hello,

The following program triggers use-after-free in skcipher_sock_destruct:

// autogenerated by syzkaller (http://github.com/google/syzkaller)
#include <syscall.h>
#include <string.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <pthread.h>

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\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\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:
[<ffffffff81845754>] __asan_report_load4_noabort+0x54/0x70
mm/kasan/report.c:294
[< inline >] crypto_ablkcipher_ivsize include/linux/crypto.h:807
[<ffffffff82d2d3bc>] skcipher_sock_destruct+0x39c/0x3e0
crypto/algif_skcipher.c:787
[<ffffffff856c9255>] sk_destruct+0xa5/0x5f0 net/core/sock.c:1446
[<ffffffff856c982c>] __sk_free+0x8c/0x260 net/core/sock.c:1474
[<ffffffff856c9a30>] sk_free+0x30/0x40 net/core/sock.c:1485
[< inline >] sock_put include/net/sock.h:1625
[<ffffffff82d26c50>] af_alg_release+0x60/0x90 crypto/af_alg.c:123
[<ffffffff856b06b6>] sock_release+0x96/0x260 net/socket.c:571
[<ffffffff856b0896>] sock_close+0x16/0x20 net/socket.c:1022
[<ffffffff8189d9e4>] __fput+0x244/0x860 fs/file_table.c:208
[<ffffffff8189e095>] ____fput+0x15/0x20 fs/file_table.c:244
[<ffffffff813e34d0>] task_work_run+0x130/0x240 kernel/task_work.c:115
[< inline >] exit_task_work include/linux/task_work.h:21
[<ffffffff8137d8f5>] do_exit+0x885/0x3050 kernel/exit.c:750
[<ffffffff8138021c>] do_group_exit+0xec/0x390 kernel/exit.c:880
[<ffffffff813ab067>] get_signal+0x677/0x1bf0 kernel/signal.c:2307
[<ffffffff8118645e>] do_signal+0x7e/0x2170 arch/x86/kernel/signal.c:709
[<ffffffff81003a1e>] exit_to_usermode_loop+0xfe/0x1e0
arch/x86/entry/common.c:247
[< inline >] prepare_exit_to_usermode arch/x86/entry/common.c:282
[<ffffffff8100733b>] syscall_return_slowpath+0x16b/0x240
arch/x86/entry/common.c:344
[<ffffffff86a8a122>] int_ret_from_sys_call+0x25/0x9f
arch/x86/entry/entry_64.S:281
==================================================================

On upstream commit 31ade3b83e1821da5fbb2f11b5b3d4ab2ec39db8 (Nov 29).

Stephan Mueller

unread,
Dec 21, 2015, 4:32:51 PM12/21/15
to Dmitry Vyukov, Herbert Xu, David S. Miller, linux-...@vger.kernel.org, LKML, syzkaller, Kostya Serebryany, Alexander Potapenko, Eric Dumazet, Sasha Levin, Kees Cook
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 <syscall.h>
> #include <string.h>
> #include <stdint.h>
> #include <sys/types.h>
> #include <sys/socket.h>
> #include <pthread.h>
>
> 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
> --
> To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
> the body of a message to majo...@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html


--
Ciao
Stephan
Reply all
Reply to author
Forward
0 new messages