Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4413967pxa; Mon, 10 Aug 2020 08:31:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7e1zbBEm1UY2QE0RiFI11HrBqA46YLWqz1q9Mca6fq2DPcfJKK+TRBFkiwF3++nHEWIy6 X-Received: by 2002:a05:6402:743:: with SMTP id p3mr21360092edy.19.1597073517300; Mon, 10 Aug 2020 08:31:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597073517; cv=none; d=google.com; s=arc-20160816; b=TtGRU1/+xVJbmx7LZYXcJuc7iaHQwXYynYCiLIqo8z2uf2fhs0d5XOnmb3JsG26a1W U3zP/kyj4je13Mn+wsaBFepCgjs/FAzUHuRrvSmfdyBWfkZ2YDymRx7yX8I4er4RGHbs jHPyApv3ps+6SwAC6dOBdGrsptrLWNLPFvegsHyAcgLTarhoWiEJW2NeDyZn7lrA8mFq bhZ3t27Imnvd8HzB/tyEAPNMSxXd4VroZMnan4aVXu9SZA21DPXsflIQFg1XLcXHUSpn MjehO2g7wbhsOQdHwHe0clIC6nfTfPXSe7qZXcJkq2O6izSZ1v3eRy6YqMno2mx+WoQX 1BQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YdYszqyFF4yMI5Rs7VyYo3Wy3D+h+tc2mm0/eOE+Csk=; b=wAob8i/RqsYkl97nPZIThTDKz696+L+VWBX6tDxR8SWCPFXGaTNXBzKvSlQ6NWU1LQ /z/4RdJHVyXF/9G19FrzlVKmhF+PVe7XmXWn5RKzBW92/nLSs0wMyUJW711A6PHDXiTa 7IKGIpk8wfXig13ooaa+O7kjtU/LJzxmsRnkfo0ekpHtOcf4B+pjHVFbQfFn0Ohk/x/B ZXoD8PuagVAahiyod74ABD15K3iJAa3bdt5E8XG6jRxpPAZORBo6Yqta4osRUoHCSGiU QMNJTWpByrCAtnewN8eVt4TT1CHzSR8aH7hWezvlIGmB6NXIHbUxVaAbbpR3Ak0MGiFi RVZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xt6QNMGG; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m13si10486724edv.45.2020.08.10.08.31.33; Mon, 10 Aug 2020 08:31:57 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=xt6QNMGG; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729160AbgHJPbD (ORCPT + 99 others); Mon, 10 Aug 2020 11:31:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:38188 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728622AbgHJPbA (ORCPT ); Mon, 10 Aug 2020 11:31:00 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B95B420791; Mon, 10 Aug 2020 15:30:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597073460; bh=Vw0NTeXf6g8TD8GJfu8UedAon+JFuYZRwnlsjHwj4qA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xt6QNMGGNqvZ+l7z9au0RSoIFJquwpx5ZNZzhyAoB4GoWUbvUxeX6JhvnttSUcL4G gyczGqPBY+2+pY3fDI13cRFAhcUQ063Hj+y1KDu8yc8bhXDCdgxdOT9CQv9JIQpwPj XW/1jLaW94IE85VxZSQZ+EeKdDdVymrcihl9GG1w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Martyna Szapar , Jeff Kirsher , Jesse Brandeburg Subject: [PATCH 4.19 46/48] i40e: Fix of memory leak and integer truncation in i40e_virtchnl.c Date: Mon, 10 Aug 2020 17:22:08 +0200 Message-Id: <20200810151806.488530971@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200810151804.199494191@linuxfoundation.org> References: <20200810151804.199494191@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Martyna Szapar [ Upstream commit 24474f2709af6729b9b1da1c5e160ab62e25e3a4 ] Fixed possible memory leak in i40e_vc_add_cloud_filter function: cfilter is being allocated and in some error conditions the function returns without freeing the memory. Fix of integer truncation from u16 (type of queue_id value) to u8 when calling i40e_vc_isvalid_queue_id function. Fixes: e284fc280473b ("i40e: Add and delete cloud filter") Signed-off-by: Martyna Szapar Signed-off-by: Jeff Kirsher Signed-off-by: Jesse Brandeburg Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) --- a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c +++ b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c @@ -181,7 +181,7 @@ static inline bool i40e_vc_isvalid_vsi_i * check for the valid queue id **/ static inline bool i40e_vc_isvalid_queue_id(struct i40e_vf *vf, u16 vsi_id, - u8 qid) + u16 qid) { struct i40e_pf *pf = vf->pf; struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id); @@ -3345,7 +3345,7 @@ static int i40e_vc_add_cloud_filter(stru if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) { aq_ret = I40E_ERR_PARAM; - goto err; + goto err_out; } if (!vf->adq_enabled) { @@ -3353,15 +3353,15 @@ static int i40e_vc_add_cloud_filter(stru "VF %d: ADq is not enabled, can't apply cloud filter\n", vf->vf_id); aq_ret = I40E_ERR_PARAM; - goto err; + goto err_out; } if (i40e_validate_cloud_filter(vf, vcf)) { dev_info(&pf->pdev->dev, "VF %d: Invalid input/s, can't apply cloud filter\n", vf->vf_id); - aq_ret = I40E_ERR_PARAM; - goto err; + aq_ret = I40E_ERR_PARAM; + goto err_out; } cfilter = kzalloc(sizeof(*cfilter), GFP_KERNEL); @@ -3422,13 +3422,17 @@ static int i40e_vc_add_cloud_filter(stru "VF %d: Failed to add cloud filter, err %s aq_err %s\n", vf->vf_id, i40e_stat_str(&pf->hw, ret), i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status)); - goto err; + goto err_free; } INIT_HLIST_NODE(&cfilter->cloud_node); hlist_add_head(&cfilter->cloud_node, &vf->cloud_filter_list); + /* release the pointer passing it to the collection */ + cfilter = NULL; vf->num_cloud_filters++; -err: +err_free: + kfree(cfilter); +err_out: return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_ADD_CLOUD_FILTER, aq_ret); }