netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i40e: Fix potential invalid access when MAC list is empty
@ 2025-08-27  3:23 Zhen Ni
  2025-08-27  7:47 ` Przemek Kitszel
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Zhen Ni @ 2025-08-27  3:23 UTC (permalink / raw)
  To: anthony.l.nguyen, przemyslaw.kitszel, andrew+netdev, davem,
	edumazet, kuba, pabeni
  Cc: intel-wired-lan, netdev, Zhen Ni

list_first_entry() never returns NULL — if the list is empty, it still
returns a pointer to an invalid object, leading to potential invalid
memory access when dereferenced.

Fix this by checking list_empty() before calling list_first_entry(),
and only copying the MAC address when the list is not empty.

Fixes: e3219ce6a775 ("i40e: Add support for client interface for IWARP driver")
Signed-off-by: Zhen Ni <zhen.ni@easystack.cn>
---
 drivers/net/ethernet/intel/i40e/i40e_client.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/intel/i40e/i40e_client.c b/drivers/net/ethernet/intel/i40e/i40e_client.c
index 5f1a405cbbf8..0a72157aee0e 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_client.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_client.c
@@ -359,12 +359,13 @@ static void i40e_client_add_instance(struct i40e_pf *pf)
 	if (i40e_client_get_params(vsi, &cdev->lan_info.params))
 		goto free_cdev;
 
-	mac = list_first_entry(&cdev->lan_info.netdev->dev_addrs.list,
-			       struct netdev_hw_addr, list);
-	if (mac)
+	if (!list_empty(&cdev->lan_info.netdev->dev_addrs.list)) {
+		mac = list_first_entry(&cdev->lan_info.netdev->dev_addrs.list,
+				       struct netdev_hw_addr, list);
 		ether_addr_copy(cdev->lan_info.lanmac, mac->addr);
-	else
+	} else {
 		dev_err(&pf->pdev->dev, "MAC address list is empty!\n");
+	}
 
 	pf->cinst = cdev;
 
-- 
2.20.1


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

end of thread, other threads:[~2025-08-27 15:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-27  3:23 [PATCH] i40e: Fix potential invalid access when MAC list is empty Zhen Ni
2025-08-27  7:47 ` Przemek Kitszel
2025-08-27 11:56 ` [PATCH iwl-net v2] " Zhen Ni
2025-08-27 15:19   ` [Intel-wired-lan] " Paul Menzel
2025-08-27 15:18 ` [Intel-wired-lan] [PATCH] " Paul Menzel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).