From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754839AbcAWUF2 (ORCPT ); Sat, 23 Jan 2016 15:05:28 -0500 Received: from www62.your-server.de ([213.133.104.62]:41462 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754045AbcAWUFU (ORCPT ); Sat, 23 Jan 2016 15:05:20 -0500 Message-ID: <56A3DCF7.7000404@iogearbox.net> Date: Sat, 23 Jan 2016 21:05:11 +0100 From: Daniel Borkmann User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Florian Westphal , Dmitry Vyukov CC: "David S. Miller" , Herbert Xu , Thomas Graf , Ken-ichirou MATSUZAWA , Eric Dumazet , David Herrmann , Nicolas Dichtel , netdev , LKML , syzkaller , Kostya Serebryany , Alexander Potapenko , Sasha Levin , netfilter-devel@vger.kernel.org Subject: Re: net: GPF in netlink_getsockbyportid References: <20160123192502.GB17729@breakpoint.cc> In-Reply-To: <20160123192502.GB17729@breakpoint.cc> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/23/2016 08:25 PM, Florian Westphal wrote: > Dmitry Vyukov wrote: > > [ CC nf-devel, not sure if its nfnetlink fault or NETLINK_MMAP ] > >> The following program causes GPF in netlink_getsockbyportid: >> >> // autogenerated by syzkaller (http://github.com/google/syzkaller) >> #include >> #include >> #include >> #include >> #include >> >> int main() >> { >> syscall(SYS_mmap, 0x20000000ul, 0xe65000ul, 0x3ul, 0x32ul, >> 0xfffffffffffffffful, 0x0ul); >> int fd = syscall(SYS_socket, 0x10ul, 0x803ul, 0xcul, 0, 0, 0); >> *(uint32_t*)0x20e64000 = (uint32_t)0x28; >> *(uint32_t*)0x20e64004 = (uint32_t)0x10; >> *(uint64_t*)0x20e64008 = (uint64_t)0x0; >> *(uint64_t*)0x20e64010 = (uint64_t)0x3; >> *(uint64_t*)0x20e64018 = (uint64_t)0xfff; >> *(uint16_t*)0x20e64020 = (uint16_t)0x5; >> syscall(SYS_write, fd, 0x20e64000ul, 0x28ul, 0, 0, 0); >> return 0; >> } > > CONFIG_NETLINK_MMAP and nfnetlink batching strike in unison :-/ > > root cause is in nfnetlink_rcv_batch(): > > 296 replay: > 297 status = 0; > 298 > 299 skb = netlink_skb_clone(oskb, GFP_KERNEL); > > The clone op doesn't copy oskb->sk, so we oops in > __netlink_alloc_skb -> netlink_getsockbyportid() when nfnetlink_rcv_batch > tries to send netlink ack. If indeed oskb is the mmap'ed netlink skb, then it's not even allowed to call into skb_clone() as it would access skb shared info data that can be controlled by the user space mmap buffer, iirc, we had that in the past with nlmon where skb_clone() was accidentally used.