]> www.infradead.org Git - users/griffoul/linux.git/commitdiff
i40e: Fix potential invalid access when MAC list is empty
authorZhen Ni <zhen.ni@easystack.cn>
Wed, 27 Aug 2025 11:56:31 +0000 (19:56 +0800)
committerTony Nguyen <anthony.l.nguyen@intel.com>
Tue, 2 Sep 2025 18:08:52 +0000 (11:08 -0700)
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 using list_first_entry_or_null instead of list_first_entry.

Fixes: e3219ce6a775 ("i40e: Add support for client interface for IWARP driver")
Signed-off-by: Zhen Ni <zhen.ni@easystack.cn>
Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
drivers/net/ethernet/intel/i40e/i40e_client.c

index 5f1a405cbbf8a11a31ce97af0c9b6c5116af8a44..518bc738ea3bec4482fed78b4787f6d0ecbeadbb 100644 (file)
@@ -359,8 +359,8 @@ 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);
+       mac = list_first_entry_or_null(&cdev->lan_info.netdev->dev_addrs.list,
+                                      struct netdev_hw_addr, list);
        if (mac)
                ether_addr_copy(cdev->lan_info.lanmac, mac->addr);
        else