On Sep 14, 2026, at 5:00 PM, Owen Giles <[email protected]> wrote:


flags is only initialized once before the BAR setup loop, so if a lower BAR's 
io_region is read only, every subsequent BAR will have its flags set as read 
only despite not being read only. By setting flags to RW in every iteration, 
each region


flags is only initialized once before the BAR setup loop, so if a lower
BAR's io_region is read only, every subsequent BAR will have its
flags set as read only despite not being read only. By setting flags to
RW in every iteration, each region is properly assessed and assigned
the proper flag.

Fixes: 3123f93d6b85 ("vfio-user: handle PCI BAR accesses")
Signed-off-by: Owen Giles <[email protected]>


Thank you for the patch!

Reviewed-by: Jagannathan Raman <[email protected]>

---

Notes:
    The ROM case of the read-only check is okay, as the ROM will always be the
    last in the loop, but the other check is what can result in unintended
    consequences.

 hw/remote/vfio-user-obj.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c
index a0498d218fa..67687c841a6 100644
--- a/hw/remote/vfio-user-obj.c
+++ b/hw/remote/vfio-user-obj.c
@@ -519,14 +519,15 @@ static vfu_region_access_cb_t 
*vfu_object_bar_handlers[PCI_NUM_REGIONS] = {
  */
 static void vfu_object_register_bars(vfu_ctx_t *vfu_ctx, PCIDevice *pdev)
 {
-    int flags = VFU_REGION_FLAG_RW;
-    int i;
+    int flags, i;

     for (i = 0; i < PCI_NUM_REGIONS; i++) {
         if (!pdev->io_regions[i].size) {
             continue;
         }

+        flags = VFU_REGION_FLAG_RW;
+
         if ((i == VFU_PCI_DEV_ROM_REGION_IDX) ||
             pdev->io_regions[i].memory->readonly) {
             flags &= ~VFU_REGION_FLAG_WRITE;
--
2.34.1


Reply via email to