mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: tristmd@gmail.com
Cc: sam@mendozajonas.com, fercerpav@gmail.com, davem@davemloft.net,
	edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
	horms@kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	tristan@talencesecurity.com
Subject: Re: [PATCH v2 net 1/2] net/ncsi: add missing rcu_read_lock to netlink and device list walks
Date: Tue, 24 Nov 2026 23:56:49 +0000	[thread overview]
Message-ID: <179556460945.3135.15659166746585133239@kernel.org> (raw)
In-Reply-To: <20261120235407.1911365-2-tristmd@gmail.com>

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

  reply	other threads:[~2026-11-24 23:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 23:54 [PATCH v2 net 0/2] net/ncsi: fix RCU list entry lifetime on package and channel removal Tristan Madani
2026-11-20 23:54 ` [PATCH v2 net 1/2] net/ncsi: add missing rcu_read_lock to netlink and device list walks Tristan Madani
2026-11-24 23:56   ` netdev-bot+sashiko [this message]
2026-11-20 23:54 ` [PATCH v2 net 2/2] net/ncsi: defer free of removed list entries to an RCU grace period Tristan Madani
2026-11-24 23:56   ` netdev-bot+sashiko

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=179556460945.3135.15659166746585133239@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=fercerpav@gmail.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sam@mendozajonas.com \
    --cc=stable@vger.kernel.org \
    --cc=tristan@talencesecurity.com \
    --cc=tristmd@gmail.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

all inboxes | Powered by JetHome®