From: Maxime Chevallier <maxime.chevallier@bootlin.com>
To: Quan Sun <2022090917019@std.uestc.edu.cn>,
netdev@vger.kernel.org, andrew@lunn.ch
Cc: kuba@kernel.org, edumazet@google.com, pabeni@redhat.com
Subject: Re: [PATCH net] net: ethtool: fix NULL pointer dereference in phy_reply_size
Date: Wed, 6 May 2026 14:23:37 +0200 [thread overview]
Message-ID: <08d60afc-56ee-49d1-b124-4d8f6191afcd@bootlin.com> (raw)
In-Reply-To: <20260506120131.767679-1-2022090917019@std.uestc.edu.cn>
Hi,
On 06/05/2026 14:01, Quan Sun wrote:
> In phy_prepare_data(), the strings rep_data->name and rep_data->drvname
> are allocated using kstrdup(). However, the return values of these
> allocations are not checked.
>
> If kstrdup() fails to allocate memory, it returns NULL. The function
> phy_prepare_data() will still return 0 (success). Subsequently, the
> handler ethnl_default_doit() continues the execution flow and calls
> phy_reply_size() to calculate the size of the reply message. This
> unconditionally executes strlen(rep_data->name), leading to a kernel
> NULL pointer dereference and panic.
>
> Fix this by properly checking the return values of kstrdup() for both
> `name` and `drvname`, and returning -ENOMEM if the allocation fails.
>
> Signed-off-by: Quan Sun <2022090917019@std.uestc.edu.cn>
Thanks for the fix :)
You're missing the Fixes: tag however.
Can you please add it ?
> ---
> net/ethtool/phy.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/net/ethtool/phy.c b/net/ethtool/phy.c
> index d4e6887055ab1..6cf3df1df8659 100644
> --- a/net/ethtool/phy.c
> +++ b/net/ethtool/phy.c
> @@ -88,8 +88,17 @@ static int phy_prepare_data(const struct ethnl_req_info *req_info,
> return -EOPNOTSUPP;
>
> rep_data->phyindex = phydev->phyindex;
> +
> rep_data->name = kstrdup(dev_name(&phydev->mdio.dev), GFP_KERNEL);
> + if (!rep_data->name)
> + return -ENOMEM;
> +
> rep_data->drvname = kstrdup(phydev->drv->name, GFP_KERNEL);
> + if (!rep_data->drvname) {
> + kfree(rep_data->name);
> + return -ENOMEM;
> + }
> +
> rep_data->upstream_type = pdn->upstream_type;
>
> if (pdn->upstream_type == PHY_UPSTREAM_PHY) {
There's a similar problem a few lines below with :
rep_data->upstream_sfp_name
and
rep_data->downstream_sfp_name
The only problematic case really is rep_data->name, as all the other
strings are checked for being NULL upon accessing them.
So either we only fix the rep_data->name allocation checks, or all the
string allocations :)
Can you address this in V2 ?
Thanks,
Maxime
next prev parent reply other threads:[~2026-05-06 12:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-06 12:01 [PATCH net] net: ethtool: fix NULL pointer dereference in phy_reply_size Quan Sun
2026-05-06 12:23 ` Maxime Chevallier [this message]
2026-05-06 13:33 ` Quan Sun
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=08d60afc-56ee-49d1-b124-4d8f6191afcd@bootlin.com \
--to=maxime.chevallier@bootlin.com \
--cc=2022090917019@std.uestc.edu.cn \
--cc=andrew@lunn.ch \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/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