The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] RDMA/core: Fix slab-use-after-free in kernfs_find_ns()
@ 2026-11-24 16:32 Habil Eren Türker
  2026-11-24 19:39 ` Habil Eren Türker
  2026-11-26 12:17 ` Leon Romanovsky
  0 siblings, 2 replies; 3+ messages in thread
From: Habil Eren Türker @ 2026-11-24 16:32 UTC (permalink / raw)
  To: Jason Gunthorpe, Leon Romanovsky
  Cc: Parav Pandit, Jiri Pirko, linux-rdma@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	syzbot+8c2fa00c27ecafd148f5@syzkaller.appspotmail.com,
	Habil Eren Türker

In drivers/infiniband/core/device.c, remove_one_compat_dev() unlocks
device->compat_devs_mutex immediately after erasing cdev from
the xarray. device_del(&cdev->dev) is performed outside the lock.

When IB device removal races with network namespace teardown
(cleanup_net() -> rdma_dev_exit_net()), rdma_dev_exit_net() calls
remove_one_compat_dev() and observes NULL from xa_erase(), and
returns without waiting for device_del() to finish.

cleanup_net() frees struct net while device_del() is still executing,
causing device_remove_class_symlinks() -> sysfs_delete_link() ->
kernfs_ns_id() to read ns->ns_id from the freed struct net,
which triggers a slab-use-after-free.

Fix this by moving mutex_unlock(&device->compat_devs_mutex) after
device_del(&cdev->dev) finishes, while keeping put_device(&cdev->dev)
outside the lock.

Fixes: 4e0f7b907072 ("RDMA/core: Implement compat device/sysfs tree in net namespace")
Reported-by: syzbot+8c2fa00c27ecafd148f5@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=8c2fa00c27ecafd148f5
Signed-off-by: Habil Eren Türker <habilerenturker@hotmail.com>
---
 drivers/infiniband/core/device.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index 29af9fe860e2..f2a52af64718 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -1030,12 +1030,13 @@ static void remove_one_compat_dev(struct ib_device *device, u32 id)
 
 	mutex_lock(&device->compat_devs_mutex);
 	cdev = xa_erase(&device->compat_devs, id);
-	mutex_unlock(&device->compat_devs_mutex);
 	if (cdev) {
 		ib_free_port_attrs(cdev);
 		device_del(&cdev->dev);
-		put_device(&cdev->dev);
 	}
+	mutex_unlock(&device->compat_devs_mutex);
+	if (cdev)
+		put_device(&cdev->dev);
 }
 
 static void remove_compat_devs(struct ib_device *device)
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] RDMA/core: Fix slab-use-after-free in kernfs_find_ns()
  2026-11-24 16:32 [PATCH] RDMA/core: Fix slab-use-after-free in kernfs_find_ns() Habil Eren Türker
@ 2026-11-24 19:39 ` Habil Eren Türker
  2026-11-26 12:17 ` Leon Romanovsky
  1 sibling, 0 replies; 3+ messages in thread
From: Habil Eren Türker @ 2026-11-24 19:39 UTC (permalink / raw)
  To: Habil Eren Türker
  Cc: jgg@ziepe.ca, jiri@resnulli.us, leon@kernel.org,
	linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org,
	parav@nvidia.com,
	syzbot+8c2fa00c27ecafd148f5@syzkaller.appspotmail.com

Hi,

Tested with CONFIG_KASAN=y, CONFIG_PROVE_LOCKING=y, CONFIG_LOCKDEP=y
and CONFIG_RDMA_RXE=y on QEMU with -smp 4, using the syzbot reproducer.

Without the patch (pre-c41d577ac525), the reproducer reliably triggers
a KASAN slab-use-after-free in the device_del() path (observed in
kobject_uevent_env, reading a uevent_net that was freed by cleanup_net
in a racing netns teardown).

With the patch applied, the same reproducer over 10 iterations of the
rxe0 add/del + netns teardown race shows no KASAN splat and no lockdep
warning.

Regards,
Türker

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] RDMA/core: Fix slab-use-after-free in kernfs_find_ns()
  2026-11-24 16:32 [PATCH] RDMA/core: Fix slab-use-after-free in kernfs_find_ns() Habil Eren Türker
  2026-11-24 19:39 ` Habil Eren Türker
@ 2026-11-26 12:17 ` Leon Romanovsky
  1 sibling, 0 replies; 3+ messages in thread
From: Leon Romanovsky @ 2026-11-26 12:17 UTC (permalink / raw)
  To: Habil Eren Türker
  Cc: Jason Gunthorpe, Parav Pandit, Jiri Pirko,
	linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org,
	syzbot+8c2fa00c27ecafd148f5@syzkaller.appspotmail.com

On Tue, Nov 24, 2026 at 04:32:26PM +0000, Habil Eren Türker wrote:
> In drivers/infiniband/core/device.c, remove_one_compat_dev() unlocks
> device->compat_devs_mutex immediately after erasing cdev from
> the xarray. device_del(&cdev->dev) is performed outside the lock.
> 
> When IB device removal races with network namespace teardown
> (cleanup_net() -> rdma_dev_exit_net()), rdma_dev_exit_net() calls
> remove_one_compat_dev() and observes NULL from xa_erase(), and
> returns without waiting for device_del() to finish.

Please include the KASAN report in the commit message
and rewrite the AI-generated prose in function-ladder format.

Thanks

> 
> cleanup_net() frees struct net while device_del() is still executing,
> causing device_remove_class_symlinks() -> sysfs_delete_link() ->
> kernfs_ns_id() to read ns->ns_id from the freed struct net,
> which triggers a slab-use-after-free.
> 
> Fix this by moving mutex_unlock(&device->compat_devs_mutex) after
> device_del(&cdev->dev) finishes, while keeping put_device(&cdev->dev)
> outside the lock.
> 
> Fixes: 4e0f7b907072 ("RDMA/core: Implement compat device/sysfs tree in net namespace")
> Reported-by: syzbot+8c2fa00c27ecafd148f5@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=8c2fa00c27ecafd148f5
> Signed-off-by: Habil Eren Türker <habilerenturker@hotmail.com>
> ---
>  drivers/infiniband/core/device.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
> index 29af9fe860e2..f2a52af64718 100644
> --- a/drivers/infiniband/core/device.c
> +++ b/drivers/infiniband/core/device.c
> @@ -1030,12 +1030,13 @@ static void remove_one_compat_dev(struct ib_device *device, u32 id)
>  
>  	mutex_lock(&device->compat_devs_mutex);
>  	cdev = xa_erase(&device->compat_devs, id);
> -	mutex_unlock(&device->compat_devs_mutex);
>  	if (cdev) {
>  		ib_free_port_attrs(cdev);
>  		device_del(&cdev->dev);
> -		put_device(&cdev->dev);
>  	}
> +	mutex_unlock(&device->compat_devs_mutex);
> +	if (cdev)
> +		put_device(&cdev->dev);
>  }
>  
>  static void remove_compat_devs(struct ib_device *device)
> -- 
> 2.47.3
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-26 12:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 16:32 [PATCH] RDMA/core: Fix slab-use-after-free in kernfs_find_ns() Habil Eren Türker
2026-11-24 19:39 ` Habil Eren Türker
2026-11-26 12:17 ` Leon Romanovsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox