Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC4FEC04A68 for ; Thu, 28 Jul 2022 16:14:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233003AbiG1QOT (ORCPT ); Thu, 28 Jul 2022 12:14:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232997AbiG1QN4 (ORCPT ); Thu, 28 Jul 2022 12:13:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AEF66F7FB for ; Thu, 28 Jul 2022 09:13:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8C98F61C61 for ; Thu, 28 Jul 2022 16:13:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6950CC433C1; Thu, 28 Jul 2022 16:13:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659024834; bh=qQutBS72eiffF4P4V4Os6GY17cXXD43YWpoFdyGcBN8=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=gdIlltz6pYIGz2Z89Yz6HHdUTDR9kou6hkAOm+9B5WpRVSMAy3sTsLcoiDnyXEzSj in2Ipm2GCMXmgZ0fmV76/Fd5eHtReDFJluiwEm/FCPUKJf9/R6Cboc2y7i3zMnGExy sum3Q9PVw931hXEQmYwzKdeHn/3CLfMzD/hSEFjX1c/HrhYA3tABagLRTYzZ7OFYuV FwG8ofD4Fhy2PsXMkd/yfcKEkBjjx9rewRxh91ab5Q2sS2qP2cBXpXknNcetKFC1gN akOTZF473eCLj6h35nrXZfY171NcJRqw2T5LL7jeH7jRQxjbYmfIPyA7Al+4ARbmvC WGp93OUhJ1l9w== Message-ID: <8fca8bc2-d8a8-eb41-9649-f96b5801f72c@kernel.org> Date: Thu, 28 Jul 2022 10:13:52 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v2 net] net: ping6: Fix memleak in ipv6_renew_options(). Content-Language: en-US To: Kuniyuki Iwashima , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Lorenzo Colitti , Benjamin Herrenschmidt , Ayushman Dutta , netdev@vger.kernel.org, syzbot+a8430774139ec3ab7176@syzkaller.appspotmail.com References: <20220728012220.46918-1-kuniyu@amazon.com> From: David Ahern In-Reply-To: <20220728012220.46918-1-kuniyu@amazon.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On 7/27/22 7:22 PM, Kuniyuki Iwashima wrote: > When we close ping6 sockets, some resources are left unfreed because > pingv6_prot is missing sk->sk_prot->destroy(). As reported by > syzbot [0], just three syscalls leak 96 bytes and easily cause OOM. > > struct ipv6_sr_hdr *hdr; > char data[24] = {0}; > int fd; > > hdr = (struct ipv6_sr_hdr *)data; > hdr->hdrlen = 2; > hdr->type = IPV6_SRCRT_TYPE_4; > > fd = socket(AF_INET6, SOCK_DGRAM, NEXTHDR_ICMP); > setsockopt(fd, IPPROTO_IPV6, IPV6_RTHDR, data, 24); > close(fd); > > To fix memory leaks, let's add a destroy function. > > Note the socket() syscall checks if the GID is within the range of > net.ipv4.ping_group_range. The default value is [1, 0] so that no > GID meets the condition (1 <= GID <= 0). Thus, the local DoS does > not succeed until we change the default value. However, at least > Ubuntu/Fedora/RHEL loosen it. > > $ cat /usr/lib/sysctl.d/50-default.conf > ... > -net.ipv4.ping_group_range = 0 2147483647 > > Also, there could be another path reported with these options, and > some of them require CAP_NET_RAW. > > setsockopt > IPV6_ADDRFORM (inet6_sk(sk)->pktoptions) > IPV6_RECVPATHMTU (inet6_sk(sk)->rxpmtu) > IPV6_HOPOPTS (inet6_sk(sk)->opt) > IPV6_RTHDRDSTOPTS (inet6_sk(sk)->opt) > IPV6_RTHDR (inet6_sk(sk)->opt) > IPV6_DSTOPTS (inet6_sk(sk)->opt) > IPV6_2292PKTOPTIONS (inet6_sk(sk)->opt) > > getsockopt > IPV6_FLOWLABEL_MGR (inet6_sk(sk)->ipv6_fl_list) > > For the record, I left a different splat with syzbot's one. > > unreferenced object 0xffff888006270c60 (size 96): > comm "repro2", pid 231, jiffies 4294696626 (age 13.118s) > hex dump (first 32 bytes): > 01 00 00 00 44 00 00 00 00 00 00 00 00 00 00 00 ....D........... > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ > backtrace: > [<00000000f6bc7ea9>] sock_kmalloc (net/core/sock.c:2564 net/core/sock.c:2554) > [<000000006d699550>] do_ipv6_setsockopt.constprop.0 (net/ipv6/ipv6_sockglue.c:715) > [<00000000c3c3b1f5>] ipv6_setsockopt (net/ipv6/ipv6_sockglue.c:1024) > [<000000007096a025>] __sys_setsockopt (net/socket.c:2254) > [<000000003a8ff47b>] __x64_sys_setsockopt (net/socket.c:2265 net/socket.c:2262 net/socket.c:2262) > [<000000007c409dcb>] do_syscall_64 (arch/x86/entry/common.c:50 arch/x86/entry/common.c:80) > [<00000000e939c4a9>] entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:120) > > [0]: https://syzkaller.appspot.com/bug?extid=a8430774139ec3ab7176 > > Fixes: 6d0bfe226116 ("net: ipv6: Add IPv6 support to the ping socket.") > Reported-by: syzbot+a8430774139ec3ab7176@syzkaller.appspotmail.com > Reported-by: Ayushman Dutta > Signed-off-by: Kuniyuki Iwashima > --- > v2: > - Remove ip6_flush_pending_frames() (Jakub Kicinski) > > v1: offlist > --- > net/ipv6/ping.c | 6 ++++++ > 1 file changed, 6 insertions(+) > Reviewed-by: David Ahern