Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3018413pxu; Mon, 14 Dec 2020 18:07:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJyhwoeTORlwgnYSD41eagtMSXJ/FZrk8s4fgyG7AfAqEEQ0mKoi2KRu6T2NbvD8/P5I7tzt X-Received: by 2002:a50:ac86:: with SMTP id x6mr27330567edc.197.1607998022405; Mon, 14 Dec 2020 18:07:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607998022; cv=none; d=google.com; s=arc-20160816; b=uukwD+GHYovmVrxTDFFlVSB4bHOHMg/l7yJm179NSjhSJh0iEkN8Zm+I7iooDeQOgS emqVbU73IN6So6jEo+cQooaXacElH2Sm6k3JXCd1PD4hk9VHEy7SUZquUmJOrWAcjhkP jwQ7Qoxz593TA0iQxFHll1ke+9kPuHnezcAxxVFDZPC/CdXki5XaL5qIeI6GhSx7zyb7 BPXULdnZbzBympcTKEg2cn3SWwc5RW45ZmqMSln1j1uFHw7WmTH3WBZMkAMRWl3CwlmH j0e8nkvH/po5aJRhRKg2UdOAPMi62gkCtBbUqAyiXP2He1NoJoK5YROmUHG0cYtJ0Dwi oJNQ== 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 :message-id:date:subject:cc:to:from; bh=EUPSQWSwD7+47vn2wAOXsoX3ycvYLZy+YlgwJefrtPo=; b=F/OcTEJve7C1U7q4Lw2r3bFmF9RHUPJ+6Eo6w+xhI3ZI/IqyDbkimX/6netoy9R2tA iw5DPlOjFnv+UlflrPsLCfCPPeJr5j1ihWh+NUzzhwlxX/vZe+jwgGFE8LtHhBFQOOzY gLJmTIEdM+jZwDFPORS+9U1pXwUalDVmPwv0eUY0kITrRFlHntukWbFBfCyzrtiQGHUR w0zr3mQ9ujuy89930uS5EXz7AIAxz3WSVUDDlm2TcYhtL/6xKVUsOPrZ8q9rrpKRx5JI Hlq9wi+jEHiCX5fzq8+NKDtoUHuRQKj4Iuf8BHZKY6Mo45OaufBVH13mlxFYjXA9Ma1X GTsg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w2si106352edx.591.2020.12.14.18.06.38; Mon, 14 Dec 2020 18:07:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727217AbgLNXl1 (ORCPT + 99 others); Mon, 14 Dec 2020 18:41:27 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:40756 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726559AbgLNXlB (ORCPT ); Mon, 14 Dec 2020 18:41:01 -0500 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1koxRv-00033F-An; Mon, 14 Dec 2020 23:40:15 +0000 From: Colin King To: Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , "David S . Miller" , Jakub Kicinski , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] netfilter: nftables: fix incorrect increment of loop counter Date: Mon, 14 Dec 2020 23:40:15 +0000 Message-Id: <20201214234015.85072-1-colin.king@canonical.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King The intention of the err_expr cleanup path is to iterate over the allocated expr_array objects and free them, starting from i - 1 and working down to the start of the array. Currently the loop counter is being incremented instead of decremented and also the index i is being used instead of k, repeatedly destroying the same expr_array element. Fix this by decrementing k and using k as the index into expr_array. Addresses-Coverity: ("Infinite loop") Fixes: 8cfd9b0f8515 ("netfilter: nftables: generalize set expressions support") Signed-off-by: Colin Ian King --- net/netfilter/nf_tables_api.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index 8d5aa0ac45f4..4186b1e52d58 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -5254,8 +5254,8 @@ static int nft_set_elem_expr_clone(const struct nft_ctx *ctx, return 0; err_expr: - for (k = i - 1; k >= 0; k++) - nft_expr_destroy(ctx, expr_array[i]); + for (k = i - 1; k >= 0; k--) + nft_expr_destroy(ctx, expr_array[k]); return -ENOMEM; } -- 2.29.2