xen/arm: fix iomem_ranges cfg in map_range_to_domain()
v2 cover xen/arm: fix iomem_ranges cfg in map_range_to_domain()
Hi
This series fixes incorrect calculation of iomem_range end address in map_range_to_domain() which is then passed to iomem_permit_access() and rangeset_add_range().
Those function expect the iomem_range end address to be inclusive while calculations are made with incorrect assumption it's exclusive.
Output of "key 'q' (ascii '71') => dump domain (and guest debug) info"
before:
(XEN) I/O Memory { 8000-c000, 30000-40000, 47ff0-47ff8, 7ff00-7ff01, c0000-d0000, e6020-e6021, ...
after:
(XEN) I/O Memory { 8000-bfff, 30000-3ffff, 47ff0-47ff7, 7ff00, c0000-cffff, e6020, ...
Changes in v2:
- split on two patches
- add "fixes" tags
- rewording of commit messages
v1:
https://patchew.org/Xen/[email protected]/
Grygorii Strashko (2):
xen/arm: fix iomem permissions cfg in map_range_to_domain() xen/arm: fix iomem_ranges cfg in map_range_to_domain()
xen/arch/arm/device.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 1/2 xen/arm: fix iomem permissions cfg in map_range_to_domain()
Now the following code in map_range_to_domain()
res = iomem_permit_access(d, paddr_to_pfn(addr),
paddr_to_pfn(PAGE_ALIGN(addr + len - 1)));
calculates the iomem range end address by rounding it up to the next Xen page with incorrect assumption that iomem range end address passed to iomem_permit_access() is exclusive, while it is expected to be inclusive. It gives Control domain (Dom0) access to manage incorrect MMIO range with one additional page.
For example, if requested range is [00e6140000:00e6141004] then it expected to add [e6140:e6141] range (num_pages=2) to the domain iomem_caps rangeset, but will add [e6140:e6142] (num_pages=3) instead.
To fix it, drop PAGE_ALIGN() from the iomem range end address calculation formula.
of mapped devices")
--- xen/arch/arm/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/device.c +1 -1
@@ -71,7 +71,7 @@ int map_range_to_domain(const struct dt_device_node *dev, strlen("/reserved-memory/")) != 0 ) { res =iomem_permit_access (d,paddr_to_pfn (addr), -paddr_to_pfn (PAGE_ALIGN (addr + len -1 ))); +paddr_to_pfn (addr + len -1 ));if ( res ) { printk(XENLOG_ERR "Unable to permit to dom%d access to"
Signature · 1 line
2.34.1
Re: [PATCH v2 1/2] xen/arm: fix iomem permissions cfg in map_range_to_domain()
Hi Grygorii,
Quoted 15 lines · Grygorii Strashko
Now the following code in
map_range_to_domain()res = iomem_permit_access(d,
paddr_to_pfn(addr),
paddr_to_pfn(PAGE_ALIGN(addr + len - 1)));calculates the iomem range end address by rounding it up to the next Xen page with incorrect assumption that iomem range end address passed to
iomem_permit_access()is exclusive, while it is expected to be inclusive. It gives Control domain (Dom0) access to manage incorrect MMIO range with one additional page.For example, if requested range is [00e6140000:00e6141004] then it expected to add [e6140:e6141] range (num_pages=2) to the domain
iomem_capsrangeset, but will add [e6140:e6142] (num_pages=3) instead.
Quoted 6 lines
To fix it, drop
PAGE_ALIGN()from the iomem range end address calculation formula.Fixes 33233c2758345 ("arch/arm: domain build: let dom0 access I/O memoryof mapped devices")
Signed-off-by Grygorii Strashko <[email protected]>
Cheers,
Quoted 17 lines
--- xen/arch/arm/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)xen/arch/arm/device.c +1
-1@@ -71,7 +71,7 @@ int map_range_to_domain(const struct dt_device_node *dev, strlen("/reserved-memory/")) != 0 ) { res =iomem_permit_access (d,paddr_to_pfn (addr), -paddr_to_pfn (PAGE_ALIGN (addr + len -1 ))); +paddr_to_pfn (addr + len -1 ));if ( res ) { printk(XENLOG_ERR "Unable to permit to dom%d access to"
Signature · 1 line
Julien Grall
Re: [PATCH v2 1/2] xen/arm: fix iomem permissions cfg in map_range_to_domain()
Hi
Quoted 18 lines · Julien Grall
Hi Grygorii,
Quoted 15 lines · Grygorii Strashko
Now the following code in
map_range_to_domain()res =
iomem_permit_access(d, paddr_to_pfn(addr), paddr_to_pfn(PAGE_ALIGN(addr + len - 1)));calculates the iomem range end address by rounding it up to the next Xen page with incorrect assumption that iomem range end address passed to
iomem_permit_access()is exclusive, while it is expected to be inclusive. It gives Control domain (Dom0) access to manage incorrect MMIO range with one additional page.For example, if requested range is [00e6140000:00e6141004] then it expected to add [e6140:e6141] range (num_pages=2) to the domain
iomem_capsrangeset, but will add [e6140:e6142] (num_pages=3) instead.
Quoted 8 lines
Quoted 6 lines
To fix it, drop
PAGE_ALIGN()from the iomem range end address calculation formula.Fixes 33233c2758345 ("arch/arm: domain build: let dom0 access I/O memoryof mapped devices")
Signed-off-by Grygorii Strashko <[email protected]>Reviewed-by Julien Grall <[email protected]>
Sorry, that I'm disturbing you, but do i need to perform any additional actions here?
Quoted 7 lines
Cheers,
Quoted 4 lines
---
xen/arch/arm/device.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines
Quoted 12 lines
xen/arch/arm/device.c +1
-1@@ -71,7 +71,7 @@ int map_range_to_domain(const struct dt_device_node *dev, strlen("/reserved-memory/")) != 0 ) { res = iomem_permit_access(d, paddr_to_pfn(addr), - paddr_to_pfn(PAGE_ALIGN(addr + len - 1))); + paddr_to_pfn(addr + len - 1)); if ( res ) {Quoted 1 line
printk(XENLOG_ERR "Unable to permit to dom%d access to"
Best regards,
-grygorii
Re: [PATCH v2 1/2] xen/arm: fix iomem permissions cfg in map_range_to_domain()
Quoted 24 lines · Grygorii Strashko
Hi
Quoted 21 lines · Julien Grall
Hi Grygorii,
Quoted 18 lines · Grygorii Strashko
Now the following code in
map_range_to_domain()res =
iomem_permit_access(d, paddr_to_pfn(addr), paddr_to_pfn(PAGE_ALIGN(addr + len - 1)));calculates the iomem range end address by rounding it up to the next Xen page with incorrect assumption that iomem range end address passed to
iomem_permit_access()is exclusive, while it is expected to be inclusive. It gives Control domain (Dom0) access to manage incorrect MMIO range with one additional page.For example, if requested range is [00e6140000:00e6141004] then it expected to add [e6140:e6141] range (num_pages=2) to the domain
iomem_capsrangeset, but will add [e6140:e6142] (num_pages=3) instead.To fix it, drop
PAGE_ALIGN()from the iomem range end address calculation formula.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Fixes 33233c2758345 ("arch/arm: domain build: let dom0 access I/O memoryof mapped devices")
Signed-off-by Grygorii Strashko <[email protected]>Reviewed-by Julien Grall <[email protected]>Sorry, that I'm disturbing you, but do i need to perform any additional actions here?
Thanks for the reminder. The tree only re-opened a few days ago and I haven't had a chance to go through the list of pending patches. I have pushed them to a branch. If the CI pass, then I will push them to staging.
Cheers,
Signature · 1 line
Julien Grall
PATCH v2 2/2 xen/arm: fix iomem_ranges cfg in map_range_to_domain()
In reply to Grygorii StrashkoNow the following code in map_range_to_domain()
res = rangeset_add_range(mr_data->iomem_ranges,
paddr_to_pfn(addr),
paddr_to_pfn_aligned(addr + len - 1)); where
paddr_to_pfn_aligned(paddr) defined as paddr_to_pfn(PAGE_ALIGN(paddr))
calculates the iomem range end address by rounding it up to the next Xen page with incorrect assumption that iomem range end address passed to rangeset_add_range() is exclusive, while it is expected to be inclusive.
For example, if requested range is [00e6140000:00e6141004] then it expected to add [e6140:e6141] range (num_pages=2) to the mr_data->iomem_ranges rangeset, but will add [e6140:e6142] (num_pages=3) instead.
To fix it, drop PAGE_ALIGN() from the iomem range end address calculation formula and just use paddr_to_pfn(addr + len - 1).
rangeset.")
--- xen/arch/arm/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/device.c +1 -1
@@ -107,7 +107,7 @@ int map_range_to_domain(const struct dt_device_node *dev, { res =rangeset_add_range (mr_data->iomem_ranges,paddr_to_pfn (addr), -paddr_to_pfn_aligned (addr + len -1 )); +paddr_to_pfn (addr + len -1 ));if ( res )return res; }
Signature · 1 line
2.34.1
Hi Grygorii,
Quoted 16 lines · Grygorii Strashko
Now the following code in
map_range_to_domain()res = rangeset_add_range(mr_data->iomem_ranges, paddr_to_pfn(addr), paddr_to_pfn_aligned(addr + len - 1)); where paddr_to_pfn_aligned(paddr) defined as paddr_to_pfn(PAGE_ALIGN(paddr))calculates the iomem range end address by rounding it up to the next Xen page with incorrect assumption that iomem range end address passed to
rangeset_add_range()is exclusive, while it is expected to be inclusive.For example, if requested range is [00e6140000:00e6141004] then it expected to add [e6140:e6141] range (num_pages=2) to the
mr_data->iomem_rangesrangeset, but will add [e6140:e6142] (num_pages=3) instead.
Quoted 6 lines
To fix it, drop
PAGE_ALIGN()from the iomem range end address calculation formula and just usepaddr_to_pfn(addr + len - 1).Fixes 57d4d7d4e8f3b (arm/asm/setup.h: Update struct map_range_data to addrangeset.")
Signed-off-by Grygorii Strashko <[email protected]>
Cheers,
Signature · 1 line
Julien Grall