Skip to content

Commit a2d2e6e

Browse files
jannaujoergroedel
authored andcommitted
iommu/io-pgtable-dart: Fix off by one error in table index check
The check for the dart table index allowed values of (1 << data->tbl_bits) while only as many entries are initialized in apple_dart_alloc_pgtable. This results in an array out of bounds access when data->tbl_bits is at its maximal value of 2. When data->tbl_bits is 0 or 1 an unset (initialized to zero) data->pgd[] entry is used. In both cases the value is used as pointer to read page table entries and results in dereferencing invalid pointers. There is no prior check that the passed iova is inside the iommu's IAS so invalid values can be passed from driver's calling iommu_map(). Fixes: 74a0e72 ("iommu/io-pgtable-dart: Add 4-level page table support") Reported-by: Dan Carpenter <[email protected]> Closes: https://lore.kernel.org/asahi/[email protected]/ Signed-off-by: Janne Grunau <[email protected]> Signed-off-by: Joerg Roedel <[email protected]>
1 parent ecf6508 commit a2d2e6e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/iommu/io-pgtable-dart.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ static dart_iopte *dart_get_last(struct dart_io_pgtable *data, unsigned long iov
177177
int level = data->levels;
178178
int tbl = dart_get_index(data, iova, level);
179179

180-
if (tbl > (1 << data->tbl_bits))
180+
if (tbl >= (1 << data->tbl_bits))
181181
return NULL;
182182

183183
ptep = data->pgd[tbl];
@@ -246,7 +246,7 @@ static int dart_map_pages(struct io_pgtable_ops *ops, unsigned long iova,
246246

247247
tbl = dart_get_index(data, iova, level);
248248

249-
if (tbl > (1 << data->tbl_bits))
249+
if (tbl >= (1 << data->tbl_bits))
250250
return -ENOMEM;
251251

252252
ptep = data->pgd[tbl];

0 commit comments

Comments
 (0)