Skip to contentSkip to conversation

vfio/iommufd: Fix SIGSEV in iommufd_cdev_attach()

PATCH Applied Zhenzhong Duan 3 participants 3 messages Jan 16, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vfio/iommufd: Fix SIGSEV in iommufd_cdev_attach()

When iommufd_cdev_ram_block_discard_disable() fails for whatever reason, errp should be set or else SIGSEV is triggered in vfio_realize() when error_prepend() is called.

By this chance, use the same error message for both legacy and iommufd backend.

Fixes 5ee3dc7af785 ("vfio/iommufd: Implement the iommufd backend")
---
 hw/vfio/iommufd.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/vfio/iommufd.c +3 -2
index 3490a8f1eb..df61edffc0 100644
@@ -515,8 +515,8 @@ static bool iommufd_cdev_attach(const char *name, VFIODevice *vbasedev,
         } else {
             ret = iommufd_cdev_ram_block_discard_disable(true);
             if (ret) {
-                error_setg(errp,
-                              "Cannot set discarding of RAM broken (%d)", ret);
+                error_setg_errno(errp, -ret,
+                                 "Cannot set discarding of RAM broken");
                 goto err_discard_disable;
             }
             goto found_container;
@@ -544,6 +544,7 @@ static bool iommufd_cdev_attach(const char *name, VFIODevice *vbasedev,
 
     ret = iommufd_cdev_ram_block_discard_disable(true);
     if (ret) {
+        error_setg_errno(errp, -ret, "Cannot set discarding of RAM broken");
         goto err_discard_disable;
     }
 
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Zhenzhong,

Quoted 29 lines · Zhenzhong Duan

When iommufd_cdev_ram_block_discard_disable() fails for whatever reason, errp should be set or else SIGSEV is triggered in vfio_realize() when error_prepend() is called.

By this chance, use the same error message for both legacy and iommufd backend.

Fixes 5ee3dc7af785 ("vfio/iommufd: Implement the iommufd backend")
---
 hw/vfio/iommufd.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/vfio/iommufd.c +2 -2
index 3490a8f1eb..df61edffc0 100644
@@ -515,8 +515,8 @@ static bool iommufd_cdev_attach(const char *name, VFIODevice *vbasedev,
         } else {
             ret = iommufd_cdev_ram_block_discard_disable(true);
             if (ret) {
-                error_setg(errp,
-                              "Cannot set discarding of RAM broken (%d)", ret);
+                error_setg_errno(errp, -ret,
+                                 "Cannot set discarding of RAM broken");
                 goto err_discard_disable;
             }
             goto found_container;

hw/vfio/iommufd.c static bool iommufd_cdev_attach(const char *name, VFIODevice *vbasedev, · line 550

Quoted 7 lines
hw/vfio/iommufd.c +1 -0
@@ -544,6 +544,7 @@ static bool iommufd_cdev_attach(const char *name, VFIODevice *vbasedev,
 
     ret = iommufd_cdev_ram_block_discard_disable(true);
     if (ret) {
+        error_setg_errno(errp, -ret, "Cannot set discarding of RAM broken");
         goto err_discard_disable;
     }
 

Thanks!

Eric

#2 lore raw
In reply to Zhenzhong Duan
Quoted 9 lines · Zhenzhong Duan

When iommufd_cdev_ram_block_discard_disable() fails for whatever reason, errp should be set or else SIGSEV is triggered in vfio_realize() when error_prepend() is called.

By this chance, use the same error message for both legacy and iommufd backend.

Fixes 5ee3dc7af785 ("vfio/iommufd: Implement the iommufd backend")

Applied to vfio-next.

Thanks,

C.

Quoted 27 lines
---
  hw/vfio/iommufd.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
hw/vfio/iommufd.c +3 -2
index 3490a8f1eb..df61edffc0 100644
@@ -515,8 +515,8 @@ static bool iommufd_cdev_attach(const char *name, VFIODevice *vbasedev,
          } else {
              ret = iommufd_cdev_ram_block_discard_disable(true);
              if (ret) {
-                error_setg(errp,
-                              "Cannot set discarding of RAM broken (%d)", ret);
+                error_setg_errno(errp, -ret,
+                                 "Cannot set discarding of RAM broken");
                  goto err_discard_disable;
              }
              goto found_container;
@@ -544,6 +544,7 @@ static bool iommufd_cdev_attach(const char *name, VFIODevice *vbasedev,
 
      ret = iommufd_cdev_ram_block_discard_disable(true);
      if (ret) {
+        error_setg_errno(errp, -ret, "Cannot set discarding of RAM broken");
          goto err_discard_disable;
      }