mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] EDAC/versalnet: Fix device-name use-after-free on removal
@ 2026-11-18 13:30 Suyuan Wang via B4 Relay
  2026-11-30 13:55 ` Pandey, Radhey Shyam
  0 siblings, 1 reply; 2+ messages in thread
From: Suyuan Wang via B4 Relay @ 2026-11-18 13:30 UTC (permalink / raw)
  To: tony.luck, bp, shubhrajyoti.datta
  Cc: linux-edac, linux-kernel, radhey.shyam.pandey

From: Suyuan Wang <stevewong@hust.edu.cn>

mc_init() stores a pointer to the backing device's name in mci->dev_name
without copying the string:

	mci->dev_name = dev_name(dev);

remove_one_mc() then unregisters that device before calling
edac_mc_del_mc():

	device_unregister(mci->pdev);
	edac_mc_del_mc(mci->pdev);

device_unregister() can drop the last reference, and kobject_cleanup()
frees the device's name along with the device. edac_mc_del_mc() then
logs the controller removal through edac_dev_name(mci), i.e.
mci->dev_name, reading the freed name string.

Call edac_mc_del_mc() before device_unregister(), so the device and its
name stay alive until EDAC has logged and removed the controller.

Found with a static analysis tool and checked by hand.

Fixes: d5fe2fec6c40 ("EDAC: Add a driver for the AMD Versal NET DDR controller")
Link: https://lore.kernel.org/linux-edac/20260724171945.2812749-9-shubhrajyoti.datta@amd.com/
Cc: stable@vger.kernel.org
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
We found this independently and later found the earlier patch linked
above, which fixes the same bug as part of a larger series; this is a
standalone two-line version. The bad ordering predates the refactor in
62a9fc50e8d9 -- it was already in the original driver, in both the normal
remove path and the init-failure rollback path.

The change only reorders two cleanup calls. Checked by inspection; I
couldn't build it here (it needs an arm64 Zynq config and my arm64 cross
toolchain fails at an unrelated vdso step), and I don't have the hardware.
---
 drivers/edac/versalnet_edac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/edac/versalnet_edac.c b/drivers/edac/versalnet_edac.c
index d59ba3904cda..075b0105c427 100644
--- a/drivers/edac/versalnet_edac.c
+++ b/drivers/edac/versalnet_edac.c
@@ -767,8 +767,8 @@ static void remove_one_mc(struct mc_priv *priv, int i)
 	struct mem_ctl_info *mci;
 
 	mci = priv->mci[i];
-	device_unregister(mci->pdev);
 	edac_mc_del_mc(mci->pdev);
+	device_unregister(mci->pdev);
 	edac_mc_free(mci);
 }
 





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

* Re: [PATCH] EDAC/versalnet: Fix device-name use-after-free on removal
  2026-11-18 13:30 [PATCH] EDAC/versalnet: Fix device-name use-after-free on removal Suyuan Wang via B4 Relay
@ 2026-11-30 13:55 ` Pandey, Radhey Shyam
  0 siblings, 0 replies; 2+ messages in thread
From: Pandey, Radhey Shyam @ 2026-11-30 13:55 UTC (permalink / raw)
  To: shyckless, tony.luck, bp, shubhrajyoti.datta
  Cc: linux-edac, linux-kernel, radhey.shyam.pandey

On 11/18/2026 7:00 PM, Suyuan Wang via B4 Relay wrote:
> From: Suyuan Wang <stevewong@hust.edu.cn>
> 
> mc_init() stores a pointer to the backing device's name in mci->dev_name
> without copying the string:
> 
> 	mci->dev_name = dev_name(dev);
> 
> remove_one_mc() then unregisters that device before calling
> edac_mc_del_mc():
> 
> 	device_unregister(mci->pdev);
> 	edac_mc_del_mc(mci->pdev);
> 
> device_unregister() can drop the last reference, and kobject_cleanup()
> frees the device's name along with the device. edac_mc_del_mc() then
> logs the controller removal through edac_dev_name(mci), i.e.
> mci->dev_name, reading the freed name string.
> 
> Call edac_mc_del_mc() before device_unregister(), so the device and its
> name stay alive until EDAC has logged and removed the controller.
> 
> Found with a static analysis tool and checked by hand.
> 
> Fixes: d5fe2fec6c40 ("EDAC: Add a driver for the AMD Versal NET DDR controller")
> Link: https://lore.kernel.org/linux-edac/20260724171945.2812749-9-shubhrajyoti.datta@amd.com/
> Cc: stable@vger.kernel.org
> Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
> Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
> Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>

Thanks for the patch. This is already handled in series[1] and applied
to edac-urgent branch.

[1]: 
https://lore.kernel.org/all/20261118142213.100581-1-shubhrajyoti.datta@amd.com

> ---
> We found this independently and later found the earlier patch linked
> above, which fixes the same bug as part of a larger series; this is a
> standalone two-line version. The bad ordering predates the refactor in
> 62a9fc50e8d9 -- it was already in the original driver, in both the normal
> remove path and the init-failure rollback path.
> 
> The change only reorders two cleanup calls. Checked by inspection; I
> couldn't build it here (it needs an arm64 Zynq config and my arm64 cross
> toolchain fails at an unrelated vdso step), and I don't have the hardware.
> ---
>   drivers/edac/versalnet_edac.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/edac/versalnet_edac.c b/drivers/edac/versalnet_edac.c
> index d59ba3904cda..075b0105c427 100644
> --- a/drivers/edac/versalnet_edac.c
> +++ b/drivers/edac/versalnet_edac.c
> @@ -767,8 +767,8 @@ static void remove_one_mc(struct mc_priv *priv, int i)
>   	struct mem_ctl_info *mci;
>   
>   	mci = priv->mci[i];
> -	device_unregister(mci->pdev);
>   	edac_mc_del_mc(mci->pdev);
> +	device_unregister(mci->pdev);
>   	edac_mc_free(mci);
>   }
>   


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

end of thread, other threads:[~2026-11-30 13:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 13:30 [PATCH] EDAC/versalnet: Fix device-name use-after-free on removal Suyuan Wang via B4 Relay
2026-11-30 13:55 ` Pandey, Radhey Shyam

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®