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,