Skip to contentSkip to conversation

vfio/pci: Fix OpRegion read

PATCH In review Zhenyu Wang 3 participants 5 messages Nov 19, 2021 – Nov 30, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vfio/pci: Fix OpRegion read

This is to fix incorrect pointer arithmetic which caused wrong OpRegion version returned, then VM driver got error to get wanted VBT block. We need to be safe to return correct data, so force pointer type for byte access.

Fixes 49ba1a2976c8 ("vfio/pci: Add OpRegion 2.0+ Extended VBT support.")
Cc Colin Xu <[email protected]>
Cc Dmitry Torokhov <[email protected]>
---
 drivers/vfio/pci/vfio_pci_igd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/vfio/pci/vfio_pci_igd.c +2 -2
index 56cd551e0e04..dad6eeed5e80 100644
@@ -98,7 +98,7 @@ static ssize_t vfio_pci_igd_rw(struct vfio_pci_core_device *vdev,
 			version = cpu_to_le16(0x0201);
 
 		if (igd_opregion_shift_copy(buf, &off,
-					    &version + (pos - OPREGION_VERSION),
+					    (u8 *)&version + (pos - OPREGION_VERSION),
 					    &pos, &remaining, bytes))
 			return -EFAULT;
 	}
@@ -121,7 +121,7 @@ static ssize_t vfio_pci_igd_rw(struct vfio_pci_core_device *vdev,
 					  OPREGION_SIZE : 0);
 
 		if (igd_opregion_shift_copy(buf, &off,
-					    &rvda + (pos - OPREGION_RVDA),
+					    (u8 *)&rvda + (pos - OPREGION_RVDA),
 					    &pos, &remaining, bytes))
 			return -EFAULT;
 	}
Signature · 1 line
2.33.1
#1 lore raw

Thanks for the fix.
The implicit ptr cast will incorrectly advance the pointer. Cast to byte is the correct step.

Best Regards,
Colin

Quoted 39 lines · Zhenyu Wang

This is to fix incorrect pointer arithmetic which caused wrong OpRegion version returned, then VM driver got error to get wanted VBT block. We need to be safe to return correct data, so force pointer type for byte access.

Fixes 49ba1a2976c8 ("vfio/pci: Add OpRegion 2.0+ Extended VBT support.")
Cc Colin Xu <[email protected]>
Cc Dmitry Torokhov <[email protected]>
---
 drivers/vfio/pci/vfio_pci_igd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/vfio/pci/vfio_pci_igd.c +2 -3
index 56cd551e0e04..dad6eeed5e80 100644
@@ -98,7 +98,7 @@ static ssize_t vfio_pci_igd_rw(struct vfio_pci_core_device *vdev,
                        version = cpu_to_le16(0x0201);
 
                if (igd_opregion_shift_copy(buf, &off,
-                                           &version + (pos - OPREGION_VERSION),
+                                           (u8 *)&version + (pos - OPREGION_VERSION),
                                            &pos, &remaining, bytes))
                        return -EFAULT;
        }
@@ -121,7 +121,7 @@ static ssize_t vfio_pci_igd_rw(struct vfio_pci_core_device *vdev,
                                          OPREGION_SIZE : 0);
 
                if (igd_opregion_shift_copy(buf, &off,
-                                           &rvda + (pos - OPREGION_RVDA),
+                                           (u8 *)&rvda + (pos - OPREGION_RVDA),
                                            &pos, &remaining, bytes))
                        return -EFAULT;
        }
--

2.33.1

Acked-by on v1 1/1
#2 lore raw
In reply to Zhenyu Wang

Thanks and appreciated for the fix.

Quoted 39 lines · Zhenyu Wang

This is to fix incorrect pointer arithmetic which caused wrong OpRegion version returned, then VM driver got error to get wanted VBT block. We need to be safe to return correct data, so force pointer type for byte access.

Fixes 49ba1a2976c8 ("vfio/pci: Add OpRegion 2.0+ Extended VBT support.")
Cc Colin Xu <[email protected]>
Cc Dmitry Torokhov <[email protected]>
---
 drivers/vfio/pci/vfio_pci_igd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/vfio/pci/vfio_pci_igd.c +2 -3
index 56cd551e0e04..dad6eeed5e80 100644
@@ -98,7 +98,7 @@ static ssize_t vfio_pci_igd_rw(struct vfio_pci_core_device *vdev,
                        version = cpu_to_le16(0x0201);
 
                if (igd_opregion_shift_copy(buf, &off,
-                                           &version + (pos - OPREGION_VERSION),
+                                           (u8 *)&version + (pos - OPREGION_VERSION),
                                            &pos, &remaining, bytes))
                        return -EFAULT;
        }
@@ -121,7 +121,7 @@ static ssize_t vfio_pci_igd_rw(struct vfio_pci_core_device *vdev,
                                          OPREGION_SIZE : 0);
 
                if (igd_opregion_shift_copy(buf, &off,
-                                           &rvda + (pos - OPREGION_RVDA),
+                                           (u8 *)&rvda + (pos - OPREGION_RVDA),
                                            &pos, &remaining, bytes))
                        return -EFAULT;
        }
--

2.33.1

#3 lore raw

PATCH 1/1 vfio/pci: Fix OpRegion read

This is to fix incorrect pointer arithmetic which caused wrong OpRegion version returned, then VM driver got error to get wanted VBT block. We need to be safe to return correct data, so force pointer type for byte access.

Fixes 49ba1a2976c8 ("vfio/pci: Add OpRegion 2.0+ Extended VBT support.")
Cc Colin Xu <[email protected]>
Cc Alex Williamson <[email protected]>
Cc Dmitry Torokhov <[email protected]>
Cc "Xu, Terrence" <[email protected]>
Cc "Gao, Fred" <[email protected]>
---
 drivers/vfio/pci/vfio_pci_igd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/vfio/pci/vfio_pci_igd.c +2 -2
index 56cd551e0e04..dad6eeed5e80 100644
@@ -98,7 +98,7 @@ static ssize_t vfio_pci_igd_rw(struct vfio_pci_core_device *vdev,
 			version = cpu_to_le16(0x0201);
 
 		if (igd_opregion_shift_copy(buf, &off,
-					    &version + (pos - OPREGION_VERSION),
+					    (u8 *)&version + (pos - OPREGION_VERSION),
 					    &pos, &remaining, bytes))
 			return -EFAULT;
 	}
@@ -121,7 +121,7 @@ static ssize_t vfio_pci_igd_rw(struct vfio_pci_core_device *vdev,
 					  OPREGION_SIZE : 0);
 
 		if (igd_opregion_shift_copy(buf, &off,
-					    &rvda + (pos - OPREGION_RVDA),
+					    (u8 *)&rvda + (pos - OPREGION_RVDA),
 					    &pos, &remaining, bytes))
 			return -EFAULT;
 	}
Signature · 1 line
2.33.1
#4 lore raw
Quoted 31 lines · On Thu, 25 Nov 2021 13:13:28 +0800 Zhenyu Wang <[email protected]> wrote:

This is to fix incorrect pointer arithmetic which caused wrong OpRegion version returned, then VM driver got error to get wanted VBT block. We need to be safe to return correct data, so force pointer type for byte access.

Fixes 49ba1a2976c8 ("vfio/pci: Add OpRegion 2.0+ Extended VBT support.")
Cc Colin Xu <[email protected]>
Cc Alex Williamson <[email protected]>
Cc Dmitry Torokhov <[email protected]>
Cc "Xu, Terrence" <[email protected]>
Cc "Gao, Fred" <[email protected]>
---
 drivers/vfio/pci/vfio_pci_igd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/vfio/pci/vfio_pci_igd.c +1 -1
index 56cd551e0e04..dad6eeed5e80 100644
@@ -98,7 +98,7 @@ static ssize_t vfio_pci_igd_rw(struct vfio_pci_core_device *vdev,
 			version = cpu_to_le16(0x0201);
 
 		if (igd_opregion_shift_copy(buf, &off,
-					    &version + (pos - OPREGION_VERSION),
+					    (u8 *)&version + (pos - OPREGION_VERSION),
 					    &pos, &remaining, bytes))
 			return -EFAULT;
 	}

drivers/vfio/pci/vfio_pci_igd.c static ssize_t vfio_pci_igd_rw(struct vfio_pci_core_device *vdev, · line 127

Quoted 8 lines
drivers/vfio/pci/vfio_pci_igd.c +1 -1
@@ -121,7 +121,7 @@ static ssize_t vfio_pci_igd_rw(struct vfio_pci_core_device *vdev,
 					  OPREGION_SIZE : 0);
 
 		if (igd_opregion_shift_copy(buf, &off,
-					    &rvda + (pos - OPREGION_RVDA),
+					    (u8 *)&rvda + (pos - OPREGION_RVDA),
 					    &pos, &remaining, bytes))
 			return -EFAULT;
 	}

Applied to vfio for-linus branch for v5.16. Thanks,

Alex