From 056e4a31834cb9e13f099f17131fe4451b714972 Mon Sep 17 00:00:00 2001 From: Tomasz Leman Date: Thu, 3 Dec 2026 11:09:10 +0000 Subject: [PATCH] ipc4: handler-user: check TLV header fits before reading it ipc4_set_vendor_config_module_instance() reads tlv->length to reject zero-length TLVs before checking that a whole struct sof_tlv is left in the payload. With data_off_size = MAILBOX_HOSTBOX_SIZE and TLVs chained so the last header starts 4 bytes before the end, the length read lands just past the hostbox. Found by the IPC4 fuzzer (ASan): global-buffer-overflow READ of size 4 right after posix_hostbox. Move the header size check ahead of the first header field access. Signed-off-by: Tomasz Leman --- src/ipc/ipc4/handler-user.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/ipc/ipc4/handler-user.c b/src/ipc/ipc4/handler-user.c index 5e210bcf246b..c6e40582b244 100644 --- a/src/ipc/ipc4/handler-user.c +++ b/src/ipc/ipc4/handler-user.c @@ -1005,17 +1005,22 @@ __cold int ipc4_set_vendor_config_module_instance(struct comp_dev *dev, while ((const uint8_t *)tlv < end_offset) { size_t remaining = (size_t)(end_offset - (const uint8_t *)tlv); + /* the TLV header must fit in the payload before any of + * its fields are read, else the header read itself runs + * past the end of the hostbox + */ + if (remaining < sizeof(struct sof_tlv)) + return IPC4_INVALID_REQUEST; + /* check for invalid length */ if (!tlv->length) return IPC4_INVALID_CONFIG_DATA_LEN; - /* Validate TLV header + value fits within remaining - * payload to prevent OOB access and pointer wraparound - * on 32-bit arithmetic (CWE-190). Split into two checks - * to avoid overflow in the size_t addition itself. + /* Validate the value fits within the remaining payload + * to prevent OOB access and pointer wraparound on + * 32-bit arithmetic (CWE-190). */ - if (remaining < sizeof(struct sof_tlv) || - tlv->length > remaining - sizeof(struct sof_tlv)) + if (tlv->length > remaining - sizeof(struct sof_tlv)) return IPC4_INVALID_REQUEST; ret = drv->ops.set_large_config(dev, tlv->type, init_block,