[PATCH v33 15/18] ALSA: virtio: reject invalid playback completions

From: Joonho Lee via B4 Relay

Date: Fri Nov 13 2026 - 05:11:39 EST


From: Joonho Lee <mynameisjune111@xxxxxxxxx>

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
index 3dfc45d90f08..9c67a8bf15f5 100644
--- a/sound/virtio/virtio_pcm_msg.c
+++ b/sound/virtio/virtio_pcm_msg.c
@@ -1011,6 +1011,17 @@ static void virtsnd_pcm_msg_complete(struct virtio_pcm_msg *msg,

/* 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;

--
Git-157)