From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5EF8343D6C for ; Thu, 28 Mar 2024 15:03:22 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 25F85410F9; Thu, 28 Mar 2024 15:03:22 +0100 (CET) Received: from smtp-fw-80006.amazon.com (smtp-fw-80006.amazon.com [99.78.197.217]) by mails.dpdk.org (Postfix) with ESMTP id 7A3A8402E7; Thu, 28 Mar 2024 15:03:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1711634600; x=1743170600; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=TqOoK6QU1bxisDjBDGeil1IMLJ/sB/lgxdb52CefEVc=; b=ZgvuHk3Go0+IQw3Qb1aKA9Ze1+4ngGmVWOIsdaM0VBVmjwP6oToIz+Xt GcZxjjSJCmTT0YGultFVWdDPdcOmJobOTLShcYNkN+1K7BYC2llsDyH7v UiazoXOHHHAUg0AoItCC8ieMKy7nCKKsLMuA/7obOePhd3ln6oUF2vypq c=; X-IronPort-AV: E=Sophos;i="6.07,162,1708387200"; d="scan'208";a="283588071" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev) ([10.25.36.214]) by smtp-border-fw-80006.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Mar 2024 14:03:17 +0000 Received: from EX19MTAEUB001.ant.amazon.com [10.0.10.100:17200] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.40.187:2525] with esmtp (Farcaster) id 038d200c-84e3-4b17-8d3e-ab41aed3e9a0; Thu, 28 Mar 2024 14:03:15 +0000 (UTC) X-Farcaster-Flow-ID: 038d200c-84e3-4b17-8d3e-ab41aed3e9a0 Received: from EX19D007EUA002.ant.amazon.com (10.252.50.68) by EX19MTAEUB001.ant.amazon.com (10.252.51.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Thu, 28 Mar 2024 14:03:15 +0000 Received: from EX19MTAUWC001.ant.amazon.com (10.250.64.145) by EX19D007EUA002.ant.amazon.com (10.252.50.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Thu, 28 Mar 2024 14:03:14 +0000 Received: from HFA15-CG15235BS.amazon.com (10.85.143.172) by mail-relay.amazon.com (10.250.64.145) with Microsoft SMTP Server id 15.2.1258.28 via Frontend Transport; Thu, 28 Mar 2024 14:03:12 +0000 From: To: , , , , CC: , , Shai Brandes Subject: [PATCH v2 1/1] net/ena/base: fix metrics excessive memory consumption Date: Thu, 28 Mar 2024 16:03:07 +0200 Message-ID: <20240328140307.1291-2-shaibran@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240328140307.1291-1-shaibran@amazon.com> References: <20240328140307.1291-1-shaibran@amazon.com> MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org From: Shai Brandes The driver accidentally allocates a huge memory buffer for the customer metrics because it uses an uninitialized variable for the buffer length. This can lead to excessive memory footprint for the driver which can even fail to initialize in case of insufficient memory. Signed-off-by: Shai Brandes Reviewed-by: Amit Bernstein Fixes: f73f53f7dc7a ("net/ena: upgrade HAL") Bugzilla ID: 1400 --- drivers/net/ena/base/ena_com.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/net/ena/base/ena_com.c b/drivers/net/ena/base/ena_com.c index 6953a1fa33..8ae7dcf48e 100644 --- a/drivers/net/ena/base/ena_com.c +++ b/drivers/net/ena/base/ena_com.c @@ -3134,16 +3134,18 @@ int ena_com_allocate_debug_area(struct ena_com_dev *ena_dev, int ena_com_allocate_customer_metrics_buffer(struct ena_com_dev *ena_dev) { struct ena_customer_metrics *customer_metrics = &ena_dev->customer_metrics; + customer_metrics->buffer_len = ENA_CUSTOMER_METRICS_BUFFER_SIZE; + customer_metrics->buffer_virt_addr = NULL; ENA_MEM_ALLOC_COHERENT(ena_dev->dmadev, customer_metrics->buffer_len, customer_metrics->buffer_virt_addr, customer_metrics->buffer_dma_addr, customer_metrics->buffer_dma_handle); - if (unlikely(customer_metrics->buffer_virt_addr == NULL)) + if (unlikely(customer_metrics->buffer_virt_addr == NULL)) { + customer_metrics->buffer_len = 0; return ENA_COM_NO_MEM; - - customer_metrics->buffer_len = ENA_CUSTOMER_METRICS_BUFFER_SIZE; + } return 0; } -- 2.17.1