Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: fuwh1120@163.com
Cc: geoff@infradead.org, andrew+netdev@lunn.ch, davem@davemloft.net,
	edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
	maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com,
	chleroy@kernel.org, ritesh.list@gmail.com, sshegde@linux.ibm.com,
	mokuno@sm.sony.co.jp, dcbw@redhat.com, jeff@garzik.org,
	linville@tuxdriver.com, netdev@vger.kernel.org,
	linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH net] net: ps3: Unregister Ethernet when wireless probe fails
Date: Sat, 05 Dec 2026 17:20:43 +0000	[thread overview]
Message-ID: <179649124305.3146.2081352787535255828@kernel.org> (raw)
In-Reply-To: <20261204164508.2083305-1-fuwh1120@163.com>

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

      reply	other threads:[~2026-12-05 17:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 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=179649124305.3146.2081352787535255828@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=chleroy@kernel.org \
    --cc=davem@davemloft.net \
    --cc=dcbw@redhat.com \
    --cc=edumazet@kernel.org \
    --cc=fuwh1120@163.com \
    --cc=geoff@infradead.org \
    --cc=jeff@garzik.org \
    --cc=kuba@kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=linville@tuxdriver.com \
    --cc=maddy@linux.ibm.com \
    --cc=mokuno@sm.sony.co.jp \
    --cc=mpe@ellerman.id.au \
    --cc=netdev@vger.kernel.org \
    --cc=npiggin@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=ritesh.list@gmail.com \
    --cc=sshegde@linux.ibm.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