From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F91E36F8E9 for ; Tue, 12 May 2026 06:59:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778569200; cv=none; b=DgGXl8l937DGD1aNIQLXeny/kvJjtXit/IEoUqAUl/rpvYTRfnLktfpjOyCozOJbzgCcE0rLLDJBxvy5pIF4mKsZDMYmF9lBvj+W9Umv5YyaD0yqpY44TGIZabfIpW3ZXqrlKkCKlODDjx8Ckt5Wmt4WjR1vRVMbBWNXuaw9U9Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778569200; c=relaxed/simple; bh=jkciTllYk6CF6sRnmPRvot2mO2RNOjSUmV3yCZOiUUk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=nX+qIoFPFJMP6+QcqQgnYkHdLA2wcauS5CEdqq0RLeyh49Zkkn5ddiy7M050iwOoDFBxYtMqpWiK84C7qCnJICar3kpADg8N3LpY+QlSLsv6XT8HqYETKDGWMnhPAcD7HoeuWMFaSGebP2uQ1HKDV2A4heFftoGfwb6/GUY+FeU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=RJ5mYdYv; arc=none smtp.client-ip=185.246.85.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="RJ5mYdYv" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 620804E42C11; Tue, 12 May 2026 06:59:49 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 1EDBE60646; Tue, 12 May 2026 06:59:49 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 6F8CE11AF82F7; Tue, 12 May 2026 08:59:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1778569187; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:content-language:in-reply-to:references; bh=ifWJI6u4+GlWnZV6F3nXd/Owj+owW9w1lKV/Fx3tyFE=; b=RJ5mYdYv/VtDs7i2NcQ7mEpvXHUr56Rb50swwE/9k5Ww4Fh9F9wweyzWH3Gtbkqj0C3U6o 3yef/oLQgep8Qxdp3YmLmza+n5k/9PiP4AQZIoGN7BT7mD9zHwtAgn3nuS+SCVF7OKfS78 h195CzezzMO01Kd/LTM1D73KGRx7eBWTIgnw9NXeD34JSKtP3tpkyarCoDbCpKlaAtXAhP RV+Oy3984Ip6OrqSvTBWFD311HLb0f0QxLF7QtyRljiy2ZqCb2KAqQQNB1kyPQ5A+7l+nY SMGDPa5KGI2K6/8p0YwTKcyStTC94QCKlm9XYSlV5GvIDVvgWnjkBj5RVtFqsg== Message-ID: <75232e5f-4370-42db-8d54-1dbcc1816fd7@bootlin.com> Date: Tue, 12 May 2026 08:59:42 +0200 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net] net: ethtool: phy: avoid NULL deref when PHY driver is unbound To: David Carlier , Andrew Lunn , Heiner Kallweit , Jakub Kicinski , "David S . Miller" , Eric Dumazet , Paolo Abeni , Simon Horman Cc: Russell King , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20260509215046.107157-1-devnexen@gmail.com> Content-Language: en-US From: Maxime Chevallier In-Reply-To: <20260509215046.107157-1-devnexen@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Last-TLS-Session-Version: TLSv1.3 Hi, On 5/9/26 23:50, David Carlier wrote: > phydev->drv can become NULL while the phy_device is still attached to > its net_device, namely after the PHY driver is unbound via sysfs: > > echo > /sys/bus/mdio_bus/drivers//unbind > > phy_remove() clears phydev->drv but doesn't call phy_detach(), so the > phy_device stays in the link topology xarray and ethnl_req_get_phydev() > still hands it back. ETHTOOL_MSG_PHY_GET then oopses on: > > rep_data->drvname = kstrdup(phydev->drv->name, GFP_KERNEL); > > drvname is already treated as optional by phy_reply_size(), > phy_fill_reply() and phy_cleanup_data(), so just skip the allocation > when there is no driver bound. > > Fixes: 9dd2ad5e92b9 ("net: ethtool: phy: Convert the PHY_GET command to generic phy dump") > Cc: stable@vger.kernel.org # 6.13.x > Signed-off-by: David Carlier I was able to reproduce the bug, and your fix does solve it. Thanks ! Reviewed-by: Maxime Chevallier Tested-by: Maxime Chevallier Maxime > --- > net/ethtool/phy.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/net/ethtool/phy.c b/net/ethtool/phy.c > index f76d94d848d6..ddc6eab701ed 100644 > --- a/net/ethtool/phy.c > +++ b/net/ethtool/phy.c > @@ -94,10 +94,12 @@ static int phy_prepare_data(const struct ethnl_req_info *req_info, > if (!rep_data->name) > return -ENOMEM; > > - rep_data->drvname = kstrdup(phydev->drv->name, GFP_KERNEL); > - if (!rep_data->drvname) { > - ret = -ENOMEM; > - goto err_free_name; > + if (phydev->drv) { > + rep_data->drvname = kstrdup(phydev->drv->name, GFP_KERNEL); > + if (!rep_data->drvname) { > + ret = -ENOMEM; > + goto err_free_name; > + } > } > > rep_data->upstream_type = pdn->upstream_type;