Reviewed-by: Vasileios Almpanis <[email protected]>

On 3/23/26 9:31 PM, Konstantin Khorenko wrote:
   In function '_test_cmd_get_hw_info',
       inlined from 'iommufd_ioas_get_hw_info' at iommufd.c:614:3,
       inlined from 'wrapper_iommufd_ioas_get_hw_info' at iommufd.c:589:1:
   iommufd_utils.h:683:37: warning: array subscript 'struct 
iommu_test_hw_info[0]' is partly outside array bounds of 'struct 
iommu_test_hw_info_buffer_smaller[1]' [-Warray-bounds=]
     683 |                         assert(!info->flags);
         |                                 ~~~~^~~~~~~

The test intentionally passes a smaller buffer to exercise the kernel's
handling of undersized user buffers. Runtime data_len checks make the
access safe, but GCC cannot prove this statically. Suppress the warning
locally with a pragma.

https://virtuozzo.atlassian.net/browse/VSTOR-127529
Signed-off-by: Konstantin Khorenko <[email protected]>

Feature: fix selftests
---
  tools/testing/selftests/iommu/iommufd_utils.h | 7 +++++++
  1 file changed, 7 insertions(+)

diff --git a/tools/testing/selftests/iommu/iommufd_utils.h 
b/tools/testing/selftests/iommu/iommufd_utils.h
index 40f6f14ce136..1c65c1cde814 100644
--- a/tools/testing/selftests/iommu/iommufd_utils.h
+++ b/tools/testing/selftests/iommu/iommufd_utils.h
@@ -676,12 +676,19 @@ static int _test_cmd_get_hw_info(int fd, __u32 device_id, 
void *data,
                }
        }
+ /*
+        * When data_len is smaller than sizeof(*info), GCC warns about
+        * out-of-bounds access.  The runtime data_len checks make this safe.
+        */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Warray-bounds"
        if (info) {
                if (data_len >= offsetofend(struct iommu_test_hw_info, 
test_reg))
                        assert(info->test_reg == IOMMU_HW_INFO_SELFTEST_REGVAL);
                if (data_len >= offsetofend(struct iommu_test_hw_info, flags))
                        assert(!info->flags);
        }
+#pragma GCC diagnostic pop
if (capabilities)
                *capabilities = cmd.out_capabilities;
_______________________________________________
Devel mailing list
[email protected]
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to