From: Tao Zou <zoutao@linux.alibaba.com>
To: Bodo Stroesser <bostroesser@gmail.com>,
"Martin K . Petersen" <mkp@kernel.org>
Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org,
Tao Zou <zoutao@linux.alibaba.com>
Subject: [PATCH 1/1] tcmu: Fix inode use-after-free in global data block pool
Date: Fri, 27 Nov 2026 10:33:46 +0800 [thread overview]
Message-ID: <20261127023346.37933-2-zoutao@linux.alibaba.com> (raw)
In-Reply-To: <20261127023346.37933-1-zoutao@linux.alibaba.com>
The global data block pool can use udev->inode from delayed unmap work
after userspace closes the UIO device. tcmu_open() only stores the raw
pointer, so VFS can reclaim the inode while the device remains on
root_udev. A later find_free_blocks() then dereferences the stale pointer
in unmap_mapping_range().
Take an inode reference in tcmu_open() and hold it until the final device
reference is released. Replace the pointer under cmdr_lock to synchronize
with find_free_blocks(), and drop the previous reference after a reopen.
Keep the reference across tcmu_release() because delayed unmap work still
needs the inode after the last UIO close.
Fixes: b6df4b79a551 ("tcmu: Add global data block pool support")
Signed-off-by: Tao Zou <zoutao@linux.alibaba.com>
---
drivers/target/target_core_user.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c
index 80da90a..1bd53cd 100644
--- a/drivers/target/target_core_user.c
+++ b/drivers/target/target_core_user.c
@@ -1741,6 +1741,8 @@ static void tcmu_dev_kref_release(struct kref *kref)
bitmap_free(udev->data_bitmap);
mutex_unlock(&udev->cmdr_lock);
+ iput(udev->inode);
+
pr_debug("dev_kref_release\n");
call_rcu(&dev->rcu_head, tcmu_dev_call_rcu);
@@ -1954,12 +1956,21 @@ static int tcmu_mmap_prepare(struct uio_info *info, struct vm_area_desc *desc)
static int tcmu_open(struct uio_info *info, struct inode *inode)
{
struct tcmu_dev *udev = container_of(info, struct tcmu_dev, uio_info);
+ struct inode *old_inode;
/* O_EXCL not supported for char devs, so fake it? */
if (test_and_set_bit(TCMU_DEV_BIT_OPEN, &udev->flags))
return -EBUSY;
+ /* find_free_blocks() may use the inode after the last UIO close. */
+ ihold(inode);
+
+ mutex_lock(&udev->cmdr_lock);
+ old_inode = udev->inode;
udev->inode = inode;
+ mutex_unlock(&udev->cmdr_lock);
+
+ iput(old_inode);
pr_debug("open\n");
--
2.39.5 (Apple Git-154)
next prev parent reply other threads:[~2026-11-27 2:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 2:33 [PATCH 0/1] tcmu: Fix inode use-after-free in global data block pool Tao Zou
2026-11-27 2:33 ` Tao Zou [this message]
2026-11-27 2:45 ` [PATCH 1/1] " sashiko-bot
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=20261127023346.37933-2-zoutao@linux.alibaba.com \
--to=zoutao@linux.alibaba.com \
--cc=bostroesser@gmail.com \
--cc=linux-scsi@vger.kernel.org \
--cc=mkp@kernel.org \
--cc=target-devel@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