From: Dongli Zhang <dongli.zhang@oracle.com>
To: sashiko-reviews@lists.linux.dev, virtualization@lists.linux.dev
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 1/2] vhost-scsi: use kvzalloc for vq array allocation
Date: Fri, 31 Jul 2026 16:23:43 -0700 [thread overview]
Message-ID: <ba095baf-8837-4295-868b-891fa812f4a2@oracle.com> (raw)
In-Reply-To: <20260731222400.8AC7D1F00AC4@smtp.kernel.org>
+ virtualization@lists.linux.dev.
On 2026-07-31 3:24 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
>
> Pre-existing issues:
> - [High] The `max_io_vqs` module parameter is parsed as an unsigned integer but assigned to a signed `int` in `vhost_scsi_open()`. Setting this parameter to a large unsigned value (e.g., `4294967295`) results in a negative value (e.g., `-1`) that bypasses the maximum bound check. This leads to an undersized allocation followed by statically indexed Out-Of-Bounds (OOB) writes.
> --
I think this pre-existing issue is implicitly fixed by PATCH 2/2, where
max_io_vqs is validated by param_set_uint_minmax(val, kp, 1,
VHOST_SCSI_MAX_IO_VQ) before the value is stored.
Changing the local nvqs variable from int to unsigned int in PATCH 2/2 would
make the type flow clearer, but the issue should no longer be reachable once
both patches are applied.
Dongli Zhang
>
> --- Patch [1]: [PATCH 1/2] vhost-scsi: use kvzalloc for vq array allocation ---
> commit 3573b684f78f79b1ae3460e4a7625cb917f76044
> Author: Dongli Zhang <dongli.zhang@oracle.com>
>
> vhost-scsi: use kvzalloc for vq array allocation
>
> vhost_scsi_open() allocates one struct vhost_scsi_virtqueue for each
> virtqueue. With large max_io_vqs values, this array can require a
> high-order contiguous allocation and trigger a page allocator warning.
> This patch replaces kmalloc_objs with kvzalloc_objs to avoid the
> warning.
>
>> diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
>> index 9a1253b9d8c50..0c0634eea1443 100644
>> --- a/drivers/vhost/scsi.c
>> +++ b/drivers/vhost/scsi.c
>> @@ -2295,7 +2295,7 @@ static int vhost_scsi_open(struct inode *inode, struct file *f)
>> if (!vs->old_inflight)
>> goto err_inflight;
>>
>> - vs->vqs = kmalloc_objs(*vs->vqs, nvqs, GFP_KERNEL | __GFP_ZERO);
>> + vs->vqs = kvzalloc_objs(*vs->vqs, nvqs);
>
> [Severity: High]
> This is a pre-existing issue, but could this allocation be undersized due to
> an integer overflow in the nvqs calculation?
>
> If a privileged user sets the max_io_vqs module parameter to a value that
> overflows the signed integer nvqs (e.g., 4294967295), nvqs could become
> negative (e.g., -1). Because it is signed, this bypasses the maximum bounds
> check against VHOST_SCSI_MAX_IO_VQ.
>
> When VHOST_SCSI_VQ_IO (2) is added, nvqs becomes 1. The allocation is then
> sized for exactly 1 element:
>
> vs->vqs = kvzalloc_objs(*vs->vqs, nvqs);
>
> However, the code later unconditionally writes to index 1 (VHOST_SCSI_VQ_EVT),
> which would cause a heap out-of-bounds write:
>
> vqs[VHOST_SCSI_VQ_EVT] = &vs->vqs[VHOST_SCSI_VQ_EVT].vq;
>
> Would it be safer to use an unsigned type for nvqs and related variables to
> prevent this bounds check bypass?
>
next prev parent reply other threads:[~2026-07-31 23:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 22:10 [PATCH 0/2] vhost-scsi: fix max_io_vqs handling Dongli Zhang
2026-07-31 22:10 ` [PATCH 1/2] vhost-scsi: use kvzalloc for vq array allocation Dongli Zhang
[not found] ` <20260731222400.8AC7D1F00AC4@smtp.kernel.org>
2026-07-31 23:23 ` Dongli Zhang [this message]
2026-07-31 22:10 ` [PATCH 2/2] vhost-scsi: reject invalid max_io_vqs module parameter Dongli Zhang
[not found] ` <20260731222633.15DE01F00AC4@smtp.kernel.org>
2026-07-31 23:31 ` Dongli Zhang
2026-08-01 0:00 ` Michael S. Tsirkin
2026-08-01 6:59 ` Dongli Zhang
2026-08-01 9:55 ` Michael S. Tsirkin
2026-08-02 6:53 ` Dongli Zhang
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=ba095baf-8837-4295-868b-891fa812f4a2@oracle.com \
--to=dongli.zhang@oracle.com \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=virtualization@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