hw/cxl: Check input includes at least the header in cmd_features_set_feature()
authorJonathan Cameron <Jonathan.Cameron@huawei.com>
Fri, 1 Nov 2024 13:39:09 +0000 (13:39 +0000)
committerMichael S. Tsirkin <mst@redhat.com>
Mon, 4 Nov 2024 21:03:25 +0000 (16:03 -0500)
A buggy guest might write an insufficiently large message.
Check the header is present. Whilst zero data after the header is very
odd it will just result in failure to copy any data.

Reported-by: Esifiel <esifiel@gmail.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Message-Id: <20241101133917.27634-3-Jonathan.Cameron@huawei.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
hw/cxl/cxl-mailbox-utils.c

index 17924410dde7a2f6de0e8c6930e371bbc066ff77..e63140aefe70e3e9071e12c390599a553fcd9095 100644 (file)
@@ -1238,6 +1238,9 @@ static CXLRetCode cmd_features_set_feature(const struct cxl_cmd *cmd,
     CXLType3Dev *ct3d;
     uint16_t count;
 
+    if (len_in < sizeof(*hdr)) {
+        return CXL_MBOX_INVALID_PAYLOAD_LENGTH;
+    }
 
     if (!object_dynamic_cast(OBJECT(cci->d), TYPE_CXL_TYPE3)) {
         return CXL_MBOX_UNSUPPORTED;