]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
iommu/io-pgtable-dart: Fix off by one error in table index check
authorJanne Grunau <j@jannau.net>
Tue, 9 Sep 2025 11:54:43 +0000 (13:54 +0200)
committerJoerg Roedel <joerg.roedel@amd.com>
Sat, 13 Sep 2025 06:07:25 +0000 (08:07 +0200)
commita2d2e6ea1865d316e4f0c0bbd8275ffdc4ec62f5
treeecebc5d20fb010917c9698af8ce294765eedeb8e
parentecf6508923f87e4597228f70cc838af3d37f6662
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: 74a0e72f03ff ("iommu/io-pgtable-dart: Add 4-level page table support")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/asahi/aMACFlJjrZHs_Yf-@stanley.mountain/
Signed-off-by: Janne Grunau <j@jannau.net>
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
drivers/iommu/io-pgtable-dart.c