Skip to content

Commit 5d8b1d9

Browse files
committed
iommufd/selftest: Test reserved regions near ULONG_MAX
This has triggered an overflow inside the ioas iova auto allocation logic, test it directly. Use the same stimulus syzkaller found. Link: https://patch.msgid.link/all/[email protected]/ Tested-by: Yi Liu <[email protected]> Tested-by: Nicolin Chen <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent b42497e commit 5d8b1d9

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tools/testing/selftests/iommu/iommufd.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,33 @@ TEST_F(iommufd_ioas, area_auto_iova)
968968
test_ioctl_ioas_unmap(iovas[i], PAGE_SIZE * (i + 1));
969969
}
970970

971+
/* https://lore.kernel.org/r/[email protected] */
972+
TEST_F(iommufd_ioas, reserved_overflow)
973+
{
974+
struct iommu_test_cmd test_cmd = {
975+
.size = sizeof(test_cmd),
976+
.op = IOMMU_TEST_OP_ADD_RESERVED,
977+
.id = self->ioas_id,
978+
.add_reserved.start = 6,
979+
};
980+
unsigned int map_len;
981+
__u64 iova;
982+
983+
if (PAGE_SIZE == 4096) {
984+
test_cmd.add_reserved.length = 0xffffffffffff8001;
985+
map_len = 0x5000;
986+
} else {
987+
test_cmd.add_reserved.length =
988+
0xffffffffffffffff - MOCK_PAGE_SIZE * 16;
989+
map_len = MOCK_PAGE_SIZE * 10;
990+
}
991+
992+
ASSERT_EQ(0,
993+
ioctl(self->fd, _IOMMU_TEST_CMD(IOMMU_TEST_OP_ADD_RESERVED),
994+
&test_cmd));
995+
test_err_ioctl_ioas_map(ENOSPC, buffer, map_len, &iova);
996+
}
997+
971998
TEST_F(iommufd_ioas, area_allowed)
972999
{
9731000
struct iommu_test_cmd test_cmd = {

0 commit comments

Comments
 (0)