Skip to contentSkip to conversation

ati-vga: check address before reading configuration bytes (CVE-2020-13791)

PATCH In review P J P 5 participants 7 messages Jun 4, 2020 – Jul 2, 2020

lore
Share & tools
lore

P J P

author
#0 lore raw

PATCH v3 1/1 ati-vga: check address before reading configuration bytes (CVE-2020-13791)

From: Prasad J Pandit <[email protected]>

While reading PCI configuration bytes, a guest may send an address towards the end of the configuration space. It may lead to an OOB access issue. Add check to ensure 'address + size' is within PCI configuration space.

---
 hw/display/ati.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Update v3: avoid modifying 'addr' variable
-> https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg00834.html

hw/display/ati.c +3 -1
index 67604e68de..b4d0fd88b7 100644
@@ -387,7 +387,9 @@ static uint64_t ati_mm_read(void *opaque, hwaddr addr, unsigned int size)
         val = s->regs.crtc_pitch;
         break;
     case 0xf00 ... 0xfff:
-        val = pci_default_read_config(&s->dev, addr - 0xf00, size);
+        if ((addr - 0xf00) + size <= pci_config_size(&s->dev)) {
+            val = pci_default_read_config(&s->dev, addr - 0xf00, size);
+        }
         break;
     case CUR_OFFSET:
         val = s->regs.cur_offset;
Signature · 1 line
2.26.2
#1 lore raw
Quoted 7 lines · P J P

From: Prasad J Pandit <[email protected]>

While reading PCI configuration bytes, a guest may send an address towards the end of the configuration space. It may lead to an OOB access issue. Add check to ensure 'address + size' is within PCI configuration space.

Quoted 5 lines

BTW, this only happens on unaligned accesses.
And the IO memory region in question does not set valid.unaligned or .impl.unaligned.

And the documentation says:

- .valid.unaligned specifies that the *device being modelled* supports unaligned accesses; if false, unaligned accesses will invoke the appropriate bus or CPU specific behaviour.

and

- .impl.unaligned specifies that the *implementation* supports unaligned accesses; if false, unaligned accesses will be emulated by two aligned accesses.

Is this then another case of a memory core bug which should have either failed the access or split it?

Quoted 24 lines
---
 hw/display/ati.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Update v3: avoid modifying 'addr' variable
-> https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg00834.html

hw/display/ati.c +3 -1
index 67604e68de..b4d0fd88b7 100644
@@ -387,7 +387,9 @@ static uint64_t ati_mm_read(void *opaque, hwaddr addr, unsigned int size)
         val = s->regs.crtc_pitch;
         break;
     case 0xf00 ... 0xfff:
-        val = pci_default_read_config(&s->dev, addr - 0xf00, size);
+        if ((addr - 0xf00) + size <= pci_config_size(&s->dev)) {
+            val = pci_default_read_config(&s->dev, addr - 0xf00, size);
+        }
         break;
     case CUR_OFFSET:
         val = s->regs.cur_offset;
Signature · 1 line
2.26.2
#2 lore raw
Quoted 24 lines · Michael S. Tsirkin
Quoted 7 lines · P J P

From: Prasad J Pandit <[email protected]>

While reading PCI configuration bytes, a guest may send an address towards the end of the configuration space. It may lead to an OOB access issue. Add check to ensure 'address + size' is within PCI configuration space.

Quoted 5 lines

BTW, this only happens on unaligned accesses.
And the IO memory region in question does not set valid.unaligned or .impl.unaligned.

And the documentation says:

- .valid.unaligned specifies that the *device being modelled* supports unaligned accesses; if false, unaligned accesses will invoke the appropriate bus or CPU specific behaviour.

Quoted 8 lines

and

- .impl.unaligned specifies that the *implementation* supports unaligned accesses; if false, unaligned accesses will be emulated by two aligned accesses.

Is this then another case of a memory core bug which should have either failed the access or split it?

Related:
https://www.mail-archive.com/[email protected]/msg695362.html
earlier comment:
https://www.mail-archive.com/[email protected]/msg694805.html

Quoted 26 lines
Quoted 25 lines
---
 hw/display/ati.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Update v3: avoid modifying 'addr' variable
-> https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg00834.html

hw/display/ati.c +3 -1
index 67604e68de..b4d0fd88b7 100644
@@ -387,7 +387,9 @@ static uint64_t ati_mm_read(void *opaque, hwaddr addr, unsigned int size)
         val = s->regs.crtc_pitch;
         break;
     case 0xf00 ... 0xfff:
-        val = pci_default_read_config(&s->dev, addr - 0xf00, size);
+        if ((addr - 0xf00) + size <= pci_config_size(&s->dev)) {
+            val = pci_default_read_config(&s->dev, addr - 0xf00, size);
+        }
         break;
     case CUR_OFFSET:
         val = s->regs.cur_offset;
Signature · 1 line
2.26.2
#3 lore raw
Quoted 31 lines · Philippe Mathieu-Daudé
Quoted 30 lines · Michael S. Tsirkin
Quoted 7 lines · P J P

From: Prasad J Pandit <[email protected]>

While reading PCI configuration bytes, a guest may send an address towards the end of the configuration space. It may lead to an OOB access issue. Add check to ensure 'address + size' is within PCI configuration space.

Quoted 5 lines

BTW, this only happens on unaligned accesses.
And the IO memory region in question does not set valid.unaligned or .impl.unaligned.

And the documentation says:

- .valid.unaligned specifies that the *device being modelled* supports unaligned accesses; if false, unaligned accesses will invoke the appropriate bus or CPU specific behaviour.

and

- .impl.unaligned specifies that the *implementation* supports unaligned accesses; if false, unaligned accesses will be emulated by two aligned accesses.

Quoted 7 lines
Quoted 2 lines

Is this then another case of a memory core bug which should have either failed the access or split it?

Related:
https://www.mail-archive.com/[email protected]/msg695362.html
earlier comment:
https://www.mail-archive.com/[email protected]/msg694805.html

Yea looks like more devices following documentation and memory core doing something else instead.

Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
---
 hw/display/ati.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Update v3: avoid modifying 'addr' variable
-> https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg00834.html

hw/display/ati.c +3 -1
index 67604e68de..b4d0fd88b7 100644
@@ -387,7 +387,9 @@ static uint64_t ati_mm_read(void *opaque, hwaddr addr, unsigned int size)
         val = s->regs.crtc_pitch;
         break;
     case 0xf00 ... 0xfff:
-        val = pci_default_read_config(&s->dev, addr - 0xf00, size);
+        if ((addr - 0xf00) + size <= pci_config_size(&s->dev)) {
+            val = pci_default_read_config(&s->dev, addr - 0xf00, size);
+        }
         break;
     case CUR_OFFSET:
         val = s->regs.cur_offset;
Signature · 1 line
2.26.2
#4 lore raw

[Please excuse me for top-posting, I want to preserve somewhat old context]

So, is this CVE-2020-13791 issue fixed by the fix for CVE-2020-13754, by this commit:
https://git.qemu.org/?p=qemu.git;a=commit;h=5d971f9e672507210e77d020d89e0e89165c8fc9

?

Thanks,

/mjt

Quoted 71 lines · Michael S. Tsirkin
Quoted 31 lines · Philippe Mathieu-Daudé
Quoted 30 lines · Michael S. Tsirkin
Quoted 7 lines · P J P

From: Prasad J Pandit <[email protected]>

While reading PCI configuration bytes, a guest may send an address towards the end of the configuration space. It may lead to an OOB access issue. Add check to ensure 'address + size' is within PCI configuration space.

Quoted 5 lines

BTW, this only happens on unaligned accesses.
And the IO memory region in question does not set valid.unaligned or .impl.unaligned.

And the documentation says:

- .valid.unaligned specifies that the *device being modelled* supports unaligned accesses; if false, unaligned accesses will invoke the appropriate bus or CPU specific behaviour.

and

- .impl.unaligned specifies that the *implementation* supports unaligned accesses; if false, unaligned accesses will be emulated by two aligned accesses.

Quoted 7 lines
Quoted 2 lines

Is this then another case of a memory core bug which should have either failed the access or split it?

Related:
https://www.mail-archive.com/[email protected]/msg695362.html
earlier comment:
https://www.mail-archive.com/[email protected]/msg694805.html

Yea looks like more devices following documentation and memory core doing something else instead.

Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
---
 hw/display/ati.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Update v3: avoid modifying 'addr' variable
-> https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg00834.html

hw/display/ati.c +3 -1
index 67604e68de..b4d0fd88b7 100644
@@ -387,7 +387,9 @@ static uint64_t ati_mm_read(void *opaque, hwaddr addr, unsigned int size)
         val = s->regs.crtc_pitch;
         break;
     case 0xf00 ... 0xfff:
-        val = pci_default_read_config(&s->dev, addr - 0xf00, size);
+        if ((addr - 0xf00) + size <= pci_config_size(&s->dev)) {
+            val = pci_default_read_config(&s->dev, addr - 0xf00, size);
+        }
         break;
     case CUR_OFFSET:
         val = s->regs.cur_offset;
Signature · 1 line
2.26.2
#6 lore raw
In reply to Michael S. Tsirkin
Quoted 24 lines · Michael S. Tsirkin
Quoted 7 lines · P J P

From: Prasad J Pandit <[email protected]>

While reading PCI configuration bytes, a guest may send an address towards the end of the configuration space. It may lead to an OOB access issue. Add check to ensure 'address + size' is within PCI configuration space.

Quoted 5 lines

BTW, this only happens on unaligned accesses.
And the IO memory region in question does not set valid.unaligned or .impl.unaligned.

And the documentation says:

- .valid.unaligned specifies that the *device being modelled* supports unaligned accesses; if false, unaligned accesses will invoke the appropriate bus or CPU specific behaviour.

Quoted 8 lines

and

- .impl.unaligned specifies that the *implementation* supports unaligned accesses; if false, unaligned accesses will be emulated by two aligned accesses.

Is this then another case of a memory core bug which should have either failed the access or split it?

In this case the path should be

address_space_stl_le
address_space_stl_internal
memory_region_dispatch_write
memory_region_access_valid

and then it does check valid.unaligned. Is there a testcase?

Paolo

Quoted 26 lines
Quoted 25 lines
---
 hw/display/ati.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Update v3: avoid modifying 'addr' variable
-> https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg00834.html

hw/display/ati.c +3 -1
index 67604e68de..b4d0fd88b7 100644
@@ -387,7 +387,9 @@ static uint64_t ati_mm_read(void *opaque, hwaddr addr, unsigned int size)
         val = s->regs.crtc_pitch;
         break;
     case 0xf00 ... 0xfff:
-        val = pci_default_read_config(&s->dev, addr - 0xf00, size);
+        if ((addr - 0xf00) + size <= pci_config_size(&s->dev)) {
+            val = pci_default_read_config(&s->dev, addr - 0xf00, size);
+        }
         break;
     case CUR_OFFSET:
         val = s->regs.cur_offset;
Signature · 1 line
2.26.2