From: Paul Menzel <pmenzel@molgen.mpg.de>
To: Zhen Ni <zhen.ni@easystack.cn>
Cc: anthony.l.nguyen@intel.com, przemyslaw.kitszel@intel.com,
andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com,
intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org
Subject: Re: [Intel-wired-lan] [PATCH] i40e: Fix potential invalid access when MAC list is empty
Date: Wed, 27 Aug 2025 17:18:34 +0200 [thread overview]
Message-ID: <6dc3bd8e-66db-4237-86bc-717f7b5c7b2a@molgen.mpg.de> (raw)
In-Reply-To: <20250827032348.1374048-1-zhen.ni@easystack.cn>
Dear Zhen,
Thank you for your patch.
Am 27.08.25 um 05:23 schrieb 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;
>
Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>
Kind regards,
Paul
prev parent reply other threads:[~2025-08-27 15:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Paul Menzel [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6dc3bd8e-66db-4237-86bc-717f7b5c7b2a@molgen.mpg.de \
--to=pmenzel@molgen.mpg.de \
--cc=andrew+netdev@lunn.ch \
--cc=anthony.l.nguyen@intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=przemyslaw.kitszel@intel.com \
--cc=zhen.ni@easystack.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).