Subject: Re: [PATCH net] net: devlink: fix UAF in devlink_compat_running_version()

From: Leon Romanovsky <[email-masked]>
Date: Wed, 30 Nov 2022 10:54:06 +0200

On Tue, Nov 29, 2022 at 06:18:26PM -0800, Jakub Kicinski wrote:
> On Tue, 29 Nov 2022 09:31:40 +0100 Jiri Pirko wrote:
> > >Cool. Do you also agree with doing proper refcounting for the devlink
> > >instance struct and the liveness check after locking the instance?  
> > 
> > Could you elaborate a bit more? I missed that in the thread and can't
> > find it. Why do we need it?
> 
> Look at the __devlink_free() and changes 
> to devlink_compat_flash_update() here:
> 
> https://lore.kernel.org/netdev/[email-masked]/
> 
> The model I had in mind (a year ago when it all started) was that 
> the driver takes the devlink instance lock around its entire init path,
> including the registration of the instance. This way the devlink
> instance is never visible "half initialized". I mean - it's "visible"
> as in you can see a notification over netlink before init is done but
> you can't access it until the init in the driver is completed and it
> releases the instance lock.

In parallel thread, Jiri wanted to avoid this situation of netlink
notifications for not-visible yet object. He gave as an example
devlink_port which is advertised without devlink being ready.

Thanks