x86: remaining XSA-492 and -491 follow-on
v3 cover x86: remaining XSA-492 and -491 follow-on
1: x86/domctl: don't imply I/O port permissions from I/O port mapping 2: x86/HVM: more checking for XEN_DOMCTL_ioport_mapping
Jan
PATCH v3 1/2 x86/domctl: don't imply I/O port permissions from I/O port mapping
Rather than granting permissions when mapping (an operation that DM-s are allowed to carry out, while they can't invoke ioport-permission), check whether permissions actually were granted when adding a mapping. This then also allows relaxing the necessary locking.
While no longer granting permissions upon mapping is "only" at risk of breaking guests, no longer revoking permissions upon unmapping strictly requires callers to additionally invoke XEN_DOMCTL_ioport_permission. Or else a security issue would arise. In-tree code already does so.
While there switch to using %pd in the two log messages.
---
libxl has libxl__grant_vga_iomem_permission(), but I can't spot any I/O port equivalent (nor a revoke counterpart, btw). Everywhere else MMIO and I/O ports look to be treated equally.
Qemu uses both xc_domain_{iomem_permission,memory_mapping}() in igd_write_opregion(), but only xc_domain_{memory,ioport}_mapping() in xen_pt_region_update() and xen_pt_{,un}register_vga_regions(). Is the IGD region special in any way? Clearly this can't work from a stubdom.
---
v3: Further extend ChangeLog entry.
v2: Avoid double evaluation of "add". Add ChangeLog entry.
CHANGELOG.md +5 -0
@@ -7,6 +7,11 @@ The format is based on [Keep a Changelog ## [4.23.0 UNRELEASED](https://xenbits.xenproject.org/gitweb/?p=xen.git;a=shortlog;h=staging) - TBD ### Changed + - On x86: + - XEN_DOMCTL_ioport_mapping no longer implicitly grants or revokes + permissions for the port range in question. + XEN_DOMCTL_ioport_permission now needs invoking up front / + afterwards. ### Added
xen/arch/x86/domctl.c +26 -35
81 lines not on this page · raw message
Re: [PATCH v3 1/2] x86/domctl: don't imply I/O port permissions from I/O port mapping
Quoted 10 lines · Jan Beulich
Rather than granting permissions when mapping (an operation that DM-s are allowed to carry out, while they can't invoke ioport-permission), check whether permissions actually were granted when adding a mapping. This then also allows relaxing the necessary locking.
While no longer granting permissions upon mapping is "only" at risk of breaking guests, no longer revoking permissions upon unmapping strictly requires callers to additionally invoke
XEN_DOMCTL_ioport_permission. Or else a security issue would arise. In-tree code already does so.
Quoted 4 lines
While there switch to using %pd in the two log messages.
Fixes 192c4dabc344 ("domctl and p2m changes for PCI passthru")Signed-off-by Jan Beulich <[email protected]>
It's difficult to not think about someone appearing in 3 or 4 years complaining that this change in behavior has caused them a security issue, but I do agree that the previous behavior was inconsistent at best:
However you need to bump XEN_DOMCTL_INTERFACE_VERSION to note the ABI change as we are in 4.23 now.
We possibly need to sort out the questions below, in case there are changes required to either libxl or QEMU.
Quoted 9 lines
---
libxl haslibxl__grant_vga_iomem_permission(), but I can't spot any I/O port equivalent (nor a revoke counterpart, btw). Everywhere else MMIO and I/O ports look to be treated equally.Qemu uses both xc_domain_{iomem_permission,memory_mapping}() in
igd_write_opregion(), but only xc_domain_{memory,ioport}_mapping() inxen_pt_region_update()and xen_pt_{,un}register_vga_regions(). Is the IGD region special in any way? Clearly this can't work from a stubdom.
Those possibly need to be answered by Anthony, but he isn't on Cc?
Thanks, Roger.
Re: [PATCH v3 1/2] x86/domctl: don't imply I/O port permissions from I/O port mapping
Quoted 13 lines · Roger Pau Monné
Quoted 12 lines · Jan Beulich
Rather than granting permissions when mapping (an operation that DM-s are allowed to carry out, while they can't invoke ioport-permission), check whether permissions actually were granted when adding a mapping. This then also allows relaxing the necessary locking.
While no longer granting permissions upon mapping is "only" at risk of breaking guests, no longer revoking permissions upon unmapping strictly requires callers to additionally invoke
XEN_DOMCTL_ioport_permission. Or else a security issue would arise. In-tree code already does so.While there switch to using %pd in the two log messages.
Quoted 7 lines
Quoted 2 lines
Fixes 192c4dabc344 ("domctl and p2m changes for PCI passthru")Signed-off-by Jan Beulich <[email protected]>It's difficult to not think about someone appearing in 3 or 4 years complaining that this change in behavior has caused them a security issue, but I do agree that the previous behavior was inconsistent at best:
A positive aspect here is that the similar change for MMIO went without any fallout, as far as I'm aware.
Quoted 1 line
Acked-by Roger Pau Monné <[email protected]>
Thanks, but ...
Quoted 2 lines
However you need to bump
XEN_DOMCTL_INTERFACE_VERSIONto note the ABI change as we are in 4.23 now.
... there's no interface change here. A bump therefore won't buy us anything. I'm hesitant to take your ack as long as we disagree here.
Quoted 2 lines
We possibly need to sort out the questions below, in case there are changes required to either libxl or QEMU.
Indeed.
Quoted 11 lines
Quoted 9 lines
---
libxl haslibxl__grant_vga_iomem_permission(), but I can't spot any I/O port equivalent (nor a revoke counterpart, btw). Everywhere else MMIO and I/O ports look to be treated equally.Qemu uses both xc_domain_{iomem_permission,memory_mapping}() in
igd_write_opregion(), but only xc_domain_{memory,ioport}_mapping() inxen_pt_region_update()and xen_pt_{,un}register_vga_regions(). Is the IGD region special in any way? Clearly this can't work from a stubdom.Those possibly need to be answered by Anthony, but he isn't on Cc?
Oh, I had him Cc-ed on v2, but forgot to on v3. Anthony, your input is much appreciated.
Jan
Re: [PATCH v3 1/2] x86/domctl: don't imply I/O port permissions from I/O port mapping
Quoted 27 lines · Jan Beulich
Quoted 13 lines · Roger Pau Monné
Quoted 12 lines · Jan Beulich
Rather than granting permissions when mapping (an operation that DM-s are allowed to carry out, while they can't invoke ioport-permission), check whether permissions actually were granted when adding a mapping. This then also allows relaxing the necessary locking.
While no longer granting permissions upon mapping is "only" at risk of breaking guests, no longer revoking permissions upon unmapping strictly requires callers to additionally invoke
XEN_DOMCTL_ioport_permission. Or else a security issue would arise. In-tree code already does so.While there switch to using %pd in the two log messages.
Quoted 7 lines
Quoted 2 lines
Fixes 192c4dabc344 ("domctl and p2m changes for PCI passthru")Signed-off-by Jan Beulich <[email protected]>It's difficult to not think about someone appearing in 3 or 4 years complaining that this change in behavior has caused them a security issue, but I do agree that the previous behavior was inconsistent at best:
A positive aspect here is that the similar change for MMIO went without any fallout, as far as I'm aware.
Quoted 1 line
Acked-by Roger Pau Monné <[email protected]>
Quoted 7 lines
Thanks, but ...
Quoted 2 lines
However you need to bump
XEN_DOMCTL_INTERFACE_VERSIONto note the ABI change as we are in 4.23 now.... there's no interface change here. A bump therefore won't buy us anything. I'm hesitant to take your ack as long as we disagree here.
It's not an interface change, but it's a change in behavior of an existing hypercall in a security-relevant way, so people would generally need to be aware of it, just in case.
Thanks, Roger.
Re: [PATCH v3 1/2] x86/domctl: don't imply I/O port permissions from I/O port mapping
Quoted 33 lines · Roger Pau Monné
Quoted 32 lines · Jan Beulich
Quoted 13 lines · Roger Pau Monné
Quoted 12 lines · Jan Beulich
Rather than granting permissions when mapping (an operation that DM-s are allowed to carry out, while they can't invoke ioport-permission), check whether permissions actually were granted when adding a mapping. This then also allows relaxing the necessary locking.
While no longer granting permissions upon mapping is "only" at risk of breaking guests, no longer revoking permissions upon unmapping strictly requires callers to additionally invoke
XEN_DOMCTL_ioport_permission. Or else a security issue would arise. In-tree code already does so.While there switch to using %pd in the two log messages.
Quoted 7 lines
Quoted 2 lines
Fixes 192c4dabc344 ("domctl and p2m changes for PCI passthru")Signed-off-by Jan Beulich <[email protected]>It's difficult to not think about someone appearing in 3 or 4 years complaining that this change in behavior has caused them a security issue, but I do agree that the previous behavior was inconsistent at best:
A positive aspect here is that the similar change for MMIO went without any fallout, as far as I'm aware.
Quoted 1 line
Acked-by Roger Pau Monné <[email protected]>Thanks, but ...
Quoted 2 lines
However you need to bump
XEN_DOMCTL_INTERFACE_VERSIONto note the ABI change as we are in 4.23 now.
Quoted 6 lines
Quoted 2 lines
... there's no interface change here. A bump therefore won't buy us anything. I'm hesitant to take your ack as long as we disagree here.
It's not an interface change, but it's a change in behavior of an existing hypercall in a security-relevant way, so people would generally need to be aware of it, just in case.
But the interface version bump won't necessarily make anyone aware. Things will continue to build as before, and there's also no binary incompatibility. The best way of making people aware is the ChangeLog entry that iirc you had asked for (and that's now there).
Jan
Re: [PATCH v3 1/2] x86/domctl: don't imply I/O port permissions from I/O port mapping
Quoted 37 lines · Jan Beulich
Quoted 36 lines · Roger Pau Monné
Quoted 34 lines · Jan Beulich
Quoted 13 lines · Roger Pau Monné
Quoted 12 lines · Jan Beulich
Rather than granting permissions when mapping (an operation that DM-s are allowed to carry out, while they can't invoke ioport-permission), check whether permissions actually were granted when adding a mapping. This then also allows relaxing the necessary locking.
While no longer granting permissions upon mapping is "only" at risk of breaking guests, no longer revoking permissions upon unmapping strictly requires callers to additionally invoke
XEN_DOMCTL_ioport_permission. Or else a security issue would arise. In-tree code already does so.While there switch to using %pd in the two log messages.
Quoted 7 lines
Quoted 2 lines
Fixes 192c4dabc344 ("domctl and p2m changes for PCI passthru")Signed-off-by Jan Beulich <[email protected]>It's difficult to not think about someone appearing in 3 or 4 years complaining that this change in behavior has caused them a security issue, but I do agree that the previous behavior was inconsistent at best:
A positive aspect here is that the similar change for MMIO went without any fallout, as far as I'm aware.
Quoted 1 line
Acked-by Roger Pau Monné <[email protected]>Thanks, but ...
Quoted 2 lines
However you need to bump
XEN_DOMCTL_INTERFACE_VERSIONto note the ABI change as we are in 4.23 now.... there's no interface change here. A bump therefore won't buy us anything. I'm hesitant to take your ack as long as we disagree here.
Quoted 8 lines
Quoted 3 lines
It's not an interface change, but it's a change in behavior of an existing hypercall in a security-relevant way, so people would generally need to be aware of it, just in case.
But the interface version bump won't necessarily make anyone aware. Things will continue to build as before, and there's also no binary incompatibility. The best way of making people aware is the ChangeLog entry that iirc you had asked for (and that's now there).
I should probably add that bumping the interface version now also wouldn't do any harm; there's at least one other series pending which wants to do this anyway in this starting release cycle. Yet I still think the bumping doesn't quite belong here.
Jan
Re: [PATCH v3 1/2] x86/domctl: don't imply I/O port permissions from I/O port mapping
Quoted 47 lines · Jan Beulich
Quoted 37 lines · Jan Beulich
Quoted 36 lines · Roger Pau Monné
Quoted 34 lines · Jan Beulich
Quoted 13 lines · Roger Pau Monné
Quoted 12 lines · Jan Beulich
Rather than granting permissions when mapping (an operation that DM-s are allowed to carry out, while they can't invoke ioport-permission), check whether permissions actually were granted when adding a mapping. This then also allows relaxing the necessary locking.
While no longer granting permissions upon mapping is "only" at risk of breaking guests, no longer revoking permissions upon unmapping strictly requires callers to additionally invoke
XEN_DOMCTL_ioport_permission. Or else a security issue would arise. In-tree code already does so.While there switch to using %pd in the two log messages.
Quoted 7 lines
Quoted 2 lines
Fixes 192c4dabc344 ("domctl and p2m changes for PCI passthru")Signed-off-by Jan Beulich <[email protected]>It's difficult to not think about someone appearing in 3 or 4 years complaining that this change in behavior has caused them a security issue, but I do agree that the previous behavior was inconsistent at best:
A positive aspect here is that the similar change for MMIO went without any fallout, as far as I'm aware.
Quoted 1 line
Acked-by Roger Pau Monné <[email protected]>Thanks, but ...
Quoted 2 lines
However you need to bump
XEN_DOMCTL_INTERFACE_VERSIONto note the ABI change as we are in 4.23 now.... there's no interface change here. A bump therefore won't buy us anything. I'm hesitant to take your ack as long as we disagree here.
Quoted 8 lines
Quoted 3 lines
It's not an interface change, but it's a change in behavior of an existing hypercall in a security-relevant way, so people would generally need to be aware of it, just in case.
But the interface version bump won't necessarily make anyone aware. Things will continue to build as before, and there's also no binary incompatibility. The best way of making people aware is the ChangeLog entry that iirc you had asked for (and that's now there).
Quoted 4 lines
I should probably add that bumping the interface version now also wouldn't do any harm; there's at least one other series pending which wants to do this anyway in this starting release cycle. Yet I still think the bumping doesn't quite belong here.
I was going to say - it's very likely the interface will be bumped anyway. I'm not going to insist, the text in domctl.h does mention that the interface should only be bumped "in case the interface is modified in an incompatible way", and you might argue there's no interface change here at all, as the interface stays the same, what changes is the underlying implementation.
Thanks, Roger.
Re: [PATCH v3 1/2] x86/domctl: don't imply I/O port permissions from I/O port mapping
In reply to Jan BeulichQuoted 31 lines · Jan Beulich
Rather than granting permissions when mapping (an operation that DM-s are allowed to carry out, while they can't invoke ioport-permission), check whether permissions actually were granted when adding a mapping. This then also allows relaxing the necessary locking.
While no longer granting permissions upon mapping is "only" at risk of breaking guests, no longer revoking permissions upon unmapping strictly requires callers to additionally invoke
XEN_DOMCTL_ioport_permission. Or else a security issue would arise. In-tree code already does so.While there switch to using %pd in the two log messages.
Fixes 192c4dabc344 ("domctl and p2m changes for PCI passthru")Signed-off-by Jan Beulich <[email protected]>---
libxl haslibxl__grant_vga_iomem_permission(), but I can't spot any I/O port equivalent (nor a revoke counterpart, btw). Everywhere else MMIO and I/O ports look to be treated equally.Qemu uses both xc_domain_{iomem_permission,memory_mapping}() in
igd_write_opregion(), but only xc_domain_{memory,ioport}_mapping() inxen_pt_region_update()and xen_pt_{,un}register_vga_regions(). Is the IGD region special in any way? Clearly this can't work from a stubdom.
---
v3: Further extend ChangeLog entry.
v2: Avoid double evaluation of "add". Add ChangeLog entry.CHANGELOG.md +0
-0@@ -7,6 +7,11 @@ The format is based on [Keep a Changelog ## [4.23.0 UNRELEASED](https://xenbits.xenproject.org/gitweb/?p=xen.git;a=shortlog;h=staging) - TBD
CHANGELOG.md The format is based on [Keep a Changelog · line 17
Quoted 10 lines
CHANGELOG.md +5
-0### Changed + - On x86: + - XEN_DOMCTL_ioport_mapping no longer implicitly grants or revokes + permissions for the port range in question. + XEN_DOMCTL_ioport_permission now needs invoking up front / + afterwards. ### Added
~ Oleksii
Re: [PATCH v3 1/2] x86/domctl: don't imply I/O port permissions from I/O port mapping
In reply to Jan BeulichQuoted 19 lines · Jan Beulich
Rather than granting permissions when mapping (an operation that DM-s are allowed to carry out, while they can't invoke ioport-permission), check whether permissions actually were granted when adding a mapping. This then also allows relaxing the necessary locking.
While no longer granting permissions upon mapping is "only" at risk of breaking guests, no longer revoking permissions upon unmapping strictly requires callers to additionally invoke
XEN_DOMCTL_ioport_permission. Or else a security issue would arise. In-tree code already does so.While there switch to using %pd in the two log messages.
Fixes 192c4dabc344 ("domctl and p2m changes for PCI passthru")Signed-off-by Jan Beulich <[email protected]>---
libxl haslibxl__grant_vga_iomem_permission(), but I can't spot any I/O port equivalent (nor a revoke counterpart, btw). Everywhere else MMIO and I/O ports look to be treated equally.
Quoted 4 lines
Qemu uses both xc_domain_{iomem_permission,memory_mapping}() in
igd_write_opregion(), but only xc_domain_{memory,ioport}_mapping() inxen_pt_region_update()and xen_pt_{,un}register_vga_regions(). Is the IGD region special in any way? Clearly this can't work from a stubdom.
Yes, the IGD opregion is special, it's not something that exist on every PCI devices, just some Intel graphic devices, it's probably not part of any spec. Other region are just PCI bar, or the VGA region.
I guess the toolstack could handle that device and call iomem_perission instead of QEMU, if needed.
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH v3 2/2 x86/HVM: more checking for XEN_DOMCTL_ioport_mapping
In reply to Jan BeulichWhen adding ranges, only alter existing ones when there is an exact match. Don't accept ranges overlapping existing ones.
When removing ranges, only remove a range if there's an exact match. Return an error when the range isn't found.
---
Should "exact match" perhaps also include the guest port number? I'm uncertain here as that kind of conflicts with "add" being treated as "change" when the host port (and now count) match.
---
v2: Re-base over change to earlier patch.
xen/arch/x86/domctl.c +13 -4
@@ -728,12 +728,14 @@ long arch_do_domctl("ioport_map:remove: %pd gport=%x mport=%x nr=%x\n" , d, fgp, fmp, np); + ret = -ENOENT ;write_lock (&hvm->g2m_ioport_lock);list_for_each_entry (g2m_ioport, &hvm->g2m_ioport_list, list) -if ( g2m_ioport->mport == fmp ) +if ( g2m_ioport->mport == fmp && g2m_ioport->np == np ) {list_del (&g2m_ioport->list);xfree (g2m_ioport); + ret =0 ;break ; }write_unlock (&hvm->g2m_ioport_lock);
@@ -746,14 +748,21 @@ long arch_do_domctl(write_lock (&hvm->g2m_ioport_lock);list_for_each_entry (g2m_ioport, &hvm->g2m_ioport_list, list) -if (g2m_ioport->mport == fmp ) + { +if ( g2m_ioport->mport == fmp && g2m_ioport->np == np ) { g2m_ioport->gport = fgp; - g2m_ioport->np = np; found =1 ;break ; } -if ( !found ) +if ( fmp + np >= g2m_ioport->mport && + g2m_ioport->mport + g2m_ioport->np >= fmp ) + { + ret = -EBUSY ; +break ; + } + } +if ( !found && !ret ) { g2m_ioport = xmalloc(struct g2m_ioport);if ( !g2m_ioport )