XSA-237 follow-up
cover XSA-237 follow-up
These were held back due to the freeze.
1: x86/IRQ: conditionally preserve access permission on map error paths 2: x86/MSI: leverage local variables
3: XSM/flask: constification of IRQ mapping interfaces
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 1/3 x86/IRQ: conditionally preserve access permission on map error paths
Permissions that had been granted before should not be revoked when handling unrelated errors.
xen/arch/x86/irq.c +23 -12
@@ -1918,6 +1918,7 @@ int map_domain_pirq(struct irq_desc *desc;unsigned long flags; DECLARE_BITMAP(prepared, MAX_MSI_IRQS) = {}; + DECLARE_BITMAP(granted, MAX_MSI_IRQS) = {};ASSERT (spin_is_locked (&d->event_lock));
@@ -1951,13 +1952,17 @@ int map_domain_pirq(return ret; } - ret =irq_permit_access (d, irq); -if ( ret ) +if (likely (!irq_access_permitted (d, irq)) ) { -printk (XENLOG_G_ERR -"dom%d: could not permit access to IRQ%d (pirq %d)\n" , - d->domain_id, irq, pirq); -return ret; + ret =irq_permit_access (d, irq); +if ( ret ) + { +printk (XENLOG_G_ERR +"dom%d: could not permit access to IRQ%d (pirq %d)\n" , + d->domain_id, irq, pirq); +return ret; + } +__set_bit (0 , granted); } ret =prepare_domain_irq_pirq (d, irq, pirq, &info);
@@ -2042,10 +2047,15 @@ int map_domain_pirq(__set_bit (nr, prepared); msi_desc[nr].irq = irq; -if (irq_permit_access (d, irq) !=0 ) -printk (XENLOG_G_WARNING -"dom%d: could not permit access to IRQ%d (pirq %d)\n" , - d->domain_id, irq, pirq); +if (likely (!irq_access_permitted (d, irq)) ) + { +if (irq_permit_access (d, irq) ) +printk (XENLOG_G_WARNING +"dom%d: could not permit access to IRQ%d (pirq %d)\n" , + d->domain_id, irq, pirq); +else +__set_bit (0 , granted); + } desc =irq_to_desc (irq);spin_lock_irqsave (&desc->lock, flags);
@@ -2074,7 +2084,8 @@ int map_domain_pirq( }while ( nr ) { -if ( irq >=0 &&irq_deny_access (d, irq) ) +if ( irq >=0 &&test_bit (nr, granted) && +irq_deny_access (d, irq) )printk (XENLOG_G_ERR "dom%d: could not revoke access to IRQ%d (pirq %d)\n" , d->domain_id, irq, pirq);
@@ -2105,7 +2116,7 @@ done:if (test_bit (0 , prepared) )cleanup_domain_irq_pirq (d, irq, info); revoke: -if (irq_deny_access (d, irq) ) +if (test_bit (0 , granted) &&irq_deny_access (d, irq) )printk (XENLOG_G_ERR "dom%d: could not revoke access to IRQ%d (pirq %d)\n" , d->domain_id, irq, pirq);
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 1/3] x86/IRQ: conditionally preserve access permission on map error paths
Quoted 61 lines · Jan Beulich
Permissions that had been granted before should not be revoked when handling unrelated errors.
Reported-by HW42 <[email protected]>Signed-off-by Jan Beulich <[email protected]>xen/arch/x86/irq.c +20
-10@@ -1918,6 +1918,7 @@ int map_domain_pirq(struct irq_desc *desc;unsigned long flags; DECLARE_BITMAP(prepared, MAX_MSI_IRQS) = {}; + DECLARE_BITMAP(granted, MAX_MSI_IRQS) = {};ASSERT (spin_is_locked (&d->event_lock));@@ -1951,13 +1952,17 @@ int map_domain_pirq(return ret; } - ret =irq_permit_access (d, irq); -if ( ret ) +if (likely (!irq_access_permitted (d, irq)) ) { -printk (XENLOG_G_ERR -"dom%d: could not permit access to IRQ%d (pirq %d)\n" , - d->domain_id, irq, pirq); -return ret; + ret =irq_permit_access (d, irq); +if ( ret ) + { +printk (XENLOG_G_ERR +"dom%d: could not permit access to IRQ%d (pirq %d)\n" , + d->domain_id, irq, pirq); +return ret; + } +__set_bit (0 , granted); } ret =prepare_domain_irq_pirq (d, irq, pirq, &info);@@ -2042,10 +2047,15 @@ int map_domain_pirq(__set_bit (nr, prepared); msi_desc[nr].irq = irq; -if (irq_permit_access (d, irq) !=0 ) -printk (XENLOG_G_WARNING -"dom%d: could not permit access to IRQ%d (pirq %d)\n" , - d->domain_id, irq, pirq); +if (likely (!irq_access_permitted (d, irq)) ) + { +if (irq_permit_access (d, irq) ) +printk (XENLOG_G_WARNING +"dom%d: could not permit access to IRQ%d (pirq %d)\n" , + d->domain_id, irq, pirq); +else +__set_bit (0 , granted); + } desc =irq_to_desc (irq);spin_lock_irqsave (&desc->lock, flags);
xen/arch/x86/irq.c int map_domain_pirq( · line 2087
Quoted 5 lines
xen/arch/x86/irq.c +1
-1@@ -2074,7 +2084,8 @@ int map_domain_pirq( }while ( nr ) { -if ( irq >=0 &&irq_deny_access (d, irq) ) + if ( irq >= 0 && test_bit(nr, granted) &&
You only ever set bit 0 of granted, but you test each of them here. Something seems wrong.
Should the previous hunk be __set_bit(nr, granted) ?
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 1/3] x86/IRQ: conditionally preserve access permission on map error paths
Quoted 72 lines
Quoted 1 line
Quoted 1 line · On 04.12.17 at 17:07, <[email protected]> wrote:
Quoted 61 lines · Jan Beulich
Permissions that had been granted before should not be revoked when handling unrelated errors.
Reported-by HW42 <[email protected]>Signed-off-by Jan Beulich <[email protected]>xen/arch/x86/irq.c +20
-10@@ -1918,6 +1918,7 @@ int map_domain_pirq(struct irq_desc *desc;unsigned long flags; DECLARE_BITMAP(prepared, MAX_MSI_IRQS) = {}; + DECLARE_BITMAP(granted, MAX_MSI_IRQS) = {};ASSERT (spin_is_locked (&d->event_lock));@@ -1951,13 +1952,17 @@ int map_domain_pirq(return ret; } - ret =irq_permit_access (d, irq); -if ( ret ) +if (likely (!irq_access_permitted (d, irq)) ) { -printk (XENLOG_G_ERR -"dom%d: could not permit access to IRQ%d (pirq %d)\n" , - d->domain_id, irq, pirq); -return ret; + ret =irq_permit_access (d, irq); +if ( ret ) + { +printk (XENLOG_G_ERR +"dom%d: could not permit access to IRQ%d (pirq %d)\n" , + d->domain_id, irq, pirq); +return ret; + } +__set_bit (0 , granted); } ret =prepare_domain_irq_pirq (d, irq, pirq, &info);@@ -2042,10 +2047,15 @@ int map_domain_pirq(__set_bit (nr, prepared); msi_desc[nr].irq = irq; -if (irq_permit_access (d, irq) !=0 ) -printk (XENLOG_G_WARNING -"dom%d: could not permit access to IRQ%d (pirq %d)\n" , - d->domain_id, irq, pirq); +if (likely (!irq_access_permitted (d, irq)) ) + { +if (irq_permit_access (d, irq) ) +printk (XENLOG_G_WARNING +"dom%d: could not permit access to IRQ%d (pirq %d)\n" , + d->domain_id, irq, pirq); +else +__set_bit (0 , granted); + } desc =irq_to_desc (irq);spin_lock_irqsave (&desc->lock, flags);xen/arch/x86/irq.c int map_domain_pirq( · line 2087
Quoted 5 lines
xen/arch/x86/irq.c +1
-1@@ -2074,7 +2084,8 @@ int map_domain_pirq( }while ( nr ) { -if ( irq >=0 &&irq_deny_access (d, irq) ) + if ( irq >= 0 && test_bit(nr, granted) &&You only ever set bit 0 of granted, but you test each of them here. Something seems wrong.
Quoted 1 line
Should the previous hunk be
__set_bit(nr, granted)?
Oh, yes of course, good catch. I'm sure it was right in an initial version of the patch, but must have got broken in a re-work / re-base.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 2/3 x86/MSI: leverage local variables
In reply to Jan Beulich... instead of using redundant calculations.
xen/arch/x86/msi.c +6 -12
@@ -446,8 +446,7 @@ static bool msi_set_mask_bit(struct irq_ pdev->msix->warned = domid;printk (XENLOG_G_WARNING "cannot mask IRQ %d: masking MSI-X on Dom%d's %04x:%02x:%02x.%u\n" , - desc->irq, domid, pdev->seg, pdev->bus, -PCI_SLOT (pdev->devfn),PCI_FUNC (pdev->devfn)); + desc->irq, domid, seg, bus, slot, func); } } pdev->msix->host_maskall = maskall;
@@ -1118,8 +1117,7 @@ static int __pci_enable_msix(struct msi_if ( old_desc ) {printk (XENLOG_ERR "irq %d already mapped to MSI-X on %04x:%02x:%02x.%u\n" , - msi->irq, msi->seg, msi->bus, -PCI_SLOT (msi->devfn),PCI_FUNC (msi->devfn)); + msi->irq, msi->seg, msi->bus, slot, func);return -EEXIST ; }
@@ -1127,8 +1125,7 @@ static int __pci_enable_msix(struct msi_if ( old_desc ) {printk (XENLOG_WARNING "MSI already in use on %04x:%02x:%02x.%u\n" , - msi->seg, msi->bus, -PCI_SLOT (msi->devfn),PCI_FUNC (msi->devfn)); + msi->seg, msi->bus, slot, func);__pci_disable_msi (old_desc); }
@@ -1177,8 +1174,7 @@ static void __pci_disable_msix(struct ms {printk (XENLOG_WARNING "cannot disable IRQ %d: masking MSI-X on %04x:%02x:%02x.%u\n" , - entry->irq, dev->seg, dev->bus, -PCI_SLOT (dev->devfn),PCI_FUNC (dev->devfn)); + entry->irq, seg, bus, slot, func); maskall = true; } dev->msix->host_maskall = maskall;
@@ -1376,8 +1372,7 @@ int pci_restore_msi_state(struct pci_dev bogus:dprintk (XENLOG_ERR ,"Restore MSI for %04x:%02x:%02x:%u entry %u not set?\n" , - pdev->seg, pdev->bus,PCI_SLOT (pdev->devfn), -PCI_FUNC (pdev->devfn), i); + pdev->seg, pdev->bus, slot, func, i);spin_unlock_irqrestore (&desc->lock, flags);if ( type ==PCI_CAP_ID_MSIX ) pci_conf_write16(pdev->seg, pdev->bus, slot, func,
@@ -1441,8 +1436,7 @@ int pci_restore_msi_state(struct pci_dev control =pci_conf_read16 (pdev->seg, pdev->bus, slot, func, cpos) & ~PCI_MSI_FLAGS_QSIZE ;multi_msi_enable (control, entry->msi.nvec); -pci_conf_write16 (pdev->seg, pdev->bus,PCI_SLOT (pdev->devfn), -PCI_FUNC (pdev->devfn), cpos, control); +pci_conf_write16 (pdev->seg, pdev->bus, slot, func, cpos, control);msi_set_enable (pdev,1 ); }
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 2/3] x86/MSI: leverage local variables
Quoted 3 lines · Jan Beulich
... instead of using redundant calculations.
Signed-off-by Jan Beulich <[email protected]>
Now that pci_sbdf_t has been introduced, I should dust off my patch for %pP
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 3/3 XSM/flask: constification of IRQ mapping interfaces
In reply to Jan BeulichThis clarifies that the involved structures are read-only.
xen/include/xsm/dummy.h +4 -2
@@ -445,7 +445,8 @@ static XSM_INLINE int xsm_map_domain_pirreturn xsm_default_action (action, current->domain, d); } -static XSM_INLINE int xsm_map_domain_irq(XSM_DEFAULT_ARG struct domain *d, int irq, void *data) +static XSM_INLINE int xsm_map_domain_irq(XSM_DEFAULT_ARG struct domain *d, +int irq,const void *data) {XSM_ASSERT_ACTION (XSM_HOOK );return xsm_default_action (action, current->domain, d);
@@ -469,7 +470,8 @@ static XSM_INLINE int xsm_unbind_pt_irq(return xsm_default_action (action, current->domain, d); } -static XSM_INLINE int xsm_unmap_domain_irq(XSM_DEFAULT_ARG struct domain *d, int irq, void *data) +static XSM_INLINE int xsm_unmap_domain_irq(XSM_DEFAULT_ARG struct domain *d, +int irq,const void *data) {XSM_ASSERT_ACTION (XSM_HOOK );return xsm_default_action (action, current->domain, d);
xen/include/xsm/xsm.h +2 -2
@@ -97,9 +97,9 @@ struct xsm_operations {char *(*show_irq_sid) (int irq);int (*map_domain_pirq) (struct domain *d); -int (*map_domain_irq) (struct domain *d,int irq,void *data); +int (*map_domain_irq) (struct domain *d,int irq,const void *data);int (*unmap_domain_pirq) (struct domain *d); -int (*unmap_domain_irq) (struct domain *d,int irq,void *data); +int (*unmap_domain_irq) (struct domain *d,int irq,const void *data);int (*bind_pt_irq) (struct domain *d,struct xen_domctl_bind_pt_irq *bind);int (*unbind_pt_irq) (struct domain *d,struct xen_domctl_bind_pt_irq *bind);int (*irq_permission) (struct domain *d,int pirq,uint8_t allow);
xen/xsm/flask/hooks.c +6 -6
@@ -877,13 +877,13 @@ static int flask_map_domain_pirq (structreturn current_has_perm (d,SECCLASS_RESOURCE ,RESOURCE__ADD ); } -static int flask_map_domain_msi (struct domain *d,int irq,void *data, +static int flask_map_domain_msi (struct domain *d,int irq,const void *data,u32 *sid,struct avc_audit_data *ad) {#ifdef CONFIG_HAS_PCI -struct msi_info *msi = data; - +const struct msi_info *msi = data;u32 machine_bdf = (msi->seg <<16 ) | (msi->bus <<8 ) | msi->devfn; +AVC_AUDIT_DATA_INIT (ad,DEV ); ad->device = machine_bdf;
@@ -912,7 +912,7 @@ static u32 flask_iommu_resource_use_permreturn perm; } -static int flask_map_domain_irq (struct domain *d,int irq,void *data) +static int flask_map_domain_irq (struct domain *d,int irq,const void *data) {u32 sid, dsid;int rc = -EPERM ;
@@ -943,7 +943,7 @@ static int flask_unmap_domain_pirq (strureturn current_has_perm (d,SECCLASS_RESOURCE ,RESOURCE__REMOVE ); } -static int flask_unmap_domain_msi (struct domain *d,int irq,void *data, +static int flask_unmap_domain_msi (struct domain *d,int irq,const void *data,u32 *sid,struct avc_audit_data *ad) {#ifdef CONFIG_HAS_PCI
@@ -959,7 +959,7 @@ static int flask_unmap_domain_msi (struc#endif } -static int flask_unmap_domain_irq (struct domain *d,int irq,void *data) +static int flask_unmap_domain_irq (struct domain *d,int irq,const void *data) {u32 sid;int rc = -EPERM ;
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 3/3] XSM/flask: constification of IRQ mapping interfaces
Quoted 3 lines · Jan Beulich
This clarifies that the involved structures are read-only.
Signed-off-by Jan Beulich <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel