Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3444528iob; Mon, 16 May 2022 23:25:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyspUUci5IroRSuOt37upg2gnIKlHwNite/tlA2rkH7yVyBkBOmLaWsdWcRLdJQt0VX+DHa X-Received: by 2002:aa7:cfd8:0:b0:42a:c287:362a with SMTP id r24-20020aa7cfd8000000b0042ac287362amr3245933edy.357.1652768736770; Mon, 16 May 2022 23:25:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652768736; cv=none; d=google.com; s=arc-20160816; b=0FTiwPD1pWe2ifckSFOYtsBfftceFDwJ1ZBaK9lk7m+lhWne6QetuOeQ+cs8qDtZfX fdbdM2Uix4urbbmkK4Wo+wx/xuF+IbHqWUXe28+bCD/sQm7SBv2WJNRT5MWV8rb5K/l1 5F/JlLHDEKZSpt/AJTNB2XzV81/qdt7ZYeF/xK0nImmSd9GJJN6Y2KK0F1gq0+zlZww+ szafb8ythfmso7mkj9J40Csuh4HmcTuNFLb/TLE1p4zPsLGoCoEf8CAEEq6E3fIhN1ip 6TrKtepvH4Ldu2xd6B5vmsBStPYqibAQNUzAqS3rvGjVHNn7+nOd936Xddohj2oVmHBE pK0g== 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=HJQhfcHSDRKl02yxd6ILpVxC0dS6849BH+r0q/tF1Pg=; b=dg3tFNym+OjSgkvsnHDsnHXkJV85SSGicJcMqsCUUQf0GbrHgGt4uy/5NKNPvZebqj +8RWyuaw3ybERGkHfeuLlUVjzUJFOB3QNZuwIFEBqn37g38Jm2urQDjPPtA/nDk/UvcQ SmNrLGtHkPP/NSbkSbDckZmSGd8JYB7Ge+qg+Go6pEjtsUQJLATcjFYBz/DpXmMnpzv9 OefdxIctGuMmCgdhO6uHve8Wv9BNO+/IfJ75acSYw59a4Ny/oWnJbfmAHf228A302e50 OwOUV7XgpqVhI/XRjgbCEfsolOC3yYFpV9vK8pxKY4NWCdpNL5HVv8Q3ou1mrRYyL52G OP2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=zC2D1OuE; 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 ga11-20020a1709070c0b00b006fdd541617esi1993987ejc.960.2022.05.16.23.25.11; Mon, 16 May 2022 23:25:36 -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=zC2D1OuE; 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 S1348101AbiEPTwk (ORCPT + 99 others); Mon, 16 May 2022 15:52:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346386AbiEPTqL (ORCPT ); Mon, 16 May 2022 15:46:11 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8C1B40E75; Mon, 16 May 2022 12:43:33 -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 3422161510; Mon, 16 May 2022 19:43:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2DA0CC34100; Mon, 16 May 2022 19:43:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652730212; bh=VVL+RTQ8PBrtyz67ZksrAOqMrnI9BPzeZnMZnjHEudA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zC2D1OuEVU6vX7zHysMQ5z3XUgjATurG5l7Hsf3985/id6paGtGrL3tCaffhMmyzH 5bfX/Ldn7KAKtmKZ8AXsW+OjAWDTWxyKgxW9OV0Zz+8tNdelolWf6cWhuSjzOLa9g1 8VAu/TzhvwnSOdehosQsFLcQxUpBZ38Osy3wEuEY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaomeng Tong , Tony Nguyen , Jakub Kicinski , Gurucharan Subject: [PATCH 5.4 36/43] i40e: i40e_main: fix a missing check on list iterator Date: Mon, 16 May 2022 21:36:47 +0200 Message-Id: <20220516193615.785272690@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220516193614.714657361@linuxfoundation.org> References: <20220516193614.714657361@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.4 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: Xiaomeng Tong commit 3f95a7472d14abef284d8968734fe2ae7ff4845f upstream. The bug is here: ret = i40e_add_macvlan_filter(hw, ch->seid, vdev->dev_addr, &aq_err); The list iterator 'ch' will point to a bogus position containing HEAD if the list is empty or no element is found. This case must be checked before any use of the iterator, otherwise it will lead to a invalid memory access. To fix this bug, use a new variable 'iter' as the list iterator, while use the origin variable 'ch' as a dedicated pointer to point to the found element. Cc: stable@vger.kernel.org Fixes: 1d8d80b4e4ff6 ("i40e: Add macvlan support on i40e") Signed-off-by: Xiaomeng Tong Tested-by: Gurucharan (A Contingent worker at Intel) Signed-off-by: Tony Nguyen Link: https://lore.kernel.org/r/20220510204846.2166999-1-anthony.l.nguyen@intel.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/intel/i40e/i40e_main.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -7120,42 +7120,43 @@ static void i40e_free_macvlan_channels(s static int i40e_fwd_ring_up(struct i40e_vsi *vsi, struct net_device *vdev, struct i40e_fwd_adapter *fwd) { + struct i40e_channel *ch = NULL, *ch_tmp, *iter; int ret = 0, num_tc = 1, i, aq_err; - struct i40e_channel *ch, *ch_tmp; struct i40e_pf *pf = vsi->back; struct i40e_hw *hw = &pf->hw; - if (list_empty(&vsi->macvlan_list)) - return -EINVAL; - /* Go through the list and find an available channel */ - list_for_each_entry_safe(ch, ch_tmp, &vsi->macvlan_list, list) { - if (!i40e_is_channel_macvlan(ch)) { - ch->fwd = fwd; + list_for_each_entry_safe(iter, ch_tmp, &vsi->macvlan_list, list) { + if (!i40e_is_channel_macvlan(iter)) { + iter->fwd = fwd; /* record configuration for macvlan interface in vdev */ for (i = 0; i < num_tc; i++) netdev_bind_sb_channel_queue(vsi->netdev, vdev, i, - ch->num_queue_pairs, - ch->base_queue); - for (i = 0; i < ch->num_queue_pairs; i++) { + iter->num_queue_pairs, + iter->base_queue); + for (i = 0; i < iter->num_queue_pairs; i++) { struct i40e_ring *tx_ring, *rx_ring; u16 pf_q; - pf_q = ch->base_queue + i; + pf_q = iter->base_queue + i; /* Get to TX ring ptr */ tx_ring = vsi->tx_rings[pf_q]; - tx_ring->ch = ch; + tx_ring->ch = iter; /* Get the RX ring ptr */ rx_ring = vsi->rx_rings[pf_q]; - rx_ring->ch = ch; + rx_ring->ch = iter; } + ch = iter; break; } } + if (!ch) + return -EINVAL; + /* Guarantee all rings are updated before we update the * MAC address filter. */