scsi/lsi53c895a: fix use-after-free in lsi_do_msgout (CVE-2022-0216)
PATCH 1/1 scsi/lsi53c895a: fix use-after-free in lsi_do_msgout (CVE-2022-0216)
Set current_req->req to NULL to prevent reusing a free'd buffer in case of repeated SCSI cancel requests. Thanks to Thomas Huth for suggesting the patch.
Fixes: CVE-2022-0216
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/972
--- hw/scsi/lsi53c895a.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/scsi/lsi53c895a.c +2 -1
@@ -1028,8 +1028,9 @@ static void lsi_do_msgout(LSIState *s)case 0x0d :/* The ABORT TAG message clears the current I/O process only. */ trace_lsi_do_msgout_abort (current_tag); -if (current_req) { +if (current_req && current_req->req) {scsi_req_cancel (current_req->req); + current_req->req =NULL ; }lsi_disconnect (s);break ;
Signature · 1 line
2.35.3
Quoted 15 lines · Mauro Matteo Cascella
Set
current_req->reqto NULL to prevent reusing a free'd buffer in case of repeated SCSI cancel requests. Thanks to Thomas Huth for suggesting the patch.Fixes: CVE-2022-0216
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/972Signed-off-by Mauro Matteo Cascella <[email protected]>--- hw/scsi/lsi53c895a.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/scsi/lsi53c895a.c +0
-0
hw/scsi/lsi53c895a.c static void lsi_do_msgout(LSIState *s) · line 1036
Quoted 10 lines
hw/scsi/lsi53c895a.c +2
-1@@ -1028,8 +1028,9 @@ static void lsi_do_msgout(LSIState *s)case 0x0d :/* The ABORT TAG message clears the current I/O process only. */ trace_lsi_do_msgout_abort (current_tag); -if (current_req) { +if (current_req && current_req->req) {scsi_req_cancel (current_req->req); + current_req->req =NULL ; }lsi_disconnect (s);break ;
Let's hope that this will fix the issue for good...
Paolo Bonzini
AppliedQueued, thanks.
Paolo
Quoted 29 lines · Mauro Matteo Cascella
Set
current_req->reqto NULL to prevent reusing a free'd buffer in case of repeated SCSI cancel requests. Thanks to Thomas Huth for suggesting the patch.Fixes: CVE-2022-0216
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/972Signed-off-by Mauro Matteo Cascella <[email protected]>--- hw/scsi/lsi53c895a.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/scsi/lsi53c895a.c +2
-1@@ -1028,8 +1028,9 @@ static void lsi_do_msgout(LSIState *s)case 0x0d :/* The ABORT TAG message clears the current I/O process only. */ trace_lsi_do_msgout_abort (current_tag); -if (current_req) { +if (current_req && current_req->req) {scsi_req_cancel (current_req->req); + current_req->req =NULL ; }lsi_disconnect (s);break ;Signature · 1 line
2.35.3
Hi Mauro,
https://gitlab.com/qemu-project/qemu/-/issues/972#note_1019851430
This reproducer crashes, with this patch applied. Maybe it is some different bug though - I'm not sure.
With -trace lsi*
lsi_reg_write Write reg DSP1 0x2d = 0x00lsi_reg_write Write reg DSP2 0x2e = 0x40lsi_reg_write Write reg DSP3 0x2f = 0x36lsi_execute_script SCRIPTS dsp=0x364001d0 opcode 0x58000008 arg 0x0 lsi_execute_script_io_set Set ATNlsi_execute_script SCRIPTS dsp=0x364001d8 opcode 0x26010000 arg 0x5a41ae0d lsi_do_msgout MSG out len=65536lsi_do_msgout_busdevicereset MSG: BUS DEVICE RESET tag=0x0 lsi_do_msgout_select Select LUN 0lsi_do_msgout_abort MSG: ABORT TAG tag=0x0
In busdevicereset, there are also scsi_req_cancel calls. Do they need similar changes?
-Alex
Hi Alexander,
Thanks for the reproducer! It looks like ABORT, CLEAR QUEUE and BUS DEVICE RESET messages can all cancel the current request, so yes I guess a similar change is needed there, too. Will try to send a v2 soon.
Best regards.
Quoted 50 lines · Alexander Bulekov
Quoted 26 lines · Mauro Matteo Cascella
Set
current_req->reqto NULL to prevent reusing a free'd buffer in case of repeated SCSI cancel requests. Thanks to Thomas Huth for suggesting the patch.Fixes: CVE-2022-0216
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/972Signed-off-by Mauro Matteo Cascella <[email protected]>--- hw/scsi/lsi53c895a.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/scsi/lsi53c895a.c +2
-2@@ -1028,8 +1028,9 @@ static void lsi_do_msgout(LSIState *s)case 0x0d :/* The ABORT TAG message clears the current I/O process only. */ trace_lsi_do_msgout_abort (current_tag); -if (current_req) { +if (current_req && current_req->req) {scsi_req_cancel (current_req->req); + current_req->req =NULL ; }lsi_disconnect (s);break ; --Quoted 3 lines
2.35.3
Hi Mauro,
https://gitlab.com/qemu-project/qemu/-/issues/972#note_1019851430
This reproducer crashes, with this patch applied. Maybe it is some different bug though - I'm not sure.With -trace lsi*
lsi_reg_writeWrite reg DSP10x2d=0x00lsi_reg_writeWrite reg DSP20x2e=0x40lsi_reg_writeWrite reg DSP30x2f=0x36lsi_execute_scriptSCRIPTS dsp=0x364001d0 opcode0x58000008arg0x0lsi_execute_script_io_setSet ATNlsi_execute_scriptSCRIPTS dsp=0x364001d8 opcode0x26010000arg0x5a41ae0dlsi_do_msgoutMSG out len=65536lsi_do_msgout_busdeviceresetMSG: BUS DEVICE RESET tag=0x0lsi_do_msgout_selectSelect LUN 0lsi_do_msgout_abortMSG: ABORT TAG tag=0x0
Quoted 5 lines
In busdevicereset, there are also
scsi_req_cancelcalls. Do they need similar changes?-Alex
--
Mauro Matteo Cascella
Red Hat Product Security
PGP-Key ID: BB3410B0