Skip to content

Commit cf26839

Browse files
committed
Merge tag 'for-linus-iommufd' of git://git.kernel.org/pub/scm/linux/kernel/git/jgg/iommufd
Pull iommufd fixes from Jason Gunthorpe: "A few minor fixes, other than the randconfig fix this is only relevant to test code, not releases: - Randconfig failure if CONFIG_DMA_SHARED_BUFFER is not set - Remove gcc warning in kselftest - Fix a refcount leak on an error path in the selftest support code - Fix missing overflow checks in the selftest support code" * tag 'for-linus-iommufd' of git://git.kernel.org/pub/scm/linux/kernel/git/jgg/iommufd: iommufd/selftest: Check for overflow in IOMMU_TEST_OP_ADD_RESERVED iommufd/selftest: Do not leak the hwpt if IOMMU_TEST_OP_MD_CHECK_MAP fails iommufd/selftest: Make it clearer to gcc that the access is not out of bounds iommufd: Fix building without dmabuf
2 parents 7b8e926 + e6a973a commit cf26839

3 files changed

Lines changed: 19 additions & 9 deletions

File tree

drivers/iommu/iommufd/io_pagetable.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,11 @@ int iopt_map_file_pages(struct iommufd_ctx *ictx, struct io_pagetable *iopt,
495495
return -EOVERFLOW;
496496

497497
start_byte = start - ALIGN_DOWN(start, PAGE_SIZE);
498-
dmabuf = dma_buf_get(fd);
498+
if (IS_ENABLED(CONFIG_DMA_SHARED_BUFFER))
499+
dmabuf = dma_buf_get(fd);
500+
else
501+
dmabuf = ERR_PTR(-ENXIO);
502+
499503
if (!IS_ERR(dmabuf)) {
500504
pages = iopt_alloc_dmabuf_pages(ictx, dmabuf, start_byte, start,
501505
length,

drivers/iommu/iommufd/selftest.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,14 +1184,20 @@ static int iommufd_test_add_reserved(struct iommufd_ucmd *ucmd,
11841184
unsigned int mockpt_id,
11851185
unsigned long start, size_t length)
11861186
{
1187+
unsigned long last;
11871188
struct iommufd_ioas *ioas;
11881189
int rc;
11891190

1191+
if (!length)
1192+
return -EINVAL;
1193+
if (check_add_overflow(start, length - 1, &last))
1194+
return -EOVERFLOW;
1195+
11901196
ioas = iommufd_get_ioas(ucmd->ictx, mockpt_id);
11911197
if (IS_ERR(ioas))
11921198
return PTR_ERR(ioas);
11931199
down_write(&ioas->iopt.iova_rwsem);
1194-
rc = iopt_reserve_iova(&ioas->iopt, start, start + length - 1, NULL);
1200+
rc = iopt_reserve_iova(&ioas->iopt, start, last, NULL);
11951201
up_write(&ioas->iopt.iova_rwsem);
11961202
iommufd_put_object(ucmd->ictx, &ioas->obj);
11971203
return rc;
@@ -1215,8 +1221,10 @@ static int iommufd_test_md_check_pa(struct iommufd_ucmd *ucmd,
12151221
page_size = 1 << __ffs(mock->domain.pgsize_bitmap);
12161222
if (iova % page_size || length % page_size ||
12171223
(uintptr_t)uptr % page_size ||
1218-
check_add_overflow((uintptr_t)uptr, (uintptr_t)length, &end))
1219-
return -EINVAL;
1224+
check_add_overflow((uintptr_t)uptr, (uintptr_t)length, &end)) {
1225+
rc = -EINVAL;
1226+
goto out_put;
1227+
}
12201228

12211229
for (; length; length -= page_size) {
12221230
struct page *pages[1];

tools/testing/selftests/iommu/iommufd.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -755,9 +755,6 @@ TEST_F(iommufd_ioas, get_hw_info)
755755
struct iommu_test_hw_info info;
756756
uint64_t trailing_bytes;
757757
} buffer_larger;
758-
struct iommu_test_hw_info_buffer_smaller {
759-
__u32 flags;
760-
} buffer_smaller;
761758

762759
if (self->device_id) {
763760
uint8_t max_pasid = 0;
@@ -789,8 +786,9 @@ TEST_F(iommufd_ioas, get_hw_info)
789786
* the fields within the size range still gets updated.
790787
*/
791788
test_cmd_get_hw_info(self->device_id,
792-
IOMMU_HW_INFO_TYPE_DEFAULT,
793-
&buffer_smaller, sizeof(buffer_smaller));
789+
IOMMU_HW_INFO_TYPE_DEFAULT, &buffer_exact,
790+
offsetofend(struct iommu_test_hw_info,
791+
flags));
794792
test_cmd_get_hw_info_pasid(self->device_id, &max_pasid);
795793
ASSERT_EQ(0, max_pasid);
796794
if (variant->pasid_capable) {

0 commit comments

Comments
 (0)