Skip to content

Commit 996dc53

Browse files
jgunthorpejoergroedel
authored andcommitted
iommufd: Do not allow creating areas without READ or WRITE
This results in passing 0 or just IOMMU_CACHE to iommu_map(). Most of the page table formats don't like this: amdv1 - -EINVAL armv7s - returns 0, doesn't update mapped arm-lpae - returns 0 doesn't update mapped dart - returns 0, doesn't update mapped VT-D - returns -EINVAL Unfortunately the three formats that return 0 cause serious problems: - Returning ret = but not uppdating mapped from domain->map_pages() causes an infinite loop in __iommu_map() - Not writing ioptes means that VFIO/iommufd have no way to recover them and we will have memory leaks and worse during unmap Since almost nothing can support this, and it is a useless thing to do, block it early in iommufd. Cc: [email protected] Fixes: aad37e7 ("iommufd: IOCTLs for the io_pagetable") Signed-off-by: Jason Gunthorpe <[email protected]> Reviewed-by: Nicolin Chen <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 7af6c72 commit 996dc53

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

drivers/iommu/iommufd/ioas.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ int iommufd_ioas_map(struct iommufd_ucmd *ucmd)
213213
if (cmd->iova >= ULONG_MAX || cmd->length >= ULONG_MAX)
214214
return -EOVERFLOW;
215215

216+
if (!(cmd->flags &
217+
(IOMMU_IOAS_MAP_WRITEABLE | IOMMU_IOAS_MAP_READABLE)))
218+
return -EINVAL;
219+
216220
ioas = iommufd_get_ioas(ucmd->ictx, cmd->ioas_id);
217221
if (IS_ERR(ioas))
218222
return PTR_ERR(ioas);
@@ -253,6 +257,10 @@ int iommufd_ioas_copy(struct iommufd_ucmd *ucmd)
253257
cmd->dst_iova >= ULONG_MAX)
254258
return -EOVERFLOW;
255259

260+
if (!(cmd->flags &
261+
(IOMMU_IOAS_MAP_WRITEABLE | IOMMU_IOAS_MAP_READABLE)))
262+
return -EINVAL;
263+
256264
src_ioas = iommufd_get_ioas(ucmd->ictx, cmd->src_ioas_id);
257265
if (IS_ERR(src_ioas))
258266
return PTR_ERR(src_ioas);

tools/testing/selftests/iommu/iommufd.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ TEST_F(iommufd_ioas, copy_area)
825825
{
826826
struct iommu_ioas_copy copy_cmd = {
827827
.size = sizeof(copy_cmd),
828-
.flags = IOMMU_IOAS_MAP_FIXED_IOVA,
828+
.flags = IOMMU_IOAS_MAP_FIXED_IOVA | IOMMU_IOAS_MAP_WRITEABLE,
829829
.dst_ioas_id = self->ioas_id,
830830
.src_ioas_id = self->ioas_id,
831831
.length = PAGE_SIZE,
@@ -1318,7 +1318,7 @@ TEST_F(iommufd_ioas, copy_sweep)
13181318
{
13191319
struct iommu_ioas_copy copy_cmd = {
13201320
.size = sizeof(copy_cmd),
1321-
.flags = IOMMU_IOAS_MAP_FIXED_IOVA,
1321+
.flags = IOMMU_IOAS_MAP_FIXED_IOVA | IOMMU_IOAS_MAP_WRITEABLE,
13221322
.src_ioas_id = self->ioas_id,
13231323
.dst_iova = MOCK_APERTURE_START,
13241324
.length = MOCK_PAGE_SIZE,
@@ -1608,7 +1608,7 @@ TEST_F(iommufd_mock_domain, user_copy)
16081608
};
16091609
struct iommu_ioas_copy copy_cmd = {
16101610
.size = sizeof(copy_cmd),
1611-
.flags = IOMMU_IOAS_MAP_FIXED_IOVA,
1611+
.flags = IOMMU_IOAS_MAP_FIXED_IOVA | IOMMU_IOAS_MAP_WRITEABLE,
16121612
.dst_ioas_id = self->ioas_id,
16131613
.dst_iova = MOCK_APERTURE_START,
16141614
.length = BUFFER_SIZE,

0 commit comments

Comments
 (0)