Re: Re: [PATCH 1/2] cxl/mbox: clamp the event record count to the received payload
From: 黄高彬
Date: Thu Sep 17 2026 - 07:14:44 EST
> If I follow the above correctly this hardening against a buggy device?
> If that's the case drop the fixes tag. I'm happy to see this sort
> of change go as long as we make it clear what it is.
You have followed it correctly: this is hardening against a device that does
not honour the protocol, not a fix for a regression. An honest device never
reports more records than it returned.
Having gone looking, I am dropping this patch rather than posting it again.
Anisa Su fixed the same bug in the same function on 2026-08-31:
[PATCH v2 2/4] cxl/events: Validate the record count reported by the device
https://lore.kernel.org/linux-cxl/20260901002912.958-3-anisa.su@xxxxxxxxxxx/
Same expression for the bound (struct_size() against mbox_cmd.size_out), same
Fixes: commit (6ebe28f9ec72), and hers is the better of the two: it fails the
command instead of clamping, which also bounds the per-log loop. Clamping
leaves nr_rec non-zero, so `} while (nr_rec);` keeps issuing Get and Clear
Event Records to a device that never clears them -- a hang, which is worse than
the read being fixed. Hers also comes with a pass bound for that loop, which
this one did not. So this is a duplicate and I withdraw it.
Sorry for the noise.
> Feels a bit like there should be a function to reverse struct_size() but sadly not.
> We do have struct_offset() however so given we are using this access into
> payloads, I think we can write this as:
>
> max_rec = (mbox_cmd.size_out - struct_offset(payload, records) /
> sizeof(*payload->records);
Thank you -- it is applied to the Get Supported Logs patch, which is not part
of her series and continues as
[PATCH v2] cxl/mbox: bound the Get Supported Logs entry count by the payload
https://lore.kernel.org/all/20260917104603.2658529-1-huanggaobin23@xxxxxxxxxx/
One reading note in case it was a sketch rather than a paste: as written the
parenthesis closes after sizeof(*payload->records), so the division would bind
to struct_offset() alone, and the paren opened before mbox_cmd.size_out is
never closed. I grouped the subtraction. No new include is needed:
struct_size() a few lines above comes from the same linux/overflow.h.
Gaobin