Re: [PATCH v2 net 1/2] net/ncsi: add missing rcu_read_lock to netlink and device list walks
From: netdev-bot+sashiko
Date: Tue Nov 24 2026 - 18:56:58 EST
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · 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).
- [High] The new RCU section in ncsi_find_dev() ends before the pointer
it found is used.
--
net/ncsi: add missing rcu_read_lock to netlink and device list walks
This commit adds rcu_read_lock()/rcu_read_unlock() around the
NCSI_FOR_EACH_* list walks in ncsi_find_dev(), ncsi_write_package_info()
and ncsi_pkg_info_all_nl(). It also turns the early returns in
ncsi_write_package_info() into a goto so there is a single unlock point.
> diff --git a/net/ncsi/ncsi-manage.c b/net/ncsi/ncsi-manage.c
> index 1d63958c4429b..ec7c0d8cf3d9f 100644
> --- a/net/ncsi/ncsi-manage.c
> +++ b/net/ncsi/ncsi-manage.c
> @@ -419,13 +419,18 @@ void ncsi_free_request(struct ncsi_request *nr)
> struct ncsi_dev *ncsi_find_dev(struct net_device *dev)
> {
> struct ncsi_dev_priv *ndp;
> + struct ncsi_dev *nd = NULL;
>
> + rcu_read_lock();
> NCSI_FOR_EACH_DEV(ndp) {
> - if (ndp->ndev.dev == dev)
> - return &ndp->ndev;
> + if (ndp->ndev.dev == dev) {
> + nd = &ndp->ndev;
> + break;
> + }
> }
> + rcu_read_unlock();
>
> - return NULL;
> + return nd;
> }
[Severity: High]
Is ndp still used after this RCU section ends?
ncsi_find_dev() drops the RCU read lock before it returns &ndp->ndev.
ndp_from_ifindex() then drops the netdev reference too:
net/ncsi/ncsi-netlink.c:ndp_from_ifindex() {
...
nd = ncsi_find_dev(dev);
ndp = nd ? TO_NCSI_DEV_PRIV(nd) : NULL;
dev_put(dev);
return ndp;
}
As a result, the NCSI_CMD_PKG_INFO doit handler, which unprivileged users
can call, uses ndp without holding a reference and outside any RCU
read-side section:
ncsi_pkg_info_nl()
ndp_from_ifindex()
ncsi_find_dev() <- rcu_read_unlock()
genlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL) <- may sleep
ncsi_write_package_info(skb, ndp, package_id)
reads ndp->package_num / ndp->ndev.dev before rcu_read_lock()
NCSI_FOR_EACH_PACKAGE(ndp, np) <- list head embedded in ndp
ncsi_pkg_info_all_nl() follows the same pattern. It gets ndp from
ndp_from_ifindex(), walks ndp->packages, and then calls
ncsi_write_package_info(skb, ndp, package_id).
On the free side, ftgmac100_remove()->ncsi_unregister_dev() does:
spin_lock_irqsave(&ncsi_dev_lock, flags);
list_del_rcu(&ndp->node);
spin_unlock_irqrestore(&ncsi_dev_lock, flags);
disable_work_sync(&ndp->work);
kfree(ndp);
Can ndp be freed while ncsi_pkg_info_nl() or ncsi_pkg_info_all_nl() is
still using it?
The follow-up patch "net/ncsi: defer free of removed list entries to an
RCU grace period" changes this to kfree_rcu_mightsleep(ndp). Even so, the
grace period can end between the rcu_read_unlock() in ncsi_find_dev() and
the next rcu_read_lock() in ncsi_write_package_info(). The sleeping
genlmsg_new() call sits inside that gap.
The netdev reference can't pin ndp either. ftgmac100_remove() unregisters
NCSI before it unregisters the netdev:
if (priv->ndev)
ncsi_unregister_dev(priv->ndev);
unregister_netdev(netdev);
The commit message says these walks race with ncsi_unregister_dev(). Is
that race still open through the ndp pointer that ncsi_find_dev()
returns? The follow-up patch doesn't change ncsi_find_dev(),
ndp_from_ifindex() or the netlink handlers, so the issue seems to remain
after the full series.
Would this need either a reference count on ndp, or one RCU section that
covers every use of ndp in the handlers, with the sleeping allocation
moved out of it?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120235407.1911365-1-tristmd%40gmail.com