Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp1958689imn; Mon, 1 Aug 2022 06:19:33 -0700 (PDT) X-Google-Smtp-Source: AA6agR5lXIXLdMfLbSVijbS40TZaxJqCqzUL7me8GlPkvh5HROSU/+Cv3WTEoTCICbqMWuraovZy X-Received: by 2002:a17:902:7fcf:b0:16d:c92b:8ac1 with SMTP id t15-20020a1709027fcf00b0016dc92b8ac1mr16456371plb.74.1659359973086; Mon, 01 Aug 2022 06:19:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659359973; cv=none; d=google.com; s=arc-20160816; b=JKDGZzMEkZjVhEJUc2s7wvPgBZfH54iNPn6FNgjzU7wyMQrGtzHfoqVAG/K/YKivEr ASByne4cIVSbC9bsnZPo6Ocw69IhCgQpa7f3LRzFXxFOwouVTqfHjuGiYXT9MhDjqZ9V aA54FpZiuPl4RVaFnXLxU8mgRrHVm2ehVfCgPA25g8HumUhdS9iJaK7iISmK3NLKm1VK sHTTKRJVVHLSTBpboYIGxU+/sjXDyJ/ZtMe6JxINLGFEekFZ5tDwDvU8+x0+VhFNsK6F RYpNDg22C/FCZVd/xamgKfIPPZmUXMW/2ItZxKY0V8fepZU5yjSUp0jN2WxGWZo7sD2R ralA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ceOfO/mpi2ML06tj+VCVROkrQWNnxcve2gBChMEbdYY=; b=c8QaMf1wgSkeWvkvUZuyDrCy6Yx9t7qhuqWXFjCM1tdKGYFW4X6QKt4YlXn1GQsmrp wCuJoG31kuGwlUrz3qkhHF4TlR+eRVUyBcoVCFaGdR6+c0H2VaCTNFzz5VjYs8BoCrqf J7JOkAUyYbcxyXnx8lCNh58nT9DZnd4cf+3qYyMB8ldqJyCKeUUcxZ/LS8WTZuRttxcy fVcyGisAL+kBSyl9PFEFqZFmtrr/HyA2wxEsvmeJnXkrq5JzZ38ezyhxgP+8RZjsdBzC flSnZSGVPFexnrndrc1pw1/6t+58J3SKGqIvDBJ3/fMZ2OZNSQrXlYGUKg8xM1TXO/vR keVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=puh5Mh05; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j16-20020a056a00131000b005289521cdccsi12154226pfu.60.2022.08.01.06.19.01; Mon, 01 Aug 2022 06:19:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=puh5Mh05; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233113AbiHAMDV (ORCPT + 99 others); Mon, 1 Aug 2022 08:03:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233616AbiHAMBb (ORCPT ); Mon, 1 Aug 2022 08:01:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 396EE51A10; Mon, 1 Aug 2022 04:53:38 -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 6FC8B61346; Mon, 1 Aug 2022 11:53:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83A3BC433C1; Mon, 1 Aug 2022 11:53:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1659354816; bh=XOpb2CXKFtXe5At9Dw0CarN+eLf69nnV4G0OdhwVCuk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=puh5Mh05UNrpRfdpspe1Lg4QiUK2AvWUcfNgDH47Oc+TZxkAFj9c/iUAhLrdJjSMd 0ThABWjUoVO17aQ+LcgkKtzToqJuuF0awxvtkTVHig0q37ECAgVzQNz3lzOSWQKEib UkBLsn7WAQsnMnwRfG4HhHafMjiGwqgZnJO6Z5b0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+a8430774139ec3ab7176@syzkaller.appspotmail.com, Ayushman Dutta , Kuniyuki Iwashima , David Ahern , Eric Dumazet , Jakub Kicinski Subject: [PATCH 5.15 30/69] net: ping6: Fix memleak in ipv6_renew_options(). Date: Mon, 1 Aug 2022 13:46:54 +0200 Message-Id: <20220801114135.745146111@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220801114134.468284027@linuxfoundation.org> References: <20220801114134.468284027@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kuniyuki Iwashima commit e27326009a3d247b831eda38878c777f6f4eb3d1 upstream. 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 Reviewed-by: David Ahern Reviewed-by: Eric Dumazet Link: https://lore.kernel.org/r/20220728012220.46918-1-kuniyu@amazon.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/ipv6/ping.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/net/ipv6/ping.c +++ b/net/ipv6/ping.c @@ -22,6 +22,11 @@ #include #include +static void ping_v6_destroy(struct sock *sk) +{ + inet6_destroy_sock(sk); +} + /* Compatibility glue so we can support IPv6 when it's compiled as a module */ static int dummy_ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len) @@ -166,6 +171,7 @@ struct proto pingv6_prot = { .owner = THIS_MODULE, .init = ping_init_sock, .close = ping_close, + .destroy = ping_v6_destroy, .connect = ip6_datagram_connect_v6_only, .disconnect = __udp_disconnect, .setsockopt = ipv6_setsockopt,