From: sashiko-bot@kernel.org
To: "Linmao Li" <lilinmao@kylinos.cn>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v2 1/2] scsi: leapraid: balance host references for firmware log VMAs
Date: Thu, 13 Aug 2026 07:39:01 +0000 [thread overview]
Message-ID: <20260813073901.808DE1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260813072614.1387555-2-lilinmao@kylinos.cn>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Unkillable sleep in device removal path if userspace keeps the memory mapped.
- [High] TOCTOU race in leapraid_fw_mmap allowing use-after-free of fw_log_buffer.
--
--- Patch [1]: [PATCH v2 1/2] scsi: leapraid: balance host references for firmware log VMAs ---
commit f0e08e76b84e5bcaddf6147e197d89f0cec2a4e9
Author: Linmao Li <lilinmao@kylinos.cn>
scsi: leapraid: balance host references for firmware log VMAs
leapraid_fw_mmap() keeps the Scsi_Host reference obtained while
looking up the adapter for the lifetime of the initial VMA. The VMA
close callback drops that reference.
The open callback is also invoked when a VMA is duplicated or split,
but it only increments mmap_refcnt. Since every corresponding close
callback drops a host reference, cloning the mapping can release the
host while another VMA still refers to the adapter.
Take a host device reference for every VMA open and release the lookup
reference once the initial mapping has acquired its own reference. Use
get_device() because a VMA can be cloned after the host enters SHOST_DEL;
an existing VMA still pins the host at that point and open cannot fail.
> diff --git a/drivers/scsi/leapraid/leapraid_app.c b/drivers/scsi/leapraid/leapraid_app.c
> index 742f19c07fcbb..841027ce2501c 100644
> --- a/drivers/scsi/leapraid/leapraid_app.c
> +++ b/drivers/scsi/leapraid/leapraid_app.c
> @@ -697,6 +697,7 @@ static void leapraid_fw_mmap_open(struct vm_area_struct *vma)
> if (!adapter)
> return;
>
> + get_device(&adapter->shost->shost_gendev);
> atomic_inc(&adapter->fw_log_desc.mmap_refcnt);
[Severity: High]
This is a pre-existing issue, but does this create an unkillable sleep in the
device removal path?
If a user maps the firmware log buffer via mmap and never unmaps it, the
removal thread executing leapraid_fw_log_exit() in leapraid_func.c will block
indefinitely waiting for the reference count to drop to zero:
wait_event(adapter->fw_log_desc.mmap_waitq,
!atomic_read(&adapter->fw_log_desc.mmap_refcnt));
Since there is no mechanism to forcibly revoke the mapping, could this allow
userspace to block device removal indefinitely?
> }
>
> @@ -767,7 +768,6 @@ static int leapraid_fw_mmap(struct file *filp, struct vm_area_struct *vma)
> vma->vm_private_data = adapter;
> vma->vm_ops = &leapraid_fw_mmap_vm_ops;
> leapraid_fw_mmap_open(vma);
[Severity: High]
This isn't a bug introduced by this patch, but is there a race condition here
that allows a use-after-free of the firmware log buffer?
The buffer is mapped to user space via dma_mmap_coherent() earlier in this
function before mmap_refcnt is incremented here in leapraid_fw_mmap_open().
If a concurrent device removal preempts this thread right before
leapraid_fw_mmap_open() is called, leapraid_fw_log_exit() will see
mmap_refcnt == 0 and free the buffer via dma_free_coherent().
When the mmap thread resumes, will it have successfully mapped freed kernel
DMA memory into user space?
> - adapter = NULL;
>
> rc = 0;
> out_put:
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260813072614.1387555-1-lilinmao@kylinos.cn?part=1
next prev parent reply other threads:[~2026-08-13 7:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-13 7:26 [PATCH v2 0/2] scsi: leapraid: fix firmware log mmap lifetime Linmao Li
2026-08-13 7:26 ` [PATCH v2 1/2] scsi: leapraid: balance host references for firmware log VMAs Linmao Li
2026-08-13 7:39 ` sashiko-bot [this message]
2026-08-13 7:26 ` [PATCH v2 2/2] scsi: leapraid: serialize firmware log mmap with teardown Linmao Li
2026-08-13 7:39 ` 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=20260813073901.808DE1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=lilinmao@kylinos.cn \
--cc=linux-scsi@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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