hw/sd/sd: validate migrated blk_len in post_load
PATCH 1/1 hw/sd/sd: validate migrated blk_len in post_load
Migration streams are untrusted input. A crafted stream can set blk_len larger than the 512 byte data[] buffer, so a later block read passes that length to blk_pread() and overflows data[] on the host heap.
Reject such state in post_load.
Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4725
Reported-by Karl Mehltretter
Signed-off-by Harshit Mukhedkar <[email protected]>
--- hw/sd/sd.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
hw/sd/sd.c +13 -0
@@ -1073,11 +1073,24 @@ static int sd_vmstate_pre_load(void *opaque)return 0 ; } +static int sd_vmstate_post_load (void *opaque,int version_id) +{ +SDState *sd = opaque; + +/* Check for blk_len that overflows data[] */ +if (sd->blk_len >sizeof (sd->data)) { +return -EINVAL ; + } + +return 0 ; +} +static const VMStateDescription sd_vmstate = { .name ="sd-card" , .version_id =2 , .minimum_version_id =2 , .pre_load = sd_vmstate_pre_load, + .post_load = sd_vmstate_post_load, .fields = (const VMStateField []) {VMSTATE_UNUSED (4 ),VMSTATE_INT32 (state, SDState),
Signature · 1 line
2.56.0
Quoted 8 lines · Harshit Mukhedkar
Migration streams are untrusted input. A crafted stream can set
blk_lenlarger than the 512 byte data[] buffer, so a later block read passes that length toblk_pread()and overflows data[] on the host heap.Reject such state in
post_load.
Quoted 7 lines
Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4725Reported-by Karl MehltretterSigned-off-by Harshit Mukhedkar <[email protected]>--- hw/sd/sd.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
Reviewed-by Peter Maydell <[email protected]>
thanks
-- PMM