Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
To: linux-kselftest@vger.kernel.org
Cc: eva.kurchatova@virtuozzo.com, khorenko@virtuozzo.com
Subject: [PATCH 13/15] selftests/iommu: suppress -Warray-bounds in _test_cmd_get_hw_info
Date: Wed, 29 Apr 2026 13:28:09 +0300	[thread overview]
Message-ID: <20260429102811.47214-14-eva.kurchatova@virtuozzo.com> (raw)
In-Reply-To: <20260429102811.47214-1-eva.kurchatova@virtuozzo.com>

  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 via copying into properly-sized temporary structure.

Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
 tools/testing/selftests/iommu/iommufd_utils.h | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/iommu/iommufd_utils.h b/tools/testing/selftests/iommu/iommufd_utils.h
index 5502751d500c..ca978b8b796d 100644
--- a/tools/testing/selftests/iommu/iommufd_utils.h
+++ b/tools/testing/selftests/iommu/iommufd_utils.h
@@ -5,6 +5,7 @@
 
 #include <unistd.h>
 #include <stddef.h>
+#include <string.h>
 #include <sys/fcntl.h>
 #include <sys/ioctl.h>
 #include <stdint.h>
@@ -826,7 +827,6 @@ static int _test_cmd_get_hw_info(int fd, __u32 device_id, __u32 data_type,
 				 void *data, size_t data_len,
 				 uint32_t *capabilities, uint8_t *max_pasid)
 {
-	struct iommu_test_hw_info *info = (struct iommu_test_hw_info *)data;
 	struct iommu_hw_info cmd = {
 		.size = sizeof(cmd),
 		.dev_id = device_id,
@@ -866,11 +866,13 @@ static int _test_cmd_get_hw_info(int fd, __u32 device_id, __u32 data_type,
 		}
 	}
 
-	if (info) {
+	if (data) {
+		struct iommu_test_hw_info info = {0};
+		memcpy(&info, data, data_len);
 		if (data_len >= offsetofend(struct iommu_test_hw_info, test_reg))
-			assert(info->test_reg == IOMMU_HW_INFO_SELFTEST_REGVAL);
+			assert(info.test_reg == IOMMU_HW_INFO_SELFTEST_REGVAL);
 		if (data_len >= offsetofend(struct iommu_test_hw_info, flags))
-			assert(!info->flags);
+			assert(!info.flags);
 	}
 
 	if (max_pasid)
-- 
2.54.0


  parent reply	other threads:[~2026-04-29 10:28 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-29 10:27 [PATCH 00/15] Fix compilation warnings in selftests Eva Kurchatova
2026-04-29 10:27 ` [PATCH 01/15] selftests/uevent: fix -Wmaybe-uninitialized warning in uevent_filtering Eva Kurchatova
2026-04-29 10:27 ` [PATCH 02/15] selftests/prctl: remove unused variable 'j' in set-process-name Eva Kurchatova
2026-04-29 10:27 ` [PATCH 03/15] selftests/netfilter: remove unused variables in conntrack_dump_flush Eva Kurchatova
2026-04-29 10:28 ` [PATCH 04/15] selftests/netfilter: remove unused variable 'plen' in conntrack_reverse_clash Eva Kurchatova
2026-04-29 10:28 ` [PATCH 05/15] selftests/mqueue: fix warnings in mq_perf_tests Eva Kurchatova
2026-04-29 10:28 ` [PATCH 06/15] selftests/mqueue: fix -Wunused-variable warning for 'usage' in mq_open_tests Eva Kurchatova
2026-04-29 10:28 ` [PATCH 07/15] selftests/memfd: fix -Wmaybe-uninitialized warning in memfd_test Eva Kurchatova
2026-04-29 10:28 ` [PATCH 08/15] selftests/memfd: remove unused variable 'sig' in fuse_test Eva Kurchatova
2026-04-29 10:28 ` [PATCH 09/15] selftests/membarrier: remove unused variable 'i' Eva Kurchatova
2026-04-29 10:28 ` [PATCH 10/15] selftests/epoll: remove unused variable 'pfd' in epoll59 test Eva Kurchatova
2026-04-29 10:28 ` [PATCH 11/15] selftests/clone3: remove unused variables in clone3_cap_checkpoint_restore Eva Kurchatova
2026-04-29 10:28 ` [PATCH 12/15] selftests/tcp_ao: fix -Wdiscarded-qualifiers under C23 Eva Kurchatova
2026-04-29 10:28 ` Eva Kurchatova [this message]
2026-04-29 10:28 ` [PATCH 14/15] selftests/fchmodat2: suppress -Wunused-parameter Eva Kurchatova
2026-04-29 10:28 ` [PATCH 15/15] selftests/openat2: suppress -Wsign-compare and -Wunused-parameter Eva Kurchatova

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260429102811.47214-14-eva.kurchatova@virtuozzo.com \
    --to=eva.kurchatova@virtuozzo.com \
    --cc=khorenko@virtuozzo.com \
    --cc=linux-kselftest@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox