mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xinyou Ji <jerryjilol@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] uio: remove the device before releasing its minor
Date: Tue, 10 Nov 2026 11:15:28 +0000	[thread overview]
Message-ID: <20261110111528.2248401-1-jerryjilol@gmail.com> (raw)

core-1                            core-2
====================================================================
uio_unregister_device()           __uio_register_device()
  uio_free_minor(minor)
                                    uio_get_minor(idev)
                                    device_add(&idev->dev)
                                      -> -EEXIST
  device_unregister(&idev->dev)
====================================================================

After core-1 releases the minor, core-2 can reuse it before the old
uioN sysfs entry is removed. device_add() then fails with -EEXIST.
This caused TCMU backstore creation failures.

Call device_del() before uio_free_minor() and put_device() afterwards.
This removes the old name before minor reuse while keeping the device
alive until its IDR entry is removed, so concurrent uio_open() cannot
access a freed device.

Fixes: 0c9ae0b86050 ("uio: Fix use-after-free in uio_open")
Link: https://lists.openwall.net/linux-kernel/2026/04/16/709
Cc: stable@vger.kernel.org
Signed-off-by: Xinyou Ji <jerryjilol@gmail.com>

---
Built the 7.4.0-rc2 x86_64 kernel and modules. With 128 workers
repeatedly creating and removing TCMU backstores, the unpatched run
failed to enable a backstore with -EEXIST after 385 successful
create/remove iterations across the workers. Replacing only the UIO
module on the same booted kernel completed 4,350 such iterations and
1,758,183 concurrent read/write operations without -EEXIST.

diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index f8fa205..aa93cb9 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -1136,8 +1136,9 @@ void uio_unregister_device(struct uio_info *info)
 	wake_up_interruptible(&idev->wait);
 	kill_fasync(&idev->async_queue, SIGIO, POLL_HUP);
 
+	device_del(&idev->dev);
 	uio_free_minor(minor);
-	device_unregister(&idev->dev);
+	put_device(&idev->dev);
 
 	return;
 }

base-commit: b3dfbde62cf1981c4638939c159dfd087b7a72e9
-- 
2.54.0


                 reply	other threads:[~2026-11-10 11:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261110111528.2248401-1-jerryjilol@gmail.com \
    --to=jerryjilol@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    /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®