[PATCH 0/2] cxl/mbox: bound device supplied counts by the received payload
From: Gaobin Huang
Date: Mon Sep 14 2026 - 10:58:55 EST
The CXL mailbox layer uses counts the device writes inside a response to
index flexible arrays in that same response, without ever comparing them
against the number of bytes the device actually delivered. Two of those
walks can leave the buffer:
Patch 1 Get Event Records. record_count bounds the walk over
records[], in cxl_mem_get_records_log() and again in
cxl_clear_event_record().
Patch 2 Get Supported Logs. entries bounds the walk over entry[],
during command enumeration, on every probe.
The number to compare against is already in hand:
__cxl_pci_mbox_send_cmd() stores how many bytes it copied into the driver
buffer in mbox_cmd.size_out. Both paths derive their bound from it, so
this adds no new trust in the device, it just uses what the driver already
knows.
It matters because the count is read from the same response whose length
the device also reports: a device that reports success and a full length
while writing less leaves the kernel reading the rest of its mailbox
buffer as the count. Firmware that takes an error path can do that
without any malice, and patch 2 runs at probe time, so no host action is
involved.
The cross-check is not new to this driver. get_supported_features() in
drivers/cxl/core/features.c already compares the device supplied count
against the retrieved length before touching the entries.
Both were found by fuzzing a QEMU Type-3 device that lies in those two
responses, with a KASAN guest kernel; the reports are in the patches.
Gaobin Huang (2):
cxl/mbox: clamp the event record count to the received payload
cxl/mbox: bound the Get Supported Logs entry count by the payload
drivers/cxl/core/mbox.c | 54 +++++++++++++++++++++++++++++++++++------
1 file changed, 46 insertions(+), 8 deletions(-)
base-commit: 999811aca000b0d3d1c838c60dc9db7c72eb0c73
--
2.34.1