Hi Bin,

On 16/9/26 11:23, Bin Guo wrote:
The U2F key pending_in ring buffer uses uint8_t start/end/num indices
over a 32-entry array, all serialized in the vmstate.  A malicious
migration stream can inject values >= U2FHID_PENDING_IN_NUM (32),
causing an out-of-bounds heap read in u2f_pending_in_get() on the
first USB IN token after migration completes.

Add a post_load callback to validate the restored indices and reset
the ring buffer to empty on any out-of-range value.  Pending packets
are non-critical (the device will regenerate them), so resetting the
ring is preferable to rejecting migration entirely.

As defense-in-depth, also add a bounds clamp in u2f_pending_in_get()
so that even if corrupted state somehow reaches the consumer path,
the index is folded into range before array access.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/4483
Signed-off-by: Bin Guo <[email protected]>
---
  hw/usb/u2f.c | 31 +++++++++++++++++++++++++++++++
  1 file changed, 31 insertions(+)
pending_out_start/end/num in U2FEmulatedState have the same issue,
do you mind fixing in another patch?

Reviewed-by: Philippe Mathieu-Daudé <[email protected]>



Reply via email to