Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3360422iob; Mon, 16 May 2022 20:38:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWv1jf5kB9Hk6wgL9426nX8MF0atEQvx1DyU1HCIbT8AkioZTzgDq31LlJ5DPDVFAysgE6 X-Received: by 2002:a17:90b:3e84:b0:1dc:5942:af0e with SMTP id rj4-20020a17090b3e8400b001dc5942af0emr22696008pjb.61.1652758714354; Mon, 16 May 2022 20:38:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652758714; cv=none; d=google.com; s=arc-20160816; b=xRbL5mVo53MWYNL/yev7GmdimCinKQVbmbqrpIN/eD6Hqd8yCJhcaEq4ENYPLAvF/9 czMEoMLr/LRggIKGE5Yltcn9mTH1puLOz3dzjMm0AgbYOZBp/ay5xTQKHXNXsqNjZx3a /svb1N/tfE70HyN7hoIQYajbrLEsKDGtCGIeZVwJr6qnzMNOgMnhfgwTBqW/eOiU/u56 edWqutQgzbEGcULGn9K0sdJgFkJjTittVf2ccmtct7Aqr703NQ3EEIM/ab95Mp8t1hY9 j6aWl2b51XRn3zlu2ILj3WmG7dMZIAe6YYnnF+BdM0DTp/h8Md0rt2Z42WAluHfDem1k vG0g== 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=A0FETKGde1TegfdQ5rpRsR8k8gLuxNW1ol36i3YNP0M=; b=ZJN55BajG0eQoI/PyipwBm3e7OE3JWD5Ml2o4CE8gEIUoUcssbY8XYgv8aaU76Veyu jdMR0mjuh1y7ON4fUrv1VbomyEWwCWs3SNgwe6Tv9NSgHRdntRncuxRw7jVW4pLs0RsS /qZZNoVVzvyF93NqHp4KuAaytkZ2LXxbBP7BOns3bo1HbTq0KnbFg3rqKvJXlIr8N+HF Us48HYXYvykPe/fjo8cFGrDSC8oPlvX2n109A4QT8LrKqwDrC/3Q9n9KqGrQc1HEcrot s0cHTgj+ociAJ2qLTdV7FER9VWOACrLOgc3P9iv+89IyabVZVDUKsDxG+58nHAZzQxyI ka1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HyzPFGpo; 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 fy21-20020a17090b021500b001ca84546104si1325586pjb.27.2022.05.16.20.38.22; Mon, 16 May 2022 20:38:34 -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=HyzPFGpo; 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 S1347613AbiEPUes (ORCPT + 99 others); Mon, 16 May 2022 16:34:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351072AbiEPUB6 (ORCPT ); Mon, 16 May 2022 16:01:58 -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 8E39B4090F; Mon, 16 May 2022 12:58:06 -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 2A53060EC4; Mon, 16 May 2022 19:58:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E54BC385AA; Mon, 16 May 2022 19:58:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652731085; bh=n/zyVESSluDMEBpLn3+mn6KO/3lgO+C5pJ5rg7/Nzto=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HyzPFGpoF6yjJ5fqI6lkOqcAl3O8i0AsuD703JG+RZHwSJKPpAdfSsGqufaC+r5EW QvN5d9lR51J/QpyLrSsSeagNdiDmQ8Jcp+dx/iy5xqgaMkDt5Hl2HrLbNu63XjQFWD naqtFpnCt4xuGn5j269KcaoUnsGV2Tn2/7djTklU= 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.17 098/114] i40e: i40e_main: fix a missing check on list iterator Date: Mon, 16 May 2022 21:37:12 +0200 Message-Id: <20220516193628.289171540@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220516193625.489108457@linuxfoundation.org> References: <20220516193625.489108457@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 @@ -7535,42 +7535,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. */