From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755569AbdCJSLA (ORCPT ); Fri, 10 Mar 2017 13:11:00 -0500 Received: from mail-ua0-f179.google.com ([209.85.217.179]:35439 "EHLO mail-ua0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755386AbdCJSKw (ORCPT ); Fri, 10 Mar 2017 13:10:52 -0500 MIME-Version: 1.0 From: Dmitry Vyukov Date: Fri, 10 Mar 2017 19:10:30 +0100 Message-ID: Subject: futex: use-after-free in futex_wait_requeue_pi To: Thomas Gleixner , bigeasy@linutronix.de, Davidlohr Bueso , Ingo Molnar , Peter Zijlstra , LKML Cc: syzkaller Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, The following program triggers use-after-free in futex_wait_requeue_pi: https://gist.githubusercontent.com/dvyukov/42e596153263793b75ad587c8d0626b0/raw/35461a6c1b0a4163a67191ff5d35202f35ecbf44/gistfile1.txt ================================================================== BUG: KASAN: use-after-free in futex_wait_requeue_pi+0xf5d/0x1160 kernel/futex.c:2942 at addr ffff880066ea7158 Read of size 8 by task a.out/4777 CPU: 0 PID: 4777 Comm: a.out Not tainted 4.11.0-rc1+ #326 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011 Call Trace: __asan_report_load8_noabort+0x29/0x30 mm/kasan/report.c:337 rt_mutex_owner include/linux/compiler.h:254 [inline] futex_wait_requeue_pi.constprop.20+0xf5d/0x1160 kernel/futex.c:2942 do_futex+0x813/0x1f20 kernel/futex.c:3236 SYSC_futex kernel/futex.c:3277 [inline] SyS_futex+0x2a9/0x3a0 kernel/futex.c:3245 entry_SYSCALL_64_fastpath+0x1f/0xc2 RIP: 0033:0x4412f9 RSP: 002b:00007f803bcd9c98 EFLAGS: 00000246 ORIG_RAX: 00000000000000ca RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00000000004412f9 RDX: 0000000000000004 RSI: 000080000000000b RDI: 000000002000cffc RBP: 0000000000000082 R08: 0000000020048000 R09: 0000000000000000 R10: 00007f803bcd9cd0 R11: 0000000000000246 R12: 0000000000000000 R13: 0000000000000000 R14: 00007f803bcda9c0 R15: 00007f803bcda700 Object at ffff880066ea7100, in cache kmalloc-192 size: 192 Allocated: PID = 4825 kzalloc include/linux/slab.h:663 [inline] refill_pi_state_cache.part.8+0xa5/0x2d0 kernel/futex.c:789 refill_pi_state_cache kernel/futex.c:1669 [inline] futex_requeue+0x18f8/0x2400 kernel/futex.c:1727 do_futex+0x7e1/0x1f20 kernel/futex.c:3239 SYSC_futex kernel/futex.c:3277 [inline] SyS_futex+0x2a9/0x3a0 kernel/futex.c:3245 entry_SYSCALL_64_fastpath+0x1f/0xc2 Freed: PID = 4777 kfree+0xed/0x280 mm/slab.c:3831 put_pi_state+0x3e0/0x540 kernel/futex.c:842 unqueue_me_pi+0x4a/0xc0 kernel/futex.c:2111 futex_wait_requeue_pi.constprop.20+0xc5a/0x1160 kernel/futex.c:2934 do_futex+0x813/0x1f20 kernel/futex.c:3236 SYSC_futex kernel/futex.c:3277 [inline] SyS_futex+0x2a9/0x3a0 kernel/futex.c:3245 entry_SYSCALL_64_fastpath+0x1f/0xc2 Memory state around the buggy address: ffff880066ea7000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ffff880066ea7080: 00 fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc >ffff880066ea7100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ^ ffff880066ea7180: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc ffff880066ea7200: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ================================================================== On commit c1aa905a304e4b5e6a3fe112ec62d9c1c7b0c155.