* [PATCH] vhost-scsi: Prevent OOM from invalid protection SGL count
@ 2026-07-17 14:22 Jia Jia
2026-07-17 15:13 ` Mike Christie
0 siblings, 1 reply; 3+ messages in thread
From: Jia Jia @ 2026-07-17 14:22 UTC (permalink / raw)
To: mst, jasowang, michael.christie
Cc: pbonzini, stefanha, eperezma, virtualization, kvm, netdev,
linux-kernel, stable
The protection SGL path passes the result of vhost_scsi_calc_sgls()
directly to sg_alloc_table_chained(). The helper returns a negative
errno when the iterator is invalid or the request exceeds the segment
limit. The negative errno is then treated as a very large unsigned count
and sends the request into the SGL allocation path with an invalid size.
Repeated malformed T10-PI submissions from a host-side application caused
memory usage to rise sharply. MemAvailable fell to about 200 MB, and PSI
full avg10 reached about 1.46. The OOM killer terminated several userspace
processes before the endpoint cleanup completed. The kernel log included:
[17036.451028] Out of memory: Killed process 2345 (systemd)
[17036.493325] Out of memory: Killed process 2349 (sd-pam)
[17078.265127] Out of memory: Killed process 1793 (networkd-dispat)
Return the calculation error before setting up the protection SGL. This
keeps the protection path consistent with the data SGL path and prevents
the invalid count from entering the allocation path.
Fixes: bca939d5bcd0 ("vhost-scsi: Dynamically allocate scatterlists")
Cc: stable@vger.kernel.org
Signed-off-by: Jia Jia <physicalmtea@gmail.com>
---
drivers/vhost/scsi.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 9a1253b9d..8486652fd 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -972,6 +972,9 @@ vhost_scsi_mapal(struct vhost_scsi *vs, struct vhost_scsi_cmd *cmd,
if (prot_bytes) {
sgl_count = vhost_scsi_calc_sgls(prot_iter, prot_bytes,
VHOST_SCSI_PREALLOC_PROT_SGLS);
+ if (sgl_count < 0)
+ return sgl_count;
+
cmd->prot_table.sgl = cmd->prot_sgl;
ret = sg_alloc_table_chained(&cmd->prot_table, sgl_count,
cmd->prot_table.sgl,
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] vhost-scsi: Prevent OOM from invalid protection SGL count
2026-07-17 14:22 [PATCH] vhost-scsi: Prevent OOM from invalid protection SGL count Jia Jia
@ 2026-07-17 15:13 ` Mike Christie
2026-07-17 16:31 ` Michael S. Tsirkin
0 siblings, 1 reply; 3+ messages in thread
From: Mike Christie @ 2026-07-17 15:13 UTC (permalink / raw)
To: Jia Jia, mst, jasowang, Linfeng Sun
Cc: pbonzini, stefanha, eperezma, virtualization, kvm, netdev,
linux-kernel, stable
cc'ing Linfeng.
Linfeng also reported this bug and provided a patch that has your check
and an extra check to avoid calling into the function in the first
place. It's been stuck in some other list.
I think it might be best for Linfeng to re-submit their patch now so it
can get merged. For that patch, I think there was one outstanding
question left where Michael had asked if the issue was found with AI so
the proper tag could be added. I don't think that question was responded to.
On 7/17/26 9:22 AM, Jia Jia wrote:
> The protection SGL path passes the result of vhost_scsi_calc_sgls()
> directly to sg_alloc_table_chained(). The helper returns a negative
> errno when the iterator is invalid or the request exceeds the segment
> limit. The negative errno is then treated as a very large unsigned count
> and sends the request into the SGL allocation path with an invalid size.
>
> Repeated malformed T10-PI submissions from a host-side application caused
> memory usage to rise sharply. MemAvailable fell to about 200 MB, and PSI
> full avg10 reached about 1.46. The OOM killer terminated several userspace
> processes before the endpoint cleanup completed. The kernel log included:
>
> [17036.451028] Out of memory: Killed process 2345 (systemd)
> [17036.493325] Out of memory: Killed process 2349 (sd-pam)
> [17078.265127] Out of memory: Killed process 1793 (networkd-dispat)
>
> Return the calculation error before setting up the protection SGL. This
> keeps the protection path consistent with the data SGL path and prevents
> the invalid count from entering the allocation path.
>
> Fixes: bca939d5bcd0 ("vhost-scsi: Dynamically allocate scatterlists")
> Cc: stable@vger.kernel.org
> Signed-off-by: Jia Jia <physicalmtea@gmail.com>
> ---
> drivers/vhost/scsi.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
> index 9a1253b9d..8486652fd 100644
> --- a/drivers/vhost/scsi.c
> +++ b/drivers/vhost/scsi.c
> @@ -972,6 +972,9 @@ vhost_scsi_mapal(struct vhost_scsi *vs, struct vhost_scsi_cmd *cmd,
> if (prot_bytes) {
> sgl_count = vhost_scsi_calc_sgls(prot_iter, prot_bytes,
> VHOST_SCSI_PREALLOC_PROT_SGLS);
> + if (sgl_count < 0)
> + return sgl_count;
> +
> cmd->prot_table.sgl = cmd->prot_sgl;
> ret = sg_alloc_table_chained(&cmd->prot_table, sgl_count,
> cmd->prot_table.sgl,
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] vhost-scsi: Prevent OOM from invalid protection SGL count
2026-07-17 15:13 ` Mike Christie
@ 2026-07-17 16:31 ` Michael S. Tsirkin
0 siblings, 0 replies; 3+ messages in thread
From: Michael S. Tsirkin @ 2026-07-17 16:31 UTC (permalink / raw)
To: Mike Christie
Cc: Jia Jia, jasowang, Linfeng Sun, pbonzini, stefanha, eperezma,
virtualization, kvm, netdev, linux-kernel, stable
On Fri, Jul 17, 2026 at 10:13:36AM -0500, Mike Christie wrote:
> cc'ing Linfeng.
>
> Linfeng also reported this bug and provided a patch that has your check and
> an extra check to avoid calling into the function in the first place. It's
> been stuck in some other list.
>
> I think it might be best for Linfeng to re-submit their patch now so it can
> get merged. For that patch, I think there was one outstanding question left
> where Michael had asked if the issue was found with AI so the proper tag
> could be added. I don't think that question was responded to.
Right, was waiting for that.
>
> On 7/17/26 9:22 AM, Jia Jia wrote:
> > The protection SGL path passes the result of vhost_scsi_calc_sgls()
> > directly to sg_alloc_table_chained(). The helper returns a negative
> > errno when the iterator is invalid or the request exceeds the segment
> > limit. The negative errno is then treated as a very large unsigned count
> > and sends the request into the SGL allocation path with an invalid size.
> >
> > Repeated malformed T10-PI submissions from a host-side application caused
> > memory usage to rise sharply. MemAvailable fell to about 200 MB, and PSI
> > full avg10 reached about 1.46. The OOM killer terminated several userspace
> > processes before the endpoint cleanup completed. The kernel log included:
> >
> > [17036.451028] Out of memory: Killed process 2345 (systemd)
> > [17036.493325] Out of memory: Killed process 2349 (sd-pam)
> > [17078.265127] Out of memory: Killed process 1793 (networkd-dispat)
> >
> > Return the calculation error before setting up the protection SGL. This
> > keeps the protection path consistent with the data SGL path and prevents
> > the invalid count from entering the allocation path.
> >
> > Fixes: bca939d5bcd0 ("vhost-scsi: Dynamically allocate scatterlists")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Jia Jia <physicalmtea@gmail.com>
> > ---
> > drivers/vhost/scsi.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
> > index 9a1253b9d..8486652fd 100644
> > --- a/drivers/vhost/scsi.c
> > +++ b/drivers/vhost/scsi.c
> > @@ -972,6 +972,9 @@ vhost_scsi_mapal(struct vhost_scsi *vs, struct vhost_scsi_cmd *cmd,
> > if (prot_bytes) {
> > sgl_count = vhost_scsi_calc_sgls(prot_iter, prot_bytes,
> > VHOST_SCSI_PREALLOC_PROT_SGLS);
> > + if (sgl_count < 0)
> > + return sgl_count;
> > +
> > cmd->prot_table.sgl = cmd->prot_sgl;
> > ret = sg_alloc_table_chained(&cmd->prot_table, sgl_count,
> > cmd->prot_table.sgl,
> > --
> > 2.43.0
> >
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-07-17 16:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-17 14:22 [PATCH] vhost-scsi: Prevent OOM from invalid protection SGL count Jia Jia
2026-07-17 15:13 ` Mike Christie
2026-07-17 16:31 ` Michael S. Tsirkin
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.