Skip to contentSkip to conversation

xen/arm: map_dev_mmio_region: The iomem permission check should be done on MFN

PATCH In review Julien Grall 3 participants 4 messages Jun 14, 2016 – Jul 11, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/arm: map_dev_mmio_region: The iomem permission check should be done on MFN

The helper iomem_access_permitted expects MFNs in parameters and not GNFs. Thankfully only the hardware domain can call this function and it will always be with GFNS == MFNs for now.

Also, fix the printf to use the MFN range and not the GFN one.

---
This patch is a good candidate to backport to Xen 4.7. Without it, the hardware domain can map any MMIO because the permission check is done on the GPFNs and not the MNFs.

---
 xen/arch/arm/p2m.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/arm/p2m.c +2 -2
index 6a19c57..4c6547d 100644
@@ -1275,14 +1275,14 @@ int map_dev_mmio_region(struct domain *d,
 {
     int res;
 
-    if ( !(nr && iomem_access_permitted(d, start_gfn, start_gfn + nr - 1)) )
+    if ( !(nr && iomem_access_permitted(d, mfn, mfn + nr - 1)) )
         return 0;
 
     res = map_mmio_regions(d, start_gfn, nr, mfn);
     if ( res < 0 )
     {
         printk(XENLOG_G_ERR "Unable to map [%#lx - %#lx] in Dom%d\n",
-               start_gfn, start_gfn + nr - 1, d->domain_id);
+               mfn, mfn + nr - 1, d->domain_id);
         return res;
     }
 
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v1 1/1
#1 lore raw

Hi Julien,

Quoted 9 lines · Julien Grall

The helper iomem_access_permitted expects MFNs in parameters and not GNFs. Thankfully only the hardware domain can call this function and it will always be with GFNS == MFNs for now.

Also, fix the printf to use the MFN range and not the GFN one.

Quoted 30 lines

---
This patch is a good candidate to backport to Xen 4.7. Without it, the hardware domain can map any MMIO because the permission check is done on the GPFNs and not the MNFs.

---
 xen/arch/arm/p2m.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/arm/p2m.c +2 -2
index 6a19c57..4c6547d 100644
@@ -1275,14 +1275,14 @@ int map_dev_mmio_region(struct domain *d,
 {
     int res;
 
-    if ( !(nr && iomem_access_permitted(d, start_gfn, start_gfn + nr - 1)) )
+    if ( !(nr && iomem_access_permitted(d, mfn, mfn + nr - 1)) )
         return 0;
 
     res = map_mmio_regions(d, start_gfn, nr, mfn);
     if ( res < 0 )
     {
         printk(XENLOG_G_ERR "Unable to map [%#lx - %#lx] in Dom%d\n",
-               start_gfn, start_gfn + nr - 1, d->domain_id);
+               mfn, mfn + nr - 1, d->domain_id);
         return res;
     }
 
Signature · 7 lines
Shannon


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#2 lore raw
Quoted 7 lines · Shannon Zhao

Hi Julien,

Quoted 4 lines · Julien Grall

The helper iomem_access_permitted expects MFNs in parameters and not GNFs. Thankfully only the hardware domain can call this function and it will always be with GFNS == MFNs for now.

Quoted 6 lines
Quoted 5 lines

Also, fix the printf to use the MFN range and not the GFN one.

Shannon, thanks for your help reviewing this.

I'll commit.

Quoted 20 lines
Quoted 20 lines

---
This patch is a good candidate to backport to Xen 4.7. Without it, the hardware domain can map any MMIO because the permission check is done on the GPFNs and not the MNFs.

---
 xen/arch/arm/p2m.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/arm/p2m.c +1 -1
index 6a19c57..4c6547d 100644
@@ -1275,14 +1275,14 @@ int map_dev_mmio_region(struct domain *d,
 {
     int res;
 
-    if ( !(nr && iomem_access_permitted(d, start_gfn, start_gfn + nr - 1)) )
+    if ( !(nr && iomem_access_permitted(d, mfn, mfn + nr - 1)) )
         return 0;
 
Quoted 14 lines
Quoted 10 lines
xen/arch/arm/p2m.c +1 -1
     res = map_mmio_regions(d, start_gfn, nr, mfn);
     if ( res < 0 )
     {
         printk(XENLOG_G_ERR "Unable to map [%#lx - %#lx] in Dom%d\n",
-               start_gfn, start_gfn + nr - 1, d->domain_id);
+               mfn, mfn + nr - 1, d->domain_id);
         return res;
     }
 
Signature · 1 line
Shannon

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw
In reply to Julien Grall

Hi,

Ping?

Cheers,

Quoted 39 lines · Julien Grall

The helper iomem_access_permitted expects MFNs in parameters and not GNFs. Thankfully only the hardware domain can call this function and it will always be with GFNS == MFNs for now.

Also, fix the printf to use the MFN range and not the GFN one.

---
This patch is a good candidate to backport to Xen 4.7. Without it, the hardware domain can map any MMIO because the permission check is done on the GPFNs and not the MNFs.

---
  xen/arch/arm/p2m.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/arm/p2m.c +2 -2
index 6a19c57..4c6547d 100644
@@ -1275,14 +1275,14 @@ int map_dev_mmio_region(struct domain *d,
  {
      int res;
 
-    if ( !(nr && iomem_access_permitted(d, start_gfn, start_gfn + nr - 1)) )
+    if ( !(nr && iomem_access_permitted(d, mfn, mfn + nr - 1)) )
          return 0;
 
      res = map_mmio_regions(d, start_gfn, nr, mfn);
      if ( res < 0 )
      {
          printk(XENLOG_G_ERR "Unable to map [%#lx - %#lx] in Dom%d\n",
-               start_gfn, start_gfn + nr - 1, d->domain_id);
+               mfn, mfn + nr - 1, d->domain_id);
          return res;
      }
 
Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel