Skip to content

Commit b166b8e

Browse files
jgunthorpegregkh
authored andcommitted
iommufd/selftest: Check for overflow in IOMMU_TEST_OP_ADD_RESERVED
[ Upstream commit e6a973a ] syzkaller found it could overflow math in the test infrastructure and cause a WARN_ON by corrupting the reserved interval tree. This only effects test kernels with CONFIG_IOMMUFD_TEST. Validate the user input length in the test ioctl. Fixes: f4b20bb ("iommufd: Add kernel support for testing iommufd") Link: https://patch.msgid.link/r/0-v1-cd99f6049ba5+51-iommufd_syz_add_resv_jgg@nvidia.com Reviewed-by: Samiullah Khawaja <skhawaja@google.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Tested-by: Yi Liu <yi.l.liu@intel.com> Reported-by: syzbot+57fdb0cf6a0c5d1f15a2@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/69368129.a70a0220.38f243.008f.GAE@google.com Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 9bec0d7 commit b166b8e

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

drivers/iommu/iommufd/selftest.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1257,14 +1257,20 @@ static int iommufd_test_add_reserved(struct iommufd_ucmd *ucmd,
12571257
unsigned int mockpt_id,
12581258
unsigned long start, size_t length)
12591259
{
1260+
unsigned long last;
12601261
struct iommufd_ioas *ioas;
12611262
int rc;
12621263

1264+
if (!length)
1265+
return -EINVAL;
1266+
if (check_add_overflow(start, length - 1, &last))
1267+
return -EOVERFLOW;
1268+
12631269
ioas = iommufd_get_ioas(ucmd->ictx, mockpt_id);
12641270
if (IS_ERR(ioas))
12651271
return PTR_ERR(ioas);
12661272
down_write(&ioas->iopt.iova_rwsem);
1267-
rc = iopt_reserve_iova(&ioas->iopt, start, start + length - 1, NULL);
1273+
rc = iopt_reserve_iova(&ioas->iopt, start, last, NULL);
12681274
up_write(&ioas->iopt.iova_rwsem);
12691275
iommufd_put_object(ucmd->ictx, &ioas->obj);
12701276
return rc;

0 commit comments

Comments
 (0)