All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Bodo Strößer" <bostroesser@gmail.com>
To: Tao Zou <zoutao@linux.alibaba.com>,
	"Martin K . Petersen" <mkp@kernel.org>
Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org
Subject: Re: [PATCH v2 1/1] tcmu: Fix inode use-after-free in global data block pool
Date: Tue, 1 Dec 2026 20:33:59 +0100	[thread overview]
Message-ID: <b58202d8-8030-48e5-a8aa-3fbedc4c85aa@gmail.com> (raw)
In-Reply-To: <20261128132934.11219-2-zoutao@linux.alibaba.com>

On 28/11/2026 14:29, Tao Zou wrote:
> tcmu_open() stores the character device inode in udev->inode, but
> tcmu_release() does not clear it.  If tcmu-runner exits while the LIO
> configuration remains, delayed global data-block reclaim can later
> dereference the stale inode in unmap_mapping_range() after the VFS has
> freed it.
>
> The open file and its VMAs already keep the inode alive while mappings
> exist, so no additional inode reference is needed.  Protect the pointer
> with cmdr_lock, clear it in tcmu_release(), and skip only the mapping
> invalidation after the final close.  Block reclamation still runs.
>
> Fixes: b6df4b79a551 ("tcmu: Add global data block pool support")
> Signed-off-by: Tao Zou <zoutao@linux.alibaba.com>
> ---
>   drivers/target/target_core_user.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
>
> Changes in v2:
> - Drop the extra inode reference, which did not pin the mount or
>    sb->s_active and could leave a busy inode during filesystem unmount.
> - Clear udev->inode in tcmu_release() and skip only mapping invalidation
>    after the final close; block reclamation still runs.
> - Test the original reproducer and a separate tmpfs unmount, reopen,
>    delayed reclaim and device destruction scenario.
>
> diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c
> index 80da90a..481b16f 100644
> --- a/drivers/target/target_core_user.c
> +++ b/drivers/target/target_core_user.c
> @@ -1959,7 +1959,9 @@ static int tcmu_open(struct uio_info *info, struct inode *inode)
>   	if (test_and_set_bit(TCMU_DEV_BIT_OPEN, &udev->flags))
>   		return -EBUSY;
>   
> +	mutex_lock(&udev->cmdr_lock);
>   	udev->inode = inode;
> +	mutex_unlock(&udev->cmdr_lock);
>   
>   	pr_debug("open\n");
>   
> @@ -2000,6 +2002,7 @@ static int tcmu_release(struct uio_info *info, struct inode *inode)
>   	if (freed && list_empty(&udev->tmr_queue))
>   		run_qfull_queue(udev, false);
>   
> +	udev->inode = NULL;
>   	mutex_unlock(&udev->cmdr_lock);
>   
>   	clear_bit(TCMU_DEV_BIT_OPEN, &udev->flags);
> @@ -3255,7 +3258,9 @@ static void find_free_blocks(void)
>   
>   		/* Here will truncate the data area from off */
>   		off = udev->data_off + (loff_t)start * udev->data_blk_size;
> -		unmap_mapping_range(udev->inode->i_mapping, off, 0, 1);
> +		/* All VMAs are closed before the last fput calls tcmu_release(). */
> +		if (udev->inode)
> +			unmap_mapping_range(udev->inode->i_mapping, off, 0, 1);
>   
>   		mutex_unlock(&udev->cmdr_lock);
>   

Hi Zou,

thank you for this bug report, the analysis and intense testing.
I'm still wondering why we didn't see crashes in the past. Probably 
block reclamation isn't used very much.

V2 of the patch looks very good, thank you.

Reviewed-by: Bodo Stroesser <bostroesser@gmail.com>

Regards,
Bodo Stroesser




  reply	other threads:[~2026-12-01 19:34 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
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 [this message]
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=b58202d8-8030-48e5-a8aa-3fbedc4c85aa@gmail.com \
    --to=bostroesser@gmail.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mkp@kernel.org \
    --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.