* [PATCH 1/7] vfio/platform: prevent read-only region mappings from becoming writable
2026-09-21 12:23 [PATCH 0/7] vfio: mmap()/mprotect() hygiene for MMIO region mappings Abdifatah Suruur
@ 2026-09-21 12:23 ` Abdifatah Suruur
2026-09-21 12:23 ` [PATCH 2/7] vfio/fsl-mc: " Abdifatah Suruur
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Abdifatah Suruur @ 2026-09-21 12:23 UTC (permalink / raw)
To: kvm, linux-kernel
Cc: alex, eric.auger, smostafa, praan, ioana.ciornei, nipun.gupta,
nikhil.agarwal
vfio_platform_mmap() rejects writable mappings of regions without the
WRITE flag, but leaves VM_MAYWRITE set. Userspace can map such a region
read-only and then upgrade the mapping to writable with mprotect().
Clear VM_MAYWRITE for regions without the WRITE flag, as i915 does for
its read-only objects and as fixed in drm/vc4 (CVE-2026-68445),
drm/panthor (CVE-2024-53071) and commit a5edadbae57e ("ptp: vmclock:
prevent read-only mappings from becoming writable").
Note this is defensive hardening: no in-tree platform driver currently
publishes a region without the WRITE flag. The guard costs nothing and
keeps the mmap() interface honest if a read-only region ever appears.
Fixes: fad4d5b1f042 ("vfio/platform: support MMAP of MMIO regions")
Signed-off-by: Abdifatah Suruur <suruurism@gmail.com>
Reviewed-by: Mostafa Saleh <smostafa@google.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Pranjal Shrivastava <praan@google.com>
---
drivers/vfio/platform/vfio_platform_common.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c
index c72db5a99ebda..ab531318f170a 100644
--- a/drivers/vfio/platform/vfio_platform_common.c
+++ b/drivers/vfio/platform/vfio_platform_common.c
@@ -591,9 +591,13 @@ int vfio_platform_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma
&& (vma->vm_flags & VM_READ))
return -EINVAL;
- if (!(vdev->regions[index].flags & VFIO_REGION_INFO_FLAG_WRITE)
- && (vma->vm_flags & VM_WRITE))
- return -EINVAL;
+ /* Prevent read-only region mappings from being upgraded with mprotect() */
+ if (!(vdev->regions[index].flags & VFIO_REGION_INFO_FLAG_WRITE)) {
+ if (vma->vm_flags & VM_WRITE)
+ return -EINVAL;
+
+ vm_flags_clear(vma, VM_MAYWRITE);
+ }
vma->vm_private_data = vdev;
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 2/7] vfio/fsl-mc: prevent read-only region mappings from becoming writable
2026-09-21 12:23 [PATCH 0/7] vfio: mmap()/mprotect() hygiene for MMIO region mappings Abdifatah Suruur
2026-09-21 12:23 ` [PATCH 1/7] vfio/platform: prevent read-only region mappings from becoming writable Abdifatah Suruur
@ 2026-09-21 12:23 ` Abdifatah Suruur
2026-09-21 12:23 ` [PATCH 3/7] vfio/cdx: " Abdifatah Suruur
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Abdifatah Suruur @ 2026-09-21 12:23 UTC (permalink / raw)
To: kvm, linux-kernel
Cc: alex, eric.auger, smostafa, praan, ioana.ciornei, nipun.gupta,
nikhil.agarwal
vfio_fsl_mc_mmap() rejects writable mappings of regions without the
WRITE flag, but leaves VM_MAYWRITE set. Userspace can map such a region
read-only and then upgrade the mapping to writable with mprotect().
Clear VM_MAYWRITE for regions without the WRITE flag, as i915 does for
its read-only objects and as fixed in drm/vc4 (CVE-2026-68445),
drm/panthor (CVE-2024-53071) and commit a5edadbae57e ("ptp: vmclock:
prevent read-only mappings from becoming writable").
Note this is defensive hardening: the fsl-mc bus publishes all device
regions with the WRITE flag set, so no device can currently reach the
read-only path. The guard costs nothing and keeps the mmap() interface
honest if a read-only region ever appears.
Fixes: 67247289688d4 ("vfio/fsl-mc: Allow userspace to MMAP fsl-mc device MMIO regions")
Signed-off-by: Abdifatah Suruur <suruurism@gmail.com>
Reviewed-by: Ioana Ciornei <ioana.ciornei@nxp.com>
---
--- a/drivers/vfio/fsl-mc/vfio_fsl_mc.c
+++ b/drivers/vfio/fsl-mc/vfio_fsl_mc.c
@@ -406,7 +406,11 @@
if (!(vdev->regions[index].flags & VFIO_REGION_INFO_FLAG_WRITE)
&& (vma->vm_flags & VM_WRITE))
return -EINVAL;
+ /* Prevent read-only region mappings from being upgraded with mprotect() */
+ if (!(vdev->regions[index].flags & VFIO_REGION_INFO_FLAG_WRITE))
+ vm_flags_clear(vma, VM_MAYWRITE);
+
vma->vm_private_data = mc_dev;
return vfio_fsl_mc_mmap_mmio(vdev->regions[index], vma);
}
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 3/7] vfio/cdx: prevent read-only region mappings from becoming writable
2026-09-21 12:23 [PATCH 0/7] vfio: mmap()/mprotect() hygiene for MMIO region mappings Abdifatah Suruur
2026-09-21 12:23 ` [PATCH 1/7] vfio/platform: prevent read-only region mappings from becoming writable Abdifatah Suruur
2026-09-21 12:23 ` [PATCH 2/7] vfio/fsl-mc: " Abdifatah Suruur
@ 2026-09-21 12:23 ` Abdifatah Suruur
2026-09-21 12:23 ` [PATCH 4/7] vfio/platform: keep logical vm_pgoff in MMIO region mmap Abdifatah Suruur
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Abdifatah Suruur @ 2026-09-21 12:23 UTC (permalink / raw)
To: kvm, linux-kernel
Cc: alex, eric.auger, smostafa, praan, ioana.ciornei, nipun.gupta,
nikhil.agarwal
vfio_cdx_mmap() rejects writable mappings of regions without the WRITE
flag, but leaves VM_MAYWRITE set. Userspace can map such a region
read-only and then upgrade the mapping to writable with mprotect(),
writing to MMIO regions the device marks read-only.
Clear VM_MAYWRITE for regions without the WRITE flag, as i915 does for
its read-only objects and as fixed in drm/vc4 (CVE-2026-68445),
drm/panthor (CVE-2024-53071) and commit a5edadbae57e ("ptp: vmclock:
prevent read-only mappings from becoming writable").
Note this is defensive hardening: no in-tree cdx device currently
publishes a region without the WRITE flag. The guard costs nothing and
keeps the mmap() interface honest if a read-only region ever appears.
Fixes: 234489ac56130 ("vfio/cdx: add support for CDX bus")
Signed-off-by: Abdifatah Suruur <suruurism@gmail.com>
---
--- a/drivers/vfio/cdx/main.c
+++ b/drivers/vfio/cdx/main.c
@@ -284,5 +284,9 @@
if (!(vdev->regions[index].flags & VFIO_REGION_INFO_FLAG_WRITE) &&
(vma->vm_flags & VM_WRITE))
return -EPERM;
+ /* Prevent read-only region mappings from being upgraded with mprotect() */
+ if (!(vdev->regions[index].flags & VFIO_REGION_INFO_FLAG_WRITE))
+ vm_flags_clear(vma, VM_MAYWRITE);
+
return vfio_cdx_mmap_mmio(vdev->regions[index], vma);
}
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 4/7] vfio/platform: keep logical vm_pgoff in MMIO region mmap
2026-09-21 12:23 [PATCH 0/7] vfio: mmap()/mprotect() hygiene for MMIO region mappings Abdifatah Suruur
` (2 preceding siblings ...)
2026-09-21 12:23 ` [PATCH 3/7] vfio/cdx: " Abdifatah Suruur
@ 2026-09-21 12:23 ` Abdifatah Suruur
2026-09-21 12:23 ` [PATCH 5/7] vfio/fsl-mc: " Abdifatah Suruur
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Abdifatah Suruur @ 2026-09-21 12:23 UTC (permalink / raw)
To: kvm, linux-kernel
Cc: alex, eric.auger, smostafa, praan, ioana.ciornei, nipun.gupta,
nikhil.agarwal
vfio_platform_mmap_mmio() overwrites vma->vm_pgoff with the physical
frame number of the MMIO region and passes it to remap_pfn_range().
The VMA is inserted into the device file's mapping->i_mmap interval
tree keyed by vm_pgoff, which VFIO expects to be the logical file
offset: the core links every device mmap to the device inode's
i_mapping precisely so that unmap_mapping_range() can revoke all
mappings associated with a device (see vfio_device_cdev_open()).
With a raw PFN in vm_pgoff the interval tree entry lands in the wrong
coordinate space and unmap_mapping_range() cannot find the VMA,
leaving stale MMIO mappings behind any revocation attempt. Keep
vm_pgoff in the logical VFIO offset space, as vfio-pci does, and pass
the physical PFN to remap_pfn_range() explicitly.
This is defensive hygiene: none of vfio-platform, vfio/fsl-mc and
vfio/cdx call unmap_mapping_range() today, so no reachable
stale-mapping issue exists. Keeping vm_pgoff logical preserves the
VFIO core contract for any future revocation path.
Signed-off-by: Abdifatah Suruur <suruurism@gmail.com>
---
--- a/drivers/vfio/platform/vfio_platform_common.c
+++ b/drivers/vfio/platform/vfio_platform_common.c
@@ -561,6 +561,5 @@
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
- vma->vm_pgoff = (region.addr >> PAGE_SHIFT) + pgoff;
-
- return remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
+ return remap_pfn_range(vma, vma->vm_start,
+ (region.addr >> PAGE_SHIFT) + pgoff,
req_len, vma->vm_page_prot);
}
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 5/7] vfio/fsl-mc: keep logical vm_pgoff in MMIO region mmap
2026-09-21 12:23 [PATCH 0/7] vfio: mmap()/mprotect() hygiene for MMIO region mappings Abdifatah Suruur
` (3 preceding siblings ...)
2026-09-21 12:23 ` [PATCH 4/7] vfio/platform: keep logical vm_pgoff in MMIO region mmap Abdifatah Suruur
@ 2026-09-21 12:23 ` Abdifatah Suruur
2026-09-21 12:23 ` [PATCH 6/7] vfio/cdx: " Abdifatah Suruur
2026-09-21 12:23 ` [PATCH 7/7] vfio/cdx: reject non-shared MMIO mmaps Abdifatah Suruur
6 siblings, 0 replies; 8+ messages in thread
From: Abdifatah Suruur @ 2026-09-21 12:23 UTC (permalink / raw)
To: kvm, linux-kernel
Cc: alex, eric.auger, smostafa, praan, ioana.ciornei, nipun.gupta,
nikhil.agarwal
vfio_fsl_mc_mmap_mmio() overwrites vma->vm_pgoff with the physical
frame number of the MMIO region and passes it to remap_pfn_range().
The VMA is inserted into the device file's mapping->i_mmap interval
tree keyed by vm_pgoff, which VFIO expects to be the logical file
offset: the core links every device mmap to the device inode's
i_mapping precisely so that unmap_mapping_range() can revoke all
mappings associated with a device (see vfio_device_cdev_open()).
With a raw PFN in vm_pgoff the interval tree entry lands in the wrong
coordinate space and unmap_mapping_range() cannot find the VMA,
leaving stale MMIO mappings behind any revocation attempt. Keep
vm_pgoff in the logical VFIO offset space, as vfio-pci does, and pass
the physical PFN to remap_pfn_range() explicitly.
This is defensive hygiene: none of vfio-platform, vfio/fsl-mc and
vfio/cdx call unmap_mapping_range() today, so no reachable
stale-mapping issue exists. Keeping vm_pgoff logical preserves the
VFIO core contract for any future revocation path.
Signed-off-by: Abdifatah Suruur <suruurism@gmail.com>
Reviewed-by: Ioana Ciornei <ioana.ciornei@nxp.com>
---
--- a/drivers/vfio/fsl-mc/vfio_fsl_mc.c
+++ b/drivers/vfio/fsl-mc/vfio_fsl_mc.c
@@ -369,8 +369,7 @@
if (!region_cacheable)
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
- vma->vm_pgoff = (region.addr >> PAGE_SHIFT) + pgoff;
-
- return remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
+ return remap_pfn_range(vma, vma->vm_start,
+ (region.addr >> PAGE_SHIFT) + pgoff,
size, vma->vm_page_prot);
}
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 6/7] vfio/cdx: keep logical vm_pgoff in MMIO region mmap
2026-09-21 12:23 [PATCH 0/7] vfio: mmap()/mprotect() hygiene for MMIO region mappings Abdifatah Suruur
` (4 preceding siblings ...)
2026-09-21 12:23 ` [PATCH 5/7] vfio/fsl-mc: " Abdifatah Suruur
@ 2026-09-21 12:23 ` Abdifatah Suruur
2026-09-21 12:23 ` [PATCH 7/7] vfio/cdx: reject non-shared MMIO mmaps Abdifatah Suruur
6 siblings, 0 replies; 8+ messages in thread
From: Abdifatah Suruur @ 2026-09-21 12:23 UTC (permalink / raw)
To: kvm, linux-kernel
Cc: alex, eric.auger, smostafa, praan, ioana.ciornei, nipun.gupta,
nikhil.agarwal
vfio_cdx_mmap_mmio() overwrites vma->vm_pgoff with the physical frame
number of the MMIO region and passes it to io_remap_pfn_range(). The
VMA is inserted into the device file's mapping->i_mmap interval tree
keyed by vm_pgoff, which VFIO expects to be the logical file offset:
the core links every device mmap to the device inode's i_mapping
precisely so that unmap_mapping_range() can revoke all mappings
associated with a device (see vfio_device_cdev_open()).
With a raw PFN in vm_pgoff the interval tree entry lands in the wrong
coordinate space and unmap_mapping_range() cannot find the VMA,
leaving stale MMIO mappings behind any revocation attempt. Keep
vm_pgoff in the logical VFIO offset space, as vfio-pci does, and pass
the physical PFN to io_remap_pfn_range() explicitly.
This is defensive hygiene: none of vfio-platform, vfio/fsl-mc and
vfio/cdx call unmap_mapping_range() today, so no reachable
stale-mapping issue exists. Keeping vm_pgoff logical preserves the
VFIO core contract for any future revocation path.
Signed-off-by: Abdifatah Suruur <suruurism@gmail.com>
---
--- a/drivers/vfio/cdx/main.c
+++ b/drivers/vfio/cdx/main.c
@@ -257,6 +257,6 @@
- vma->vm_pgoff = (region.addr >> PAGE_SHIFT) + pgoff;
vma->vm_page_prot = pgprot_device(vma->vm_page_prot);
- return io_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
+ return io_remap_pfn_range(vma, vma->vm_start,
+ (region.addr >> PAGE_SHIFT) + pgoff,
size, vma->vm_page_prot);
}
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 7/7] vfio/cdx: reject non-shared MMIO mmaps
2026-09-21 12:23 [PATCH 0/7] vfio: mmap()/mprotect() hygiene for MMIO region mappings Abdifatah Suruur
` (5 preceding siblings ...)
2026-09-21 12:23 ` [PATCH 6/7] vfio/cdx: " Abdifatah Suruur
@ 2026-09-21 12:23 ` Abdifatah Suruur
6 siblings, 0 replies; 8+ messages in thread
From: Abdifatah Suruur @ 2026-09-21 12:23 UTC (permalink / raw)
To: kvm, linux-kernel
Cc: alex, eric.auger, smostafa, praan, ioana.ciornei, nipun.gupta,
nikhil.agarwal
vfio_cdx_mmap() accepts MAP_PRIVATE mappings. A non-shared mapping
with VM_MAYWRITE is a COW mapping, and remap_pfn_range()'s COW special
case in get_remap_pgoff() then overwrites vma->vm_pgoff with the
physical frame number:
if (is_cow) {
if (addr != vm_start || end != vm_end)
return -EINVAL;
*vm_pgoff_p = pfn;
}
The VMA is inserted into the device file's mapping->i_mmap interval
tree keyed by vm_pgoff, which VFIO expects to be the logical file
offset: the core links every device mmap to the device inode's
i_mapping precisely so that unmap_mapping_range() can revoke all
mappings associated with a device (see vfio_device_cdev_open()).
A raw PFN in vm_pgoff lands the interval tree entry in the wrong
coordinate space, so unmap_mapping_range() cannot find the VMA and a
stale MMIO mapping survives any revocation attempt. Without this
check, a MAP_PRIVATE mapping reintroduces that corruption even with
the logical-vm_pgoff fix in place.
Require VM_SHARED as vfio-pci, vfio/fsl-mc and vfio/platform already
do. This is defensive hygiene: vfio-cdx does not call
unmap_mapping_range() today, so no reachable stale-mapping issue
exists.
Signed-off-by: Abdifatah Suruur <suruurism@gmail.com>
---
diff --git a/drivers/vfio/cdx/main.c b/drivers/vfio/cdx/main.c
index b31ed4be7bdc1..6d208db0896d6 100644
--- a/drivers/vfio/cdx/main.c
+++ b/drivers/vfio/cdx/main.c
@@ -271,6 +271,9 @@ static int vfio_cdx_mmap(struct vfio_device *core_vdev,
index = vma->vm_pgoff >> (VFIO_CDX_OFFSET_SHIFT - PAGE_SHIFT);
+ if (!(vma->vm_flags & VM_SHARED))
+ return -EINVAL;
+
if (index >= cdx_dev->res_count)
return -EINVAL;
^ permalink raw reply [flat|nested] 8+ messages in thread