Skip to content

Commit 9bec0d7

Browse files
jgunthorpegregkh
authored andcommitted
iommufd/selftest: Make it clearer to gcc that the access is not out of bounds
[ Upstream commit 5b244b0 ] GCC gets a bit confused and reports: In function '_test_cmd_get_hw_info', inlined from 'iommufd_ioas_get_hw_info' at iommufd.c:779:3, inlined from 'wrapper_iommufd_ioas_get_hw_info' at iommufd.c:752:1: >> iommufd_utils.h:804: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=] 804 | assert(!info->flags); | ~~~~^~~~~~~ iommufd.c: In function 'wrapper_iommufd_ioas_get_hw_info': iommufd.c:761:11: note: object 'buffer_smaller' of size 4 761 | } buffer_smaller; | ^~~~~~~~~~~~~~ While it is true that "struct iommu_test_hw_info[0]" is partly out of bounds of the input pointer, it is not true that info->flags is out of bounds. Unclear why it warns on this. Reuse an existing properly sized stack buffer and pass a truncated length instead to test the same thing. Fixes: af4fde9 ("iommufd/selftest: Add coverage for IOMMU_GET_HW_INFO ioctl") Link: https://patch.msgid.link/r/0-v1-63a2cffb09da+4486-iommufd_gcc_bounds_jgg@nvidia.com Reviewed-by: Kevin Tian <kevin.tian@intel.com> Reviewed-by: Nicolin Chen <nicolinc@nvidia.com> Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/oe-kbuild-all/202512032344.kaAcKFIM-lkp@intel.com/ Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 365417a commit 9bec0d7

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

tools/testing/selftests/iommu/iommufd.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -758,9 +758,6 @@ TEST_F(iommufd_ioas, get_hw_info)
758758
struct iommu_test_hw_info info;
759759
uint64_t trailing_bytes;
760760
} buffer_larger;
761-
struct iommu_test_hw_info_buffer_smaller {
762-
__u32 flags;
763-
} buffer_smaller;
764761

765762
if (self->device_id) {
766763
uint8_t max_pasid = 0;
@@ -792,8 +789,9 @@ TEST_F(iommufd_ioas, get_hw_info)
792789
* the fields within the size range still gets updated.
793790
*/
794791
test_cmd_get_hw_info(self->device_id,
795-
IOMMU_HW_INFO_TYPE_DEFAULT,
796-
&buffer_smaller, sizeof(buffer_smaller));
792+
IOMMU_HW_INFO_TYPE_DEFAULT, &buffer_exact,
793+
offsetofend(struct iommu_test_hw_info,
794+
flags));
797795
test_cmd_get_hw_info_pasid(self->device_id, &max_pasid);
798796
ASSERT_EQ(0, max_pasid);
799797
if (variant->pasid_capable) {

0 commit comments

Comments
 (0)