uas: add stream number sanity checks (maybe 6.1)
cover uas: add stream number sanity checks (maybe 6.1)
Security fix. Sorry for the last-minute patch, I had completely forgotten this one until the CVE number for it arrived today.
Given that the classic usb storage device is way more popular than the uas (usb attached scsi) device the impact should be pretty low and we might consider to not screw up our release schedule for this.
take care,
Gerd
Gerd Hoffmann (1):
uas: add stream number sanity checks.
hw/usb/dev-uas.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
Signature · 1 line
2.31.1
PATCH 1/1 uas: add stream number sanity checks.
The device uses the guest-supplied stream number unchecked, which can lead to guest-triggered out-of-band access to the UASDevice->data3 and UASDevice->status3 fields. Add the missing checks.
--- hw/usb/dev-uas.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
hw/usb/dev-uas.c +11 -0
@@ -840,6 +840,9 @@ static void usb_uas_handle_data(USBDevice *dev, USBPacket *p) }break ;case UAS_PIPE_ID_STATUS : +if (p->stream >UAS_MAX_STREAMS ) { + goto err_stream; + }if (p->stream) { QTAILQ_FOREACH(st, &uas->results, next) {if (st->stream == p->stream) {
@@ -867,6 +870,9 @@ static void usb_uas_handle_data(USBDevice *dev, USBPacket *p)break ;case UAS_PIPE_ID_DATA_IN :case UAS_PIPE_ID_DATA_OUT : +if (p->stream >UAS_MAX_STREAMS ) { + goto err_stream; + }if (p->stream) { req =usb_uas_find_request (uas, p->stream); }else {
@@ -902,6 +908,11 @@ static void usb_uas_handle_data(USBDevice *dev, USBPacket *p) p->status =USB_RET_STALL ;break ; } + +err_stream: +error_report ("%s: invalid stream %d" , __func__, p->stream); + p->status =USB_RET_STALL ; +return ; }static void usb_uas_unrealize (USBDevice *dev)
Signature · 1 line
2.31.1
Re: [PATCH 1/1] uas: add stream number sanity checks.
Quoted 5 lines · Gerd Hoffmann
The device uses the guest-supplied stream number unchecked, which can lead to guest-triggered out-of-band access to the
UASDevice->data3andUASDevice->status3fields. Add the missing checks.Fixes CVE-2021-3713
Quoted 30 lines
Signed-off-by Gerd Hoffmann <[email protected]>--- hw/usb/dev-uas.c | 11 +++++++++++ 1 file changed, 11 insertions(+)hw/usb/dev-uas.c +6
-0@@ -840,6 +840,9 @@ static void usb_uas_handle_data(USBDevice *dev, USBPacket *p) }break ;case UAS_PIPE_ID_STATUS : +if (p->stream >UAS_MAX_STREAMS ) { + goto err_stream; + }if (p->stream) { QTAILQ_FOREACH(st, &uas->results, next) {if (st->stream == p->stream) {@@ -867,6 +870,9 @@ static void usb_uas_handle_data(USBDevice *dev, USBPacket *p)break ;case UAS_PIPE_ID_DATA_IN :case UAS_PIPE_ID_DATA_OUT : +if (p->stream >UAS_MAX_STREAMS ) { + goto err_stream; + }if (p->stream) { req =usb_uas_find_request (uas, p->stream); }else {
hw/usb/dev-uas.c static void usb_uas_handle_data(USBDevice *dev, USBPacket *p) · line 916
Quoted 9 lines
hw/usb/dev-uas.c +5
-0@@ -902,6 +908,11 @@ static void usb_uas_handle_data(USBDevice *dev, USBPacket *p) p->status =USB_RET_STALL ;break ; } + +err_stream: +error_report ("%s: invalid stream %d" , __func__, p->stream); + p->status =USB_RET_STALL ; +return ; }
Thanks for tackling this, I was looking but thought it was too late for 6.1. Beside your obvious checks, I'd also modify usb_uas_alloc_status() to feel safer, by checking 'tag'. Eventually returning NULL and adapt the call sites? Anyway this can wait 6.2, so for this patch:
Re: [PATCH 1/1] uas: add stream number sanity checks.
In reply to Gerd HoffmannQuoted 38 lines · Gerd Hoffmann
The device uses the guest-supplied stream number unchecked, which can lead to guest-triggered out-of-band access to the
UASDevice->data3andUASDevice->status3fields. Add the missing checks.Fixes CVE-2021-3713Signed-off-by Gerd Hoffmann <[email protected]>Reported-by Chen Zhe <[email protected]>Reported-by Tan Jingguo <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>--- hw/usb/dev-uas.c | 11 +++++++++++ 1 file changed, 11 insertions(+)hw/usb/dev-uas.c +6
-0@@ -840,6 +840,9 @@ static void usb_uas_handle_data(USBDevice *dev, USBPacket *p) }break ;case UAS_PIPE_ID_STATUS : +if (p->stream >UAS_MAX_STREAMS ) { + goto err_stream; + }if (p->stream) { QTAILQ_FOREACH(st, &uas->results, next) {if (st->stream == p->stream) {@@ -867,6 +870,9 @@ static void usb_uas_handle_data(USBDevice *dev, USBPacket *p)break ;case UAS_PIPE_ID_DATA_IN :case UAS_PIPE_ID_DATA_OUT : +if (p->stream >UAS_MAX_STREAMS ) { + goto err_stream; + }if (p->stream) { req =usb_uas_find_request (uas, p->stream); }else {
hw/usb/dev-uas.c static void usb_uas_handle_data(USBDevice *dev, USBPacket *p) · line 915
Quoted 8 lines
hw/usb/dev-uas.c +5
-0@@ -902,6 +908,11 @@ static void usb_uas_handle_data(USBDevice *dev, USBPacket *p) p->status =USB_RET_STALL ;break ; } + +err_stream: +error_report ("%s: invalid stream %d" , __func__, p->stream); + p->status =USB_RET_STALL ; +return ;
How is this supposed to work ? It results in messages such as the following.
qemu-system-sparc64: usb_uas_handle_data: invalid stream 1
qemu-system-sparc64: usb_uas_handle_data: invalid stream 1
It also sets the status unconditionally to USB_RET_STALL, and UAS is simply broken after this patch is applied because the error handling code is executed literally for each call of usb_uas_handle_data().
Guenter
Quoted 6 lines · Gerd Hoffmann
Security fix. Sorry for the last-minute patch, I had completely forgotten this one until the CVE number for it arrived today.
Given that the classic usb storage device is way more popular than the uas (usb attached scsi) device the impact should be pretty low and we might consider to not screw up our release schedule for this.
So 6.1-rc5 or stable?
Quoted 7 lines · Gerd Hoffmann
Security fix. Sorry for the last-minute patch, I had completely forgotten this one until the CVE number for it arrived today.
Given that the classic usb storage device is way more popular than the uas (usb attached scsi) device the impact should be pretty low and we might consider to not screw up our release schedule for this.
What's the impact if the bug is exploited ?
-- PMM
Cc'ing Mauro to double-check.
Quoted 10 lines · Peter Maydell
Quoted 7 lines · Gerd Hoffmann
Security fix. Sorry for the last-minute patch, I had completely forgotten this one until the CVE number for it arrived today.
Given that the classic usb storage device is way more popular than the uas (usb attached scsi) device the impact should be pretty low and we might consider to not screw up our release schedule for this.
What's the impact if the bug is exploited ?
Bug class: "guest-triggered user-after-free".
Being privileged (root) in the guest, you can leak some data from the host process then DoS the host or potentially exploit the use-after-free to execute code on the host.
Hi,
Quoted 13 lines · Philippe Mathieu-Daudé
Cc'ing Mauro to double-check.
Quoted 9 lines · Peter Maydell
Quoted 7 lines · Gerd Hoffmann
Security fix. Sorry for the last-minute patch, I had completely forgotten this one until the CVE number for it arrived today.
Given that the classic usb storage device is way more popular than the uas (usb attached scsi) device the impact should be pretty low and we might consider to not screw up our release schedule for this.
Quoted 8 lines
Quoted 1 line
What's the impact if the bug is exploited ?
Bug class: "guest-triggered user-after-free".
Being privileged (root) in the guest, you can leak some data from the host process then DoS the host or potentially exploit the use-after-free to execute code on the host.
This is actually an out-of-bounds access issue (not UAF). It's still potentially bad, but I agree with Gerd the impact is low. Plus there's an assert right before [1] that makes it a DoS if the accessed memory is not NULL.
[1] https://gitlab.com/qemu-project/qemu/-/blob/master/hw/usb/dev-uas.c#L850
Regards.
--
Mauro Matteo Cascella
Red Hat Product Security
PGP-Key ID: BB3410B0
Quoted 27 lines · Mauro Matteo Cascella
Hi,
Quoted 13 lines · Philippe Mathieu-Daudé
Cc'ing Mauro to double-check.
Quoted 9 lines · Peter Maydell
Quoted 7 lines · Gerd Hoffmann
Security fix. Sorry for the last-minute patch, I had completely forgotten this one until the CVE number for it arrived today.
Given that the classic usb storage device is way more popular than the uas (usb attached scsi) device the impact should be pretty low and we might consider to not screw up our release schedule for this.
Quoted 8 lines
Quoted 1 line
What's the impact if the bug is exploited ?
Bug class: "guest-triggered user-after-free".
Being privileged (root) in the guest, you can leak some data from the host process then DoS the host or potentially exploit the use-after-free to execute code on the host.
Quoted 4 lines
This is actually an out-of-bounds access issue (not UAF). It's still potentially bad, but I agree with Gerd the impact is low. Plus there's an assert right before [1] that makes it a DoS if the accessed memory is not NULL.
Thanks. OK, (and following discussion of this on irc on Friday) we won't put this fix into 6.1. (That is, we treat it the same way we would if the CVE patch had arrived the day after we tagged 6.1, ie distros and other interested parties pick up the patch as they would any other security fix.)
-- PMM