All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tao Zou" <zoutao@linux.alibaba.com>
Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org
Subject: Re: [PATCH 1/1] tcmu: Fix inode use-after-free in global data block pool
Date: Fri, 27 Nov 2026 02:45:31 +0000	[thread overview]
Message-ID: <sashiko-outbox-236459@kernel.org> (raw)
In-Reply-To: <20261127023346.37933-2-zoutao@linux.alibaba.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] tcmu: pinning udev->inode past tcmu_release() breaks superblock
  unmount
--

commit b2536748e9ead622de5208515ec23331a1f19191
Author: Tao Zou <zoutao@linux.alibaba.com>

tcmu: Fix inode use-after-free in global data block pool

This commit takes an inode reference in tcmu_open() under cmdr_lock and
holds it until tcmu_dev_kref_release() or a subsequent reopen so
find_free_blocks() does not dereference a reclaimed inode after the UIO
device is closed.

> diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c
> index 80da90accac56..1bd53cdd1d964 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");

[Severity: High]
Can holding udev->inode past tcmu_release() leave a busy inode when the
filesystem hosting the character device node is unmounted?

After the last file descriptor and all VMAs are closed, __fput() invokes
tcmu_release() and drops the file's dentry and vfsmount references.
Because ihold() does not pin the mount or sb->s_active, unmounting that
filesystem while the TCMU device is still configured reaches
generic_shutdown_super() with udev->inode still on sb->s_inodes,
triggering CHECK_DATA_CORRUPTION ("VFS: Busy inodes after unmount") and
poisoning inode->i_op, inode->i_sb, and inode->i_mapping with
VFS_PTR_POISON.  Any later find_free_blocks() call or final iput() then
dereferences VFS_PTR_POISON.

Since __fput() only calls tcmu_release() after all VMAs mapping the file
have been unmapped, could tcmu_release() instead clear udev->inode = NULL
under udev->cmdr_lock and find_free_blocks() skip unmap_mapping_range()
when udev->inode is NULL?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127023346.37933-1-zoutao@linux.alibaba.com?part=1

  reply	other threads:[~2026-11-27  2:45 UTC|newest]

Thread overview: 7+ 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 ` [PATCH 1/1] " Tao Zou
2026-11-27  2:45   ` sashiko-bot [this message]
2026-11-28 13:29 ` [PATCH v2 0/1] " Tao Zou
2026-11-28 13:29   ` [PATCH v2 1/1] " Tao Zou
2026-12-01 19:33     ` Bodo Strößer
2026-12-02  2:32       ` Tao Zou

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=sashiko-outbox-236459@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=target-devel@vger.kernel.org \
    --cc=zoutao@linux.alibaba.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.