Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3165001imw; Mon, 11 Jul 2022 03:19:01 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uhtmtp3YTvgLffclt42G2YE+tUtCNERWUGz6Kf1lEVO8YolO+ysl8ms1l4C0KknVfNCZWk X-Received: by 2002:a17:907:a42c:b0:722:c374:4062 with SMTP id sg44-20020a170907a42c00b00722c3744062mr18441045ejc.758.1657534741657; Mon, 11 Jul 2022 03:19:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657534741; cv=none; d=google.com; s=arc-20160816; b=xQHzN9ea0dY1EQcZiM5o2X+JiopFeO9aP6xc0B5fDGMxe+J4yZiYgSPmZ5iLnURdnb y7aW57J/qz+5AcPkaCXSGLzw6hJFq3kzjt1YN6pvZxj6mVij/6rkllhSvg0s+EG6W+Lx dLJFz3TRRZ/FLUmtUkU89H+MrZDpHLTErA6alRBqxIP03Y/s/1X0RZU3Ipy1svJdojwe yRjymjdz4325HCfcDNW7OSzfeC9kSPBZFkhnEQfOHU9Qf8hM5jAdbbmIGeFli9rxB4ic 1zLtDcV6L//j6d2nx858cezsOzaOHze8fTLEgfhU85g4pCakSZ3vUN2NrqEdP213/ppx TCow== 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=BMp87kA6OVHeLxeuGCo7r/Lv/Q98Q0R+qIXg9CiJEIA=; b=X1K8l2mO/8xISBsgr94eOIKzKKAtmLTH46p7yUZ0KTCxabDDKjKvYb5Ftiext2H2BC R9vNqlI6gY6cmYWTNWvbOdnyHbtBHjjEaJVe3oI7116kLkKv79nPS8D7hI++uQ47oPOR W20cshgKcvLqtUPFg8CC8uP20HeuTU34mhzqd3dU0OiZbl9iHs3KRc2waeryB+9IouPM pSUNJwM7Y3mGWKlcNpPExqeMWyh9pu3jz35rYDtli6f/0s8qatB1XhwQ1HjRsbUj8WC3 kBDtxmRVIxAFEY9njEPvVDeTo2hPuMdsRGsYSIB95eR2jvrftEkmf5pGJTcI1HcgCuhA GFOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Il/vJWrM"; 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 cw15-20020a170906478f00b0072aed524f3bsi10153497ejc.631.2022.07.11.03.18.37; Mon, 11 Jul 2022 03:19:01 -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="Il/vJWrM"; 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 S231771AbiGKJSz (ORCPT + 99 others); Mon, 11 Jul 2022 05:18:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231740AbiGKJSO (ORCPT ); Mon, 11 Jul 2022 05:18:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51F454C62E; Mon, 11 Jul 2022 02:11:45 -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 DEF326115B; Mon, 11 Jul 2022 09:11:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC57FC34115; Mon, 11 Jul 2022 09:11:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657530704; bh=i7dAol9ZDOUeNm+rfcVvLNLqnTH8aWKLgfXt6KaI0Z0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Il/vJWrMwFp2TYnujb1yukVlIQAoUKeD0RsM6Q5OIDDkoP6tx/6BVy+H2qshYxPfu 9Zo5j2e+tumVZxI/35FaXHN28EmaSUle2VWzkp7+/b1pngbLEa1SPWh1yuMLKvbEaG Y3z9tBWgDEd46+OGEojUqtTGp96jMCZ00so3/8yI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stefano Brivio , Pablo Neira Ayuso Subject: [PATCH 5.10 10/55] netfilter: nft_set_pipapo: release elements in clone from abort path Date: Mon, 11 Jul 2022 11:06:58 +0200 Message-Id: <20220711090542.066014417@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220711090541.764895984@linuxfoundation.org> References: <20220711090541.764895984@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,T_SCC_BODY_TEXT_LINE autolearn=ham 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: Pablo Neira Ayuso commit 9827a0e6e23bf43003cd3d5b7fb11baf59a35e1e upstream. New elements that reside in the clone are not released in case that the transaction is aborted. [16302.231754] ------------[ cut here ]------------ [16302.231756] WARNING: CPU: 0 PID: 100509 at net/netfilter/nf_tables_api.c:1864 nf_tables_chain_destroy+0x26/0x127 [nf_tables] [...] [16302.231882] CPU: 0 PID: 100509 Comm: nft Tainted: G W 5.19.0-rc3+ #155 [...] [16302.231887] RIP: 0010:nf_tables_chain_destroy+0x26/0x127 [nf_tables] [16302.231899] Code: f3 fe ff ff 41 55 41 54 55 53 48 8b 6f 10 48 89 fb 48 c7 c7 82 96 d9 a0 8b 55 50 48 8b 75 58 e8 de f5 92 e0 83 7d 50 00 74 09 <0f> 0b 5b 5d 41 5c 41 5d c3 4c 8b 65 00 48 8b 7d 08 49 39 fc 74 05 [...] [16302.231917] Call Trace: [16302.231919] [16302.231921] __nf_tables_abort.cold+0x23/0x28 [nf_tables] [16302.231934] nf_tables_abort+0x30/0x50 [nf_tables] [16302.231946] nfnetlink_rcv_batch+0x41a/0x840 [nfnetlink] [16302.231952] ? __nla_validate_parse+0x48/0x190 [16302.231959] nfnetlink_rcv+0x110/0x129 [nfnetlink] [16302.231963] netlink_unicast+0x211/0x340 [16302.231969] netlink_sendmsg+0x21e/0x460 Add nft_set_pipapo_match_destroy() helper function to release the elements in the lookup tables. Stefano Brivio says: "We additionally look for elements pointers in the cloned matching data if priv->dirty is set, because that means that cloned data might point to additional elements we did not commit to the working copy yet (such as the abort path case, but perhaps not limited to it)." Fixes: 3c4287f62044 ("nf_tables: Add set type for arbitrary concatenation of ranges") Reviewed-by: Stefano Brivio Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman --- net/netfilter/nft_set_pipapo.c | 48 ++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 15 deletions(-) --- a/net/netfilter/nft_set_pipapo.c +++ b/net/netfilter/nft_set_pipapo.c @@ -2121,6 +2121,32 @@ out_scratch: } /** + * nft_set_pipapo_match_destroy() - Destroy elements from key mapping array + * @set: nftables API set representation + * @m: matching data pointing to key mapping array + */ +static void nft_set_pipapo_match_destroy(const struct nft_set *set, + struct nft_pipapo_match *m) +{ + struct nft_pipapo_field *f; + int i, r; + + for (i = 0, f = m->f; i < m->field_count - 1; i++, f++) + ; + + for (r = 0; r < f->rules; r++) { + struct nft_pipapo_elem *e; + + if (r < f->rules - 1 && f->mt[r + 1].e == f->mt[r].e) + continue; + + e = f->mt[r].e; + + nft_set_elem_destroy(set, e, true); + } +} + +/** * nft_pipapo_destroy() - Free private data for set and all committed elements * @set: nftables API set representation */ @@ -2128,26 +2154,13 @@ static void nft_pipapo_destroy(const str { struct nft_pipapo *priv = nft_set_priv(set); struct nft_pipapo_match *m; - struct nft_pipapo_field *f; - int i, r, cpu; + int cpu; m = rcu_dereference_protected(priv->match, true); if (m) { rcu_barrier(); - for (i = 0, f = m->f; i < m->field_count - 1; i++, f++) - ; - - for (r = 0; r < f->rules; r++) { - struct nft_pipapo_elem *e; - - if (r < f->rules - 1 && f->mt[r + 1].e == f->mt[r].e) - continue; - - e = f->mt[r].e; - - nft_set_elem_destroy(set, e, true); - } + nft_set_pipapo_match_destroy(set, m); #ifdef NFT_PIPAPO_ALIGN free_percpu(m->scratch_aligned); @@ -2161,6 +2174,11 @@ static void nft_pipapo_destroy(const str } if (priv->clone) { + m = priv->clone; + + if (priv->dirty) + nft_set_pipapo_match_destroy(set, m); + #ifdef NFT_PIPAPO_ALIGN free_percpu(priv->clone->scratch_aligned); #endif