mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] selftests: iommu: suppress -Warray-bounds in _test_cmd_get_hw_info
@ 2026-09-08 21:48 Eva Kurchatova
  2026-09-08 21:48 ` [PATCH 2/2] selftests: iommu: skip when the mock device is not there Eva Kurchatova
  2026-09-09 16:31 ` [PATCH 1/2] selftests: iommu: suppress -Warray-bounds in _test_cmd_get_hw_info Jason Gunthorpe
  0 siblings, 2 replies; 4+ messages in thread
From: Eva Kurchatova @ 2026-09-08 21:48 UTC (permalink / raw)
  To: Jason Gunthorpe, Kevin Tian, Shuah Khan
  Cc: linux-kernel, Eva Kurchatova, iommu, linux-kselftest

  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.

Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
 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 b4928cbd4d9c..c4dfa05e0612 100644
--- a/tools/testing/selftests/iommu/iommufd_utils.h
+++ b/tools/testing/selftests/iommu/iommufd_utils.h
@@ -866,12 +866,19 @@ static int _test_cmd_get_hw_info(int fd, __u32 device_id, __u32 data_type,
 		}
 	}
 
+	/*
+	 * 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 (max_pasid)
 		*max_pasid = cmd.out_max_pasid_log2;
-- 
2.55.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-09-09 16:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-08 21:48 [PATCH 1/2] selftests: iommu: suppress -Warray-bounds in _test_cmd_get_hw_info Eva Kurchatova
2026-09-08 21:48 ` [PATCH 2/2] selftests: iommu: skip when the mock device is not there Eva Kurchatova
2026-09-09 16:33   ` Jason Gunthorpe
2026-09-09 16:31 ` [PATCH 1/2] selftests: iommu: suppress -Warray-bounds in _test_cmd_get_hw_info Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®