[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <36f320f3-f4e6-7388-6292-83f240bcd28c@huawei.com>
Date: Thu, 24 Nov 2022 15:28:38 +0800
From: Yang Yingliang <yangyingliang@...wei.com>
To: Jakub Kicinski <kuba@...nel.org>
CC: Leon Romanovsky <leon@...nel.org>, <netdev@...r.kernel.org>,
<jiri@...dia.com>, <davem@...emloft.net>, <edumazet@...gle.com>,
<pabeni@...hat.com>
Subject: Re: [PATCH net] net: devlink: fix UAF in
devlink_compat_running_version()
On 2022/11/24 10:47, Jakub Kicinski wrote:
> On Wed, 23 Nov 2022 14:40:24 +0800 Yang Yingliang wrote:
>>> +err_dl_unregister:
>>> + devl_unregister(devlink);
>> It races with dev_ethtool():
>> dev_ethtool
>> devlink_try_get()
>> nsim_drv_probe
>> devl_lock()
>> devl_lock()
>> devlink_unregister()
>> devlink_put()
>> wait_for_completion() <- the refcount
>> is got in dev_ethtool, it causes ABBA deadlock
> Yeah.. so my original design for the locking had a "devlink_is_alive()"
> check for this exact reason:
>
> https://lore.kernel.org/netdev/20211030231254.2477599-3-kuba@kernel.org/
>
> and the devlink structure was properly refcounted (devlink_put() calls
> devlink_free() when the last reference is released).
>
> Pure references then need to check if the instance is still alive
> after locking it. Which is fine, it should only happen in core code.
>
> I think we should go back to that idea.
But Leon disagree to change devlink code.
I think this problem occurs in the drivers that have multiple ports(netdev):
In some drivers (e.g. mlx5) , one net device uses one devlink
instance(see mlx5e_probe()),
the instance can not be get until the device is register, in this case,
it won't cause UAF.
But in some other drivers(e.g. netdevsim, funeth) multiple ports(net
devices) use one
devlink instance. If first one is register successful, the instance is
visible and can be get
through netdev, meanwhile, the second port register failed and goto free
the devlink
that used by first port(netdevice). So can we fix this in every single
driver.
Thanks,
Yang
>
> The waiting for references is a nightmare in the netdev code.
>
> .
Powered by blists - more mailing lists