Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753134AbbK2NSx (ORCPT ); Sun, 29 Nov 2015 08:18:53 -0500 Received: from mail-wm0-f48.google.com ([74.125.82.48]:36343 "EHLO mail-wm0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752435AbbK2NSu (ORCPT ); Sun, 29 Nov 2015 08:18:50 -0500 MIME-Version: 1.0 From: Dmitry Vyukov Date: Sun, 29 Nov 2015 14:18:29 +0100 Message-ID: Subject: user-controllable kmalloc size in bpf syscall To: Alexei Starovoitov , netdev , LKML Cc: syzkaller , Kostya Serebryany , Alexander Potapenko , Eric Dumazet , Sasha Levin , daniel@iogearbox.net Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3397 Lines: 87 Hello, The following program triggers a WARNING in kmalloc: // autogenerated by syzkaller (http://github.com/google/syzkaller) #include #include #include #define SYS_bpf 321 #define BPF_MAP_CREATE 0 #define BPF_MAP_UPDATE_ELEM 2 union bpf_attr { struct { uint32_t map_type; /* one of enum bpf_map_type */ uint32_t key_size; /* size of key in bytes */ uint32_t value_size; /* size of value in bytes */ uint32_t max_entries; /* max number of entries in a map */ }; struct { uint32_t map_fd; uint64_t key; uint64_t val; uint64_t flags; }; }; int main() { union bpf_attr ca; memset(&ca, 0, sizeof(ca)); ca.map_type = 1; ca.key_size = 1; ca.value_size = 0xfffffff9; ca.max_entries = 10; int fd = syscall(SYS_bpf, BPF_MAP_CREATE, &ca, sizeof(ca)); memset(&ca, 0, sizeof(ca)); ca.map_fd = fd; ca.key = &ca; ca.val = &ca; ca.flags = 0; syscall(SYS_bpf, BPF_MAP_UPDATE_ELEM, &ca, sizeof(ca)); return 0; } ------------[ cut here ]------------ WARNING: CPU: 2 PID: 11122 at mm/page_alloc.c:2989 __alloc_pages_nodemask+0x695/0x14e0() Modules linked in: CPU: 2 PID: 11122 Comm: syzkaller_execu Tainted: G B 4.4.0-rc2+ #5 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011 00000000ffffffff ffff880039aefa30 ffffffff82743b56 0000000000000000 ffff88003b2a0000 ffffffff85a8d0e0 ffff880039aefa70 ffffffff81244ec9 ffffffff81554e95 ffffffff85a8d0e0 0000000000000bad 0000000000000000 Call Trace: [< inline >] __dump_stack lib/dump_stack.c:15 [] dump_stack+0x68/0x92 lib/dump_stack.c:50 [] warn_slowpath_common+0xd9/0x140 kernel/panic.c:460 [] warn_slowpath_null+0x29/0x30 kernel/panic.c:493 [< inline >] __alloc_pages_slowpath mm/page_alloc.c:2989 [] __alloc_pages_nodemask+0x695/0x14e0 mm/page_alloc.c:3235 [] alloc_pages_current+0xee/0x340 mm/mempolicy.c:2055 [< inline >] alloc_pages include/linux/gfp.h:451 [] alloc_kmem_pages+0x16/0xf0 mm/page_alloc.c:3414 [] kmalloc_order+0x19/0x60 mm/slab_common.c:1007 [] kmalloc_order_trace+0x1f/0xa0 mm/slab_common.c:1018 [< inline >] kmalloc_large include/linux/slab.h:390 [] __kmalloc+0x234/0x250 mm/slub.c:3525 [< inline >] kmalloc include/linux/slab.h:463 [< inline >] map_update_elem kernel/bpf/syscall.c:288 [< inline >] SYSC_bpf kernel/bpf/syscall.c:744 [] SyS_bpf+0xfd4/0x1a20 kernel/bpf/syscall.c:695 [] entry_SYSCALL_64_fastpath+0x16/0x7a arch/x86/entry/entry_64.S:185 ---[ end trace f00640b4d448df95 ]--- On commit 78c4a49a69e910a162b05e4e8727b9bdbf948f13 (Now 25). -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/