Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3396578rwa; Tue, 23 Aug 2022 04:12:41 -0700 (PDT) X-Google-Smtp-Source: AA6agR43dts4pxlY5EU2eCrPRqXDKIBPUOrNDlewzLKhoJjmTzoAqQDRvmnLEF8xnvB4yGPG+7gy X-Received: by 2002:a17:90b:4c04:b0:1fb:2d28:bfb5 with SMTP id na4-20020a17090b4c0400b001fb2d28bfb5mr2781059pjb.42.1661253161361; Tue, 23 Aug 2022 04:12:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253161; cv=none; d=google.com; s=arc-20160816; b=y6KSA0gT0rfL9CKcx+GFfNXT5hBESfc1WGspEw8QbOayS5FBrqskk78G/ubDzCjY/P qUZx53fkWhLnJN7DGKqBUpuaZGA9yIVlTlrY3JzT+xSC6rkNzBuaIl+RSdGC71Y72nxu oXXihVAEnekSk3X8YxA95DFoL3CCGcW7Ld1FTr5Om2XXqOoKHbXzeK9iJQIU1d7gAnl7 sNFtqG4WCi+9B05nZiU1xajWgjxewgs4xqtmVoHD/9CIjxcW0L1U2rBXQO1unBFDD5S+ 5dZjkD4fLEyoEUSFQbGGokXik9rgY7r6iyjCB1DtjUoI6cmjsM0cCdKZ1btEkfzjNyFj +ldQ== 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=Udc2qzTOmS6VGtZisnrGVbhGoQMutRbTfcbaMTgrVt0=; b=bd1T2nA7nP0WcOfXFYkYFZkB3qzxkng4ahv9MZOL3FKpolPOdWoAtzQdgljO5RIZbb IOSyUWRCKIC/roOiBezDarUIG4tGcY5uawC+MQprTtYK4S8GEyrKRDhVcWRXCTYLJi1z Y4Mrw4gjdkn/AkC1YZsfWnhCUQmxz/t0rbm23gZZ1nsNKRIIGgVF633spc3zgSYk26VA Ups9Gkh5MIVZVYJCQIhKbjNz3UG4K3lKpi76hNDgBgOYIS5nNClR4voXa0DEyE/gDpfE BDHqWy/i6UKpt0Hpy0kTW4ye4nRDOi+Xqs5pgXKN7UFyCHuFSaDTkRhcla4XlWMVFll9 WfLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZxhdBits; 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 w5-20020a056a0014c500b0052d991dd7b0si16190336pfu.38.2022.08.23.04.12.30; Tue, 23 Aug 2022 04:12:41 -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=ZxhdBits; 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 S1346854AbiHWJBF (ORCPT + 99 others); Tue, 23 Aug 2022 05:01:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347443AbiHWJA2 (ORCPT ); Tue, 23 Aug 2022 05:00:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8277F7330F; Tue, 23 Aug 2022 01:27:01 -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 50E9461488; Tue, 23 Aug 2022 08:26:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D35FDC433D6; Tue, 23 Aug 2022 08:26:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661243217; bh=TmWiTKgfzoKoGyNX5HZwo3WU9A42IVlNd++im0xVLXE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZxhdBitsTGTcMbXSL0W/O4I8Q3A5dRxqc+F9tM/48gknpUoUHBtD6YWmbAFe8GD9q SDDE92bMh/VDaizGiDgBz4q/Xeem5s4yCfie05CMlyMjDNE/LHMNsDYWPYGWkgaXLm u8IOI276zp/0N+/48+Ki1OUUI4AkljSyYYfmDb8A= 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 199/365] netfilter: nf_tables: validate NFTA_SET_ELEM_OBJREF based on NFT_SET_OBJECT flag Date: Tue, 23 Aug 2022 10:01:40 +0200 Message-Id: <20220823080126.553163524@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 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 @@ -5848,6 +5848,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] || @@ -5986,10 +5995,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);