From: Leon Romanovsky <leon@kernel.org>
To: Jiayuan Chen <jiayuan.chen@linux.dev>
Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org,
Jiayuan Chen <jiayuan.chen@shopee.com>,
Jianzhou Zhao <luckd0g@163.com>, Jason Gunthorpe <jgg@ziepe.ca>,
Mark Bloch <mbloch@nvidia.com>,
Edward Srouji <edwards@nvidia.com>,
Or Har-Toov <ohartoov@nvidia.com>,
Kalesh AP <kalesh-anakkur.purayil@broadcom.com>,
Patrisious Haddad <phaddad@nvidia.com>,
Maher Sanalla <msanalla@nvidia.com>,
Yishai Hadas <yishaih@nvidia.com>, Kees Cook <kees@kernel.org>,
Jang Ingyu <ingyujang25@korea.ac.kr>,
Moni Shoua <monis@mellanox.com>,
Doug Ledford <dledford@redhat.com>,
Christian Benvenuti <benve@cisco.com>,
Selvin Xavier <selvin.xavier@broadcom.com>,
Yuval Shaia <yuval.shaia@oracle.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v1] IB/core: Fix use-after-free of ipvlan phy_dev in ib_get_eth_speed
Date: Tue, 17 Mar 2026 15:41:41 +0200 [thread overview]
Message-ID: <20260317134141.GY61385@unreal> (raw)
In-Reply-To: <07b0ee06-aae7-4c48-8ac6-503ee8f8ea63@linux.dev>
On Tue, Mar 17, 2026 at 05:48:55PM +0800, Jiayuan Chen wrote:
>
> On 3/17/26 12:29 AM, Leon Romanovsky wrote:
> > On Wed, Mar 11, 2026 at 06:03:08PM +0800, Jiayuan Chen wrote:
> > > From: Jiayuan Chen <jiayuan.chen@shopee.com>
> > >
> > > Jianzhou Zhao reported a NULL pointer dereference in
> > > __ethtool_get_link_ksettings [1]. The root cause is a use-after-free
> > > of ipvlan->phy_dev.
> > >
> > > In ib_get_eth_speed(), ib_device_get_netdev() obtains a reference to the
> > > ipvlan device outside of rtnl_lock(). This creates a race window: between
> > > ib_device_get_netdev() and rtnl_lock(), the underlying phy_dev (e.g. a
> > > dummy device) can be unregistered and freed by another thread.
> > If ib_device_get_netdev() worked as it was supposed to work, it can't.
> > That function grabs reference on netdev and returns or netdev with elevated
> > reference counter which can't be freed or returns NULL.
> >
> > Thanks
> >
>
> ipvlan's phy_dev is safe in the data path — TX/RX runs in softirq
> context with RCU protection, no lock needed per packet.
>
> The issue here is in the control path. __ethtool_get_link_ksettings()
> requires rtnl_lock() — all existing ethtool callers follow this:
>
> - ioctl path: rtnl_lock() is taken first, then __dev_get_by_name()
> looks up the dev without even holding a refcnt — relying entirely
> on RTNL for safety. (net/ethtool/ioctl.c:3571, 3249)
> - netlink path: dev is looked up with refcnt first, but the actual
> ethtool ops run under rtnl_lock(). (net/ethtool/netlink.c:527-533)
>
> Under RTNL, phy_dev cannot disappear because phy_dev unregistration
> triggers NETDEV_UNREGISTER which deletes ipvlan first — all within
> the same RTNL context. That's why no virtual netdev driver (ipvlan,
> macvlan, bond, etc.) holds an extra refcnt on the lower dev in its
> ethtool callbacks.
>
> ib_get_eth_speed() calls __ethtool_get_link_ksettings() under
> rtnl_lock(), but obtains the netdev before it. Moving the lookup
> inside rtnl_lock() makes the netdev resolution and ethtool call
> atomic w.r.t. device unregistration, consistent with how ethtool's
> own paths work.
Please reread my earlier response and explain how an ipvlan device can
disappear immediately after a successful call to ib_device_get_netdev().
Thanks
>
>
> Thanks
>
>
prev parent reply other threads:[~2026-03-17 13:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-11 10:03 [PATCH net v1] IB/core: Fix use-after-free of ipvlan phy_dev in ib_get_eth_speed Jiayuan Chen
2026-03-12 3:26 ` Jakub Kicinski
2026-03-16 16:29 ` Leon Romanovsky
2026-03-17 9:48 ` Jiayuan Chen
2026-03-17 13:41 ` Leon Romanovsky [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=20260317134141.GY61385@unreal \
--to=leon@kernel.org \
--cc=benve@cisco.com \
--cc=dledford@redhat.com \
--cc=edwards@nvidia.com \
--cc=ingyujang25@korea.ac.kr \
--cc=jgg@ziepe.ca \
--cc=jiayuan.chen@linux.dev \
--cc=jiayuan.chen@shopee.com \
--cc=kalesh-anakkur.purayil@broadcom.com \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=luckd0g@163.com \
--cc=mbloch@nvidia.com \
--cc=monis@mellanox.com \
--cc=msanalla@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=ohartoov@nvidia.com \
--cc=phaddad@nvidia.com \
--cc=selvin.xavier@broadcom.com \
--cc=yishaih@nvidia.com \
--cc=yuval.shaia@oracle.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