[v2,1/1] net/ena/base: fix metrics excessive memory consumption

Message ID 20240408121525.1906-2-shaibran@amazon.com (mailing list archive)
State Not Applicable, archived
Delegated to: Ferruh Yigit
Headers
Series net/ena/base: bug fix for 23.11 stable only |

Checks

Context Check Description
ci/loongarch-compilation warning apply patch failure
ci/checkpatch warning coding style issues
ci/Intel-compilation warning apply issues
ci/iol-testing warning apply patch failure

Commit Message

Brandes, Shai April 8, 2024, 12:15 p.m. UTC
From: Shai Brandes <shaibran@amazon.com>

[ upstream commit c8a1898f82f8c04cbe1d3e2d0eec0705386c23f7 ]

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.

Bugzilla ID: 1400
Fixes: f73f53f7dc7a ("net/ena: upgrade HAL")
Cc: stable@dpdk.org

Signed-off-by: Shai Brandes <shaibran@amazon.com>
Reviewed-by: Amit Bernstein <amitbern@amazon.com>
---
 drivers/net/ena/base/ena_com.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
  

Comments

Xueming Li April 13, 2024, 8:23 a.m. UTC | #1
Hi Shai,

Thanks for the backporting, patch queued to 23.11.1 staging branch.
  

Patch

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;
 }