From: Jonathan Cameron Date: Fri, 1 Nov 2024 13:39:10 +0000 (+0000) Subject: hw/cxl: Check input length is large enough in cmd_events_clear_records() X-Git-Tag: v9.2.0-rc0~17^2~16 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f4a12ba66bebfe200d7f56015c1cd5af321ab152;p=thirdparty%2Fqemu.git hw/cxl: Check input length is large enough in cmd_events_clear_records() Buggy software might write a message that is too short for either the header, or the header + the event data that is specified in the header. This may result in accesses beyond the range of the message allocated as a duplicate of the incoming message buffer. Reported-by: Esifiel Signed-off-by: Jonathan Cameron Message-Id: <20241101133917.27634-4-Jonathan.Cameron@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c index e63140aefe7..3cb499a24fd 100644 --- a/hw/cxl/cxl-mailbox-utils.c +++ b/hw/cxl/cxl-mailbox-utils.c @@ -266,6 +266,12 @@ static CXLRetCode cmd_events_clear_records(const struct cxl_cmd *cmd, CXLClearEventPayload *pl; pl = (CXLClearEventPayload *)payload_in; + + if (len_in < sizeof(*pl) || + len_in < sizeof(*pl) + sizeof(*pl->handle) * pl->nr_recs) { + return CXL_MBOX_INVALID_PAYLOAD_LENGTH; + } + *len_out = 0; return cxl_event_clear_records(cxlds, pl); }