Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3179145imw; Mon, 11 Jul 2022 03:40:20 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t24LZBnwGScbdye9TxLk4KH//rwqxxOBENYTNsvQuqH9Z29s1O0PgiMQAaXa0JWDkx3RIw X-Received: by 2002:a17:907:2c77:b0:72b:1154:33da with SMTP id ib23-20020a1709072c7700b0072b115433damr18858820ejc.27.1657536019882; Mon, 11 Jul 2022 03:40:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657536019; cv=none; d=google.com; s=arc-20160816; b=N0XncRD92gdKPyD5PjjJn6Lcz8cDsYya6j+Wn157PHnvLq7rn64efnE91QuRm+YDQb VLNS+NR9y3QKQsexQbLGGOUVQ1LKAwmp6V7fFOdGunLoq55W7rnOsKWrGSbRIaVgdPqw u9W8rOobF0RU1wBa9ouUNIy4C3l6b+lI1uzttux4FCIuPpJb4zOK8rM1ytjxScjvU1jV o+GY0PNh22D1DLnJ+iONe+F7wv7klW1YRVw/+h4gQbV52gKAec07ME2dipEFPrdYmrpP xzX83iYiUOCEjsLAvd92rZ2I9/vF8CiH0L2oSQHPa1bqxIYG3HCkJZfJZuShZ55Rjomz 5c4w== 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=qfPqVajUg8a1lKzVZkhAboavGxs+1sauB2ZUZaEnih0=; b=aQioyCAM57oowOEiVUamkYwzAgt28h2L3KK8TiaoRXO1U5DA7F2u+Eoyl2hURgMxGJ LCVaokO083T4vN4iAyInuGmrGjH1eh2c79AORvSdZTbYA5MN+xkmueTXkgVKHq2QxseB +Tyk3vedLeqPFFwrKmeMIcEeUhMDmdEXyv4p99cpg5DUfjoQ1H/x2mw6z6aqDdUkRI+q pOyj8c+PQyTYrJF40pk1Ac8LpqnuapIZI4Yn9UWeVMPaI+c8ZUoistO/2fApAGLm+P6f uz0fHqIhuK/1b3YALSnrFtKNnpq+ciAjVnzRPFEKcp0eZcdZcmsHU7HYH2ziAkuAmoS0 2FIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eU83xhnj; 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 o21-20020a17090611d500b00726c9f6cba6si8026593eja.743.2022.07.11.03.39.55; Mon, 11 Jul 2022 03:40:19 -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=eU83xhnj; 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 S232853AbiGKJjo (ORCPT + 99 others); Mon, 11 Jul 2022 05:39:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233071AbiGKJid (ORCPT ); Mon, 11 Jul 2022 05:38:33 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D5C38723C; Mon, 11 Jul 2022 02:19:57 -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 ams.source.kernel.org (Postfix) with ESMTPS id F3DB7B80833; Mon, 11 Jul 2022 09:19:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43FC4C34115; Mon, 11 Jul 2022 09:19:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657531194; bh=IGjaSXXz+F58VMvnjySoD6f9kLwkf6beF4+9SB1lVBY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eU83xhnjDc5oUtxW911ap0YpRKPhqhHxJXne8LTEVceblmF22N0grmTwDv3JPPNTH pV2/9l+Njb4o8z62/WqBNb37A0BzNjwLAzasTPSyMZiVF/RF7BLefgwMAh2dUQrZHO 9E76iqh2toJHbh5Qrw7aXaFHNcbgmOYNLUvziR8Y= 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.15 018/230] netfilter: nft_set_pipapo: release elements in clone from abort path Date: Mon, 11 Jul 2022 11:04:34 +0200 Message-Id: <20220711090604.590837950@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220711090604.055883544@linuxfoundation.org> References: <20220711090604.055883544@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 @@ -2125,6 +2125,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 */ @@ -2132,26 +2158,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); @@ -2165,6 +2178,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