Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3412161rwa; Tue, 23 Aug 2022 04:28:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR5fNhXRAzIQmg3wxFfHUxzM2RpjMXJOeCOJUHbT7h6xV7e+PiYxco8OiV00z3LNIAhyAQ6T X-Received: by 2002:a17:902:ce8e:b0:16d:cebc:e92e with SMTP id f14-20020a170902ce8e00b0016dcebce92emr24091153plg.85.1661254100873; Tue, 23 Aug 2022 04:28:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661254100; cv=none; d=google.com; s=arc-20160816; b=EfsGt6UMWD4s15pSdLKygPbWvtNPTI4kbV4Od7yFXEJyNdrFZCQRDr1anXloPrwqge UXg451ZYwGw53qfNwkAc1G5N12u55ceibDYfcSpjnM6damWxQcMbWDiz6pu6CgmhY7B2 ze/pES321EKsDDKclSnl3lUxcJjKouBrMwZSCi6/sJh34gO8Lr8kTdNk1eI+ZucquaGJ qmGgDdnk2O6m3divY+/sONWigYrIYCdiaGzMVw5clseb5PGjuczqX/5VrvuFQ7oDMg0I 6LU/c/MLypvO5jOpqU1MMWNs2663M/0FIyc1XlmoUr7cvx75TtR217gC9tFacDwcxfRQ TbmQ== 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=SKCUhH5Sadta6CarqHhzO8nGCjbP6nqG7yb+zNs6tDs=; b=PaZtZJfvcmXZiQfBLMi3C0QydDO606Gx3v8XKnukRps5vnKOxkli7C3dEb5SAhT8pt jPctJs3IeLNB636SCDUVYLBS9f2v/wEZqVaCJZUYEP3Dda8CWmuETmcPj3ygItI9qH2y MrA7NV2LwpyTA3cK9wQTC36c37Uj09fct73gFJ9p8yJx/+UNvm3KOW6TZk1wexM7tiCs v3mj/QS8bHlBH7ZLAqsjVExyI8UkreE4EoAgh9sZwlkSod2M0IbTZCtrGvIFoHoyGGCn nvk4ARD5BUkPqSzTVf8agfT0f5ostQETmZ5YRChF2tBukcYEkkRZjIwgqWFzgahIgqtT wZgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bsVU11ux; 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 c5-20020a170903234500b0016ec623eac3si16149327plh.239.2022.08.23.04.28.09; Tue, 23 Aug 2022 04:28:20 -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=bsVU11ux; 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 S1353068AbiHWKKc (ORCPT + 99 others); Tue, 23 Aug 2022 06:10:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352760AbiHWKC2 (ORCPT ); Tue, 23 Aug 2022 06:02:28 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F8BA7CAA2; Tue, 23 Aug 2022 01:50:51 -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 sin.source.kernel.org (Postfix) with ESMTPS id 5DE45CE1B2A; Tue, 23 Aug 2022 08:50:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F07BC433C1; Tue, 23 Aug 2022 08:50:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244647; bh=bNe4rO2J68SBkBMaIXYCYTj2UDiAQNXOSRC37aerPW0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bsVU11uxNeinsdm2ZAB2LTk75OA5XITYmpxSwup3VB6l0809Hvd7x0D3zNMXryDJj xOKk5dkRDAQ7osKnqzx/Rx/Obqhp6ZJmyRySHrVdRYz9BuE7IKH5ZkgOUI/urTn8AV l1FQFyjwmDnaNZfPRgo5CC+WWeoTaOdys5NwYlM8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pablo Neira Ayuso Subject: [PATCH 5.15 128/244] netfilter: nf_tables: validate NFTA_SET_ELEM_OBJREF based on NFT_SET_OBJECT flag Date: Tue, 23 Aug 2022 10:24:47 +0200 Message-Id: <20220823080103.360962250@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080059.091088642@linuxfoundation.org> References: <20220823080059.091088642@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 5a2f3dc31811e93be15522d9eb13ed61460b76c8 upstream. If the NFTA_SET_ELEM_OBJREF netlink attribute is present and NFT_SET_OBJECT flag is set on, report EINVAL. Move existing sanity check earlier to validate that NFT_SET_OBJECT requires NFTA_SET_ELEM_OBJREF. Fixes: 8aeff920dcc9 ("netfilter: nf_tables: add stateful object reference to set elements") Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman --- net/netfilter/nf_tables_api.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -5761,6 +5761,15 @@ static int nft_add_set_elem(struct nft_c return -EINVAL; } + if (set->flags & NFT_SET_OBJECT) { + if (!nla[NFTA_SET_ELEM_OBJREF] && + !(flags & NFT_SET_ELEM_INTERVAL_END)) + return -EINVAL; + } else { + if (nla[NFTA_SET_ELEM_OBJREF]) + return -EINVAL; + } + if ((flags & NFT_SET_ELEM_INTERVAL_END) && (nla[NFTA_SET_ELEM_DATA] || nla[NFTA_SET_ELEM_OBJREF] || @@ -5899,10 +5908,6 @@ static int nft_add_set_elem(struct nft_c } if (nla[NFTA_SET_ELEM_OBJREF] != NULL) { - if (!(set->flags & NFT_SET_OBJECT)) { - err = -EINVAL; - goto err_parse_key_end; - } obj = nft_obj_lookup(ctx->net, ctx->table, nla[NFTA_SET_ELEM_OBJREF], set->objtype, genmask);