Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp310255ybi; Wed, 29 May 2019 22:00:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqxEwKF9Xy4nec+r2pB5RfG4/411/tGVAYarj2iMtBzxP/DdcJJ6bozlSwndjAb4xj795OB/ X-Received: by 2002:a17:902:9f83:: with SMTP id g3mr1986033plq.330.1559192455501; Wed, 29 May 2019 22:00:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559192455; cv=none; d=google.com; s=arc-20160816; b=W8xhwNTtupViSnCI1t0NigqRRZlDpqzv3xSRB24vLtYwShaXlR6kZeDU91GEn9RZJq UBn3n8EmDH0amuPOem0LPfuYYdZLuFw1Ba0H9tFPJtF0k+En1DSDNfNafI1THzJvoKkS FNVZ45mptIQ/hTs/sfs33VTFfQe31Fwpl+s6G2QDULoyPLahUExsfiEjbsNiYA8pvMr7 CBlv0KQuK+22EPHIT1VFg4U/57B9uSLCBTR9lbavBkfD6E/6OZ2wRICymhx2bG2WaSrQ 6k0e1jJDqhtJO5p/+r8b8quc2p6J0zDqrna3Idb+jCvo4Yl87ONsVC36/Gn1B2BwMS5c NFRA== 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=sNxJPOgUpAn19bKW1JiRp14gkp4m1Rh4nrwQbZ+l9QQ=; b=TOw+EehgyepcR5JNtDB519Y2PJOm32Ut01fuKyE8eq8wT4+IuwgnpZ3W4QbwTFz6N8 qrdrsuSYZNHEQoNHPU8o4WZx0gthyDm6Bnz/M4KErh9dZA/yaHTkGWBZFh9NelVFB93r FnlRlCbN8KB24V+FOqDH9Y4/uLQDktwVitZ8al+b8aSK909yjxT8vMCIsgy0d+zHydjC LB07/9XwN4rCgrlC0OuJGOef/XETlDDOSX/ID0ZxyLXcZZJrSPNpIDD5AqqwIOn+SD1Y IE6e1RZ+FwU9NhFQXbdC9IOv75Hz1NIIBhczpOkU9hrQBgoIHuwjav9ntodZBIcVz05l 0FXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="ZKw86/bs"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t1si2017303pgh.406.2019.05.29.22.00.38; Wed, 29 May 2019 22:00:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="ZKw86/bs"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389289AbfE3E5y (ORCPT + 99 others); Thu, 30 May 2019 00:57:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:45638 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727836AbfE3DJx (ORCPT ); Wed, 29 May 2019 23:09:53 -0400 Received: from localhost (ip67-88-213-2.z213-88-67.customer.algx.net [67.88.213.2]) (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 6D50A2449C; Thu, 30 May 2019 03:09:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559185792; bh=oddKV1yeYzoI5BnCJbnLiq9Kkmk8WXXws4bnaRGvVLM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZKw86/bshhVvJ2xJKzc2EUO7YtzMDJhyxUVlRaDGUxsheBQIi3DHwyhP51jBB4BKm BEfXzrxkhrnp4+z9DCHvSMkGp6vJaIsqnNJRnaFwY7OneYJzyb0ZSfL4v5z5Nyzh1f 0i9y2KF2IWcgVoiGBw5QvP3svwWQQxCRBHOnoHWc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arthur Kiyanovski , Sameeh Jubran , "David S. Miller" , Sasha Levin Subject: [PATCH 5.1 065/405] net: ena: fix: set freed objects to NULL to avoid failing future allocations Date: Wed, 29 May 2019 20:01:03 -0700 Message-Id: <20190530030544.235021351@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030540.291644921@linuxfoundation.org> References: <20190530030540.291644921@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 [ Upstream commit 8ee8ee7fe87bf64738ab4e31be036a7165608b27 ] In some cases when a queue related allocation fails, successful past allocations are freed but the pointer that pointed to them is not set to NULL. This is a problem for 2 reasons: 1. This is generally a bad practice since this pointer might be accidentally accessed in the future. 2. Future allocations using the same pointer check if the pointer is NULL and fail if it is not. Fixed this by setting such pointers to NULL in the allocation of queue related objects. Also refactored the code of ena_setup_tx_resources() to goto-style error handling to avoid code duplication of resource freeing. Fixes: 1738cd3ed342 ("net: ena: Add a driver for Amazon Elastic Network Adapters (ENA)") Signed-off-by: Arthur Kiyanovski Signed-off-by: Sameeh Jubran Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/amazon/ena/ena_netdev.c | 25 ++++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c index 41c1c9acb3246..9b03d7e404f83 100644 --- a/drivers/net/ethernet/amazon/ena/ena_netdev.c +++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c @@ -224,28 +224,23 @@ static int ena_setup_tx_resources(struct ena_adapter *adapter, int qid) if (!tx_ring->tx_buffer_info) { tx_ring->tx_buffer_info = vzalloc(size); if (!tx_ring->tx_buffer_info) - return -ENOMEM; + goto err_tx_buffer_info; } size = sizeof(u16) * tx_ring->ring_size; tx_ring->free_tx_ids = vzalloc_node(size, node); if (!tx_ring->free_tx_ids) { tx_ring->free_tx_ids = vzalloc(size); - if (!tx_ring->free_tx_ids) { - vfree(tx_ring->tx_buffer_info); - return -ENOMEM; - } + if (!tx_ring->free_tx_ids) + goto err_free_tx_ids; } size = tx_ring->tx_max_header_size; tx_ring->push_buf_intermediate_buf = vzalloc_node(size, node); if (!tx_ring->push_buf_intermediate_buf) { tx_ring->push_buf_intermediate_buf = vzalloc(size); - if (!tx_ring->push_buf_intermediate_buf) { - vfree(tx_ring->tx_buffer_info); - vfree(tx_ring->free_tx_ids); - return -ENOMEM; - } + if (!tx_ring->push_buf_intermediate_buf) + goto err_push_buf_intermediate_buf; } /* Req id ring for TX out of order completions */ @@ -259,6 +254,15 @@ static int ena_setup_tx_resources(struct ena_adapter *adapter, int qid) tx_ring->next_to_clean = 0; tx_ring->cpu = ena_irq->cpu; return 0; + +err_push_buf_intermediate_buf: + vfree(tx_ring->free_tx_ids); + tx_ring->free_tx_ids = NULL; +err_free_tx_ids: + vfree(tx_ring->tx_buffer_info); + tx_ring->tx_buffer_info = NULL; +err_tx_buffer_info: + return -ENOMEM; } /* ena_free_tx_resources - Free I/O Tx Resources per Queue @@ -378,6 +382,7 @@ static int ena_setup_rx_resources(struct ena_adapter *adapter, rx_ring->free_rx_ids = vzalloc(size); if (!rx_ring->free_rx_ids) { vfree(rx_ring->rx_buffer_info); + rx_ring->rx_buffer_info = NULL; return -ENOMEM; } } -- 2.20.1