[PATCH v24 15/16] ALSA: virtio: reject invalid playback completions

From: Joonho Lee

Date: Tue Nov 10 2026 - 19:14:22 EST


A TX completion currently advances the hardware position even when the
used length is malformed or the device reports an error. Validate the
fixed status response before publishing progress. Retire the request
once, latch XRUN and schedule error delivery while preparation is
active. Keep malformed or failed transfers out of successful playback
byte accounting.

Assisted-by: LLM
Signed-off-by: Joonho Lee <mynameisjune111@xxxxxxxxx>

---
sound/virtio/virtio_pcm_msg.c | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/sound/virtio/virtio_pcm_msg.c b/sound/virtio/virtio_pcm_msg.c
--- a/sound/virtio/virtio_pcm_msg.c
+++ b/sound/virtio/virtio_pcm_msg.c
@@ -980,6 +980,17 @@

/* Playback requests point directly at the ALSA ring. */
guard(spinlock)(&vss->lock);
+ if (written_bytes != sizeof(*msg->status) ||
+ le32_to_cpu(msg->status->status) != VIRTIO_SND_S_OK) {
+ vss->xfer_xrun = true;
+ msg->length = 0;
+ vss->msg_count--;
+ if (!vss->msg_count)
+ wake_up_all(&vss->msg_empty);
+ if (vss->prepared && !vss->preparing)
+ virtsnd_pcm_schedule_period_elapsed(vss);
+ return;
+ }
completed_bytes = msg->length;
latency_bytes = le32_to_cpu(msg->status->latency_bytes);
vss->hw_ptr += completed_bytes;