* [PATCH net] net: ps3: Unregister Ethernet when wireless probe fails
@ 2026-12-04 16:45 Wanhui Fu
2026-12-05 17:20 ` netdev-bot+sashiko
0 siblings, 1 reply; 2+ messages in thread
From: Wanhui Fu @ 2026-12-04 16:45 UTC (permalink / raw)
To: geoff, andrew+netdev, davem, edumazet, kuba, pabeni, maddy, mpe,
npiggin, chleroy, ritesh.list, sshegde, mokuno, dcbw, jeff,
linville
Cc: netdev, linuxppc-dev, Wanhui Fu
gelic_net_setup_netdev() registers the Ethernet netdev before wireless
initialization. When wireless initialization fails, the probe error
path calls free_netdev() while the Ethernet netdev is still registered,
triggering the registration-state BUG_ON().
Unregister the Ethernet netdev before entering the probe cleanup.
Found it by self-developed static analysis tool and compile-test
passed.
Fixes: 09dde54c6a69 ("PS3: gelic: Add wireless support for PS3")
Signed-off-by: Wanhui Fu <fuwh1120@163.com>
---
drivers/net/ethernet/toshiba/ps3_gelic_net.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
index d35d1f3c10a1..dc660326bc12 100644
--- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
+++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
@@ -1801,6 +1801,7 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
result = gelic_wl_driver_probe(card);
if (result) {
dev_dbg(&dev->core, "%s: WL init failed\n", __func__);
+ unregister_netdev(netdev);
goto fail_setup_netdev;
}
#endif
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] net: ps3: Unregister Ethernet when wireless probe fails
2026-12-04 16:45 [PATCH net] net: ps3: Unregister Ethernet when wireless probe fails Wanhui Fu
@ 2026-12-05 17:20 ` netdev-bot+sashiko
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 17:20 UTC (permalink / raw)
To: fuwh1120
Cc: geoff, andrew+netdev, davem, edumazet, kuba, pabeni, maddy, mpe,
npiggin, chleroy, ritesh.list, sshegde, mokuno, dcbw, jeff,
linville, netdev, linuxppc-dev
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 (1) · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] In ps3_gelic_driver_probe()
(drivers/net/ethernet/toshiba/ps3_gelic_net.c), the new wireless-…
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it is a use-
after-free on the very teardown path the patch fixes.
--
net: ps3: Unregister Ethernet when wireless probe fails
This patch adds an unregister_netdev() call on the wireless probe
failure path in ps3_gelic_driver_probe(). The goal is to unregister the
already registered Ethernet netdev before the shared error unwind calls
free_netdev().
> diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> index d35d1f3c10a18..dc660326bc122 100644
> --- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> +++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
> @@ -1801,6 +1801,7 @@ static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
> result = gelic_wl_driver_probe(card);
> if (result) {
> dev_dbg(&dev->core, "%s: WL init failed\n", __func__);
> + unregister_netdev(netdev);
> goto fail_setup_netdev;
[Severity: Medium]
Can card->tx_timeout_task still be pending or running when the unwind
frees the card?
gelic_net_setup_netdev() has already registered eth0 by the time
gelic_wl_driver_probe() runs, so userspace can bring eth0 up. If the TX
watchdog then fires, gelic_net_tx_timeout() queues the driver-owned
work:
atomic_inc(&card->tx_timeout_task_counter);
if (netdev->flags & IFF_UP)
schedule_work(&card->tx_timeout_task);
unregister_netdev()->dev_close() stops the core watchdog timer. Neither
it nor gelic_net_stop() cancels tx_timeout_task. The unwind then
reaches:
fail_status_indicator:
ps3_system_bus_set_drvdata(dev, NULL);
kfree(netdev_card(netdev)->unalign);
free_netdev(netdev);
If the work is still pending, gelic_net_tx_timeout_task() calls
container_of() on the freed card and reads card->netdev[0]->flags.
If the work is already running inside
gelic_net_open()->gelic_card_up(), it can turn the IRQ mask, RX DMAC
and NAPI back on while the unwind is freeing the descriptor chains.
ps3_gelic_driver_remove() waits for this work before it frees the card:
wait_event(card->waitq,
atomic_read(&card->tx_timeout_task_counter) == 0);
Should this path have a matching step, such as
cancel_work_sync(&card->tx_timeout_task) after unregister_netdev()?
To hit this window, eth0 has to be opened and the watchdog (5*HZ) has
to fire while gelic_wl_driver_probe() is still running. That may be
hard to trigger in practice.
[Severity: High]
This isn't a bug introduced by this patch, but the unwind that this
path now reaches appears to have a use-after-free of card->napi.
The card is kzalloc'd separately from the netdev, and napi is its first
member. gelic_ether_setup_netdev_ops() links it into the netdev:
netif_napi_add(netdev, napi, gelic_net_poll);
The error tail then frees the card before it frees the netdev:
kfree(netdev_card(netdev)->unalign);
free_netdev(netdev);
free_netdev()->netdev_napi_exit() walks dev->napi_list and calls
__netif_napi_del_locked() on &card->napi. That function runs
test_and_clear_bit() on napi->state, hrtimer_cancel(&napi->timer) and
list_del_rcu(&napi->dev_list), all on the card that was already freed.
ps3_gelic_driver_remove(), which is also the .shutdown callback, frees
in the same order:
unregister_netdev(netdev0);
kfree(netdev_card(netdev0)->unalign);
free_netdev(netdev0);
With this patch, the wireless failure path avoids the reg_state
BUG_ON() in free_netdev() but still reaches this use-after-free. The
gelic_net_setup_netdev() failure path and every remove and shutdown
reach it too.
Would it make sense to call free_netdev() before kfree(card->unalign),
or to call netif_napi_del(&card->napi) before the card is freed? That
change would be needed in both the probe unwind and
ps3_gelic_driver_remove().
> }
> #endif
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204164508.2083305-1-fuwh1120%40163.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-05 17:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 16:45 [PATCH net] net: ps3: Unregister Ethernet when wireless probe fails Wanhui Fu
2026-12-05 17:20 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox