Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3398958rwa; Tue, 23 Aug 2022 04:15:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR4oUUCdp66WTuTjuO2NbaVfN/XDPHP8c13cly4+6TpJypy1FFL06s5gmobzPuRtyheyX/qR X-Received: by 2002:a63:5f17:0:b0:427:8dbf:52b8 with SMTP id t23-20020a635f17000000b004278dbf52b8mr19687532pgb.64.1661253303037; Tue, 23 Aug 2022 04:15:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253303; cv=none; d=google.com; s=arc-20160816; b=NdeGAjlHEnefSlesc9UJzeooYtzGBkLIh4PgAzc1RGPFNI88qvdeF0Rve8cLvJv6Dm m0MR+zbuBnnRDuwT/T6INFzmdekGzOxs/V5RVVzKlqB1b5MEsG426d4fePbpIzd/ib97 W+i+X2YikuGybfFhhniFQ1aEfxWgq84q5eARimgwjZOWG/RhPlX2DSq4fS96DyFhV1sD 57yHvO4IxbPy//B64YEFnkkUw2XOvjiYhVFH+bJW+43vboFxZ4E7MqEZGzrgxVUw2ta5 lv6+X/MFC4yX5VP4xfWnakfo5FAkDGASrqT2jYfKUOxL1IdkZ+HOsP4yPgWPW7madO8a 1eKA== 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=Yqg1cTa7KycEVsallZ8SKUynTANfl/RAG7jbuoDTAno=; b=n+sxdTjMmGqL3YrHsQ6ZbuUeFjuP/8tt+xHhd8qsqCPvDCsifnADoh5z/bj3pp+lhw Ga3O8bvy3ukeCyzKRYdVFspu9kV7geAek2gqOpeQx2K0ixvqgs8pIPvXruuIQcfkk/oc /daB5iUm8nhJiXMjCknWvH0cK8sb/VEBojagzkiPj3NWc2mwGCYvbFkI3dtQhBkEq9vc ZxtWUNu6WxJywPb9iaZiyS9RVVSDQdpTq+iUXQBuZMyLLrrevpZuPg3YMPOEtmD/Lgut Hr8rCIwSphl2umZlPGldzR/ems4KEYLVVLldenKRuh1EuT37am05Wfn6rgo++QBY7dha Bb7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GwThltIN; 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 14-20020aa7914e000000b0050dcf85b9e1si61363pfi.141.2022.08.23.04.14.52; Tue, 23 Aug 2022 04:15:03 -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=GwThltIN; 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 S241063AbiHWJEX (ORCPT + 99 others); Tue, 23 Aug 2022 05:04:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242903AbiHWJDG (ORCPT ); Tue, 23 Aug 2022 05:03:06 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44ED032DBE; Tue, 23 Aug 2022 01:28: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 ams.source.kernel.org (Postfix) with ESMTPS id 1139FB81C4E; Tue, 23 Aug 2022 08:27:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AB30C433D6; Tue, 23 Aug 2022 08:27:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661243252; bh=lrFmMLhDMSrDB8SJBrwArASfOdoFYOFqUPb7iQbSHgQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GwThltINac+hXcMnplD2BNqSjTRY2QS5bKym8w9uUdxOoxf097ybPaNG08Ov1sfTp +alED1/l+h5O1O6+mitVGUT2hEXdrKFVBu34HaXVLp22woQgIMfWwFbWyMDAAZQQVv A5pT4Yf4JO/0eZ8pyV6QslUBrNw3+Rn1gpmHj9k0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pablo Neira Ayuso Subject: [PATCH 5.19 200/365] netfilter: nf_tables: NFTA_SET_ELEM_KEY_END requires concat and interval flags Date: Tue, 23 Aug 2022 10:01:41 +0200 Message-Id: <20220823080126.588213521@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080118.128342613@linuxfoundation.org> References: <20220823080118.128342613@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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 88cccd908d51397f9754f89a937cd13fa59dee37 upstream. If the NFT_SET_CONCAT|NFT_SET_INTERVAL flags are set on, then the netlink attribute NFTA_SET_ELEM_KEY_END must be specified. Otherwise, NFTA_SET_ELEM_KEY_END should not be present. For catch-all element, NFTA_SET_ELEM_KEY_END should not be present. The NFT_SET_ELEM_INTERVAL_END is never used with this set flags combination. Fixes: 7b225d0b5c6d ("netfilter: nf_tables: add NFTA_SET_ELEM_KEY_END attribute") Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman --- net/netfilter/nf_tables_api.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -5798,6 +5798,24 @@ static void nft_setelem_remove(const str set->ops->remove(net, set, elem); } +static bool nft_setelem_valid_key_end(const struct nft_set *set, + struct nlattr **nla, u32 flags) +{ + if ((set->flags & (NFT_SET_CONCAT | NFT_SET_INTERVAL)) == + (NFT_SET_CONCAT | NFT_SET_INTERVAL)) { + if (flags & NFT_SET_ELEM_INTERVAL_END) + return false; + if (!nla[NFTA_SET_ELEM_KEY_END] && + !(flags & NFT_SET_ELEM_CATCHALL)) + return false; + } else { + if (nla[NFTA_SET_ELEM_KEY_END]) + return false; + } + + return true; +} + static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set, const struct nlattr *attr, u32 nlmsg_flags) { @@ -5857,6 +5875,9 @@ static int nft_add_set_elem(struct nft_c return -EINVAL; } + if (!nft_setelem_valid_key_end(set, nla, flags)) + return -EINVAL; + if ((flags & NFT_SET_ELEM_INTERVAL_END) && (nla[NFTA_SET_ELEM_DATA] || nla[NFTA_SET_ELEM_OBJREF] || @@ -6281,6 +6302,9 @@ static int nft_del_setelem(struct nft_ct if (!nla[NFTA_SET_ELEM_KEY] && !(flags & NFT_SET_ELEM_CATCHALL)) return -EINVAL; + if (!nft_setelem_valid_key_end(set, nla, flags)) + return -EINVAL; + nft_set_ext_prepare(&tmpl); if (flags != 0) {