mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net] cxgb4: allocate the full ethtool filter location array
@ 2026-11-17  9:06 Artemii Mashanov
  2026-11-17 14:10 ` Potnuri Bharat Teja
  0 siblings, 1 reply; 2+ messages in thread
From: Artemii Mashanov @ 2026-11-17  9:06 UTC (permalink / raw)
  To: netdev; +Cc: bharat, andrew+netdev, davem, edumazet, kuba, pabeni, linux-kernel

The ethtool filter location array stores nentries u32 values, but
cxgb4_init_ethtool_filters() passes nentries to kvzalloc() as a byte
count. The insertion and lookup paths allow indices below nentries,
which can address memory beyond the requested allocation.

Allocate nentries elements with kvcalloc() and the element size.
The array remains compatible with the existing kvfree() calls.

The size mismatch was found by reviewing the allocation, the array
declaration and the indexed accesses in the filter handlers.

Fixes: d915c299f1da ("cxgb4: add skeleton for ethtool n-tuple filters")
Signed-off-by: Artemii Mashanov <ralerrdirsardx@gmail.com>
---
Compile-tested cxgb4_ethtool.o with GCC 14.2 on x86-64 net/main
aa40afa831eb using W=1 and KCFLAGS=-Wno-error=format-truncation.
Both baseline and patched builds reported the same get_drvinfo()
format-truncation warning. Hardware validation is pending.

 drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c
index 0092bc16f887..c72c0bcd45c8 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c
@@ -2269,7 +2269,9 @@ int cxgb4_init_ethtool_filters(struct adapter *adap)
 	eth_filter->nentries = nentries;
 
 	for (i = 0; i < adap->params.nports; i++) {
-		eth_filter->port[i].loc_array = kvzalloc(nentries, GFP_KERNEL);
+		eth_filter->port[i].loc_array =
+			kvcalloc(nentries, sizeof(*eth_filter->port[i].loc_array),
+				 GFP_KERNEL);
 		if (!eth_filter->port[i].loc_array) {
 			ret = -ENOMEM;
 			goto free_eth_finfo;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH net] cxgb4: allocate the full ethtool filter location array
  2026-11-17  9:06 [PATCH net] cxgb4: allocate the full ethtool filter location array Artemii Mashanov
@ 2026-11-17 14:10 ` Potnuri Bharat Teja
  0 siblings, 0 replies; 2+ messages in thread
From: Potnuri Bharat Teja @ 2026-11-17 14:10 UTC (permalink / raw)
  To: Artemii Mashanov
  Cc: netdev, andrew+netdev, davem, edumazet, kuba, pabeni, linux-kernel

On Tuesday, November 11/17/26, 2026 at 14:36:08 +0530, Artemii Mashanov wrote:
> The ethtool filter location array stores nentries u32 values, but
> cxgb4_init_ethtool_filters() passes nentries to kvzalloc() as a byte
> count. The insertion and lookup paths allow indices below nentries,
> which can address memory beyond the requested allocation.
> 
> Allocate nentries elements with kvcalloc() and the element size.
> The array remains compatible with the existing kvfree() calls.
> 
> The size mismatch was found by reviewing the allocation, the array
> declaration and the indexed accesses in the filter handlers.
> 
> Fixes: d915c299f1da ("cxgb4: add skeleton for ethtool n-tuple filters")
> Signed-off-by: Artemii Mashanov <ralerrdirsardx@gmail.com>
> ---
> Compile-tested cxgb4_ethtool.o with GCC 14.2 on x86-64 net/main
> aa40afa831eb using W=1 and KCFLAGS=-Wno-error=format-truncation.
> Both baseline and patched builds reported the same get_drvinfo()
> format-truncation warning. Hardware validation is pending.
> 
>  drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c
> index 0092bc16f887..c72c0bcd45c8 100644
> --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c
> +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c
> @@ -2269,7 +2269,9 @@ int cxgb4_init_ethtool_filters(struct adapter *adap)
>  	eth_filter->nentries = nentries;
>  
>  	for (i = 0; i < adap->params.nports; i++) {
> -		eth_filter->port[i].loc_array = kvzalloc(nentries, GFP_KERNEL);
> +		eth_filter->port[i].loc_array =
> +			kvcalloc(nentries, sizeof(*eth_filter->port[i].loc_array),
> +				 GFP_KERNEL);

Thanks, Tested on T6, ethtool -N filters at high locations now insert and delete cleanly with KASAN enabled.

Reviewed-by: Potnuri Bharat Teja <bharat@chelsio.com>
Tested-by: Potnuri Bharat Teja <bharat@chelsio.com>
>  		if (!eth_filter->port[i].loc_array) {
>  			ret = -ENOMEM;
>  			goto free_eth_finfo;

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-17 14:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17  9:06 [PATCH net] cxgb4: allocate the full ethtool filter location array Artemii Mashanov
2026-11-17 14:10 ` Potnuri Bharat Teja

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®