* [PATCH] iommu/io-pgtable-arm: fix size_t signedness bug in unmap path
@ 2025-12-19 23:28 Chaitanya Kulkarni
2025-12-20 14:35 ` Rob Clark
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Chaitanya Kulkarni @ 2025-12-19 23:28 UTC (permalink / raw)
To: will, robin.murphy, joro, robin.clark
Cc: linux-arm-kernel, kch, Chaitanya Kulkarni, stable
__arm_lpae_unmap() returns size_t but was returning -ENOENT (negative
error code) when encountering an unmapped PTE. Since size_t is unsigned,
-ENOENT (typically -2) becomes a huge positive value (0xFFFFFFFFFFFFFFFE
on 64-bit systems).
This corrupted value propagates through the call chain:
__arm_lpae_unmap() returns -ENOENT as size_t
-> arm_lpae_unmap_pages() returns it
-> __iommu_unmap() adds it to iova address
-> iommu_pgsize() triggers BUG_ON due to corrupted iova
This can cause IOVA address overflow in __iommu_unmap() loop and
trigger BUG_ON in iommu_pgsize() from invalid address alignment.
Fix by returning 0 instead of -ENOENT. The WARN_ON already signals
the error condition, and returning 0 (meaning "nothing unmapped")
is the correct semantic for size_t return type. This matches the
behavior of other io-pgtable implementations (io-pgtable-arm-v7s,
io-pgtable-dart) which return 0 on error conditions.
Fixes: 3318f7b5cefb ("iommu/io-pgtable-arm: Add quirk to quiet WARN_ON()")
Cc: stable@vger.kernel.org
Signed-off-by: Chaitanya Kulkarni <ckulkarnilinux@gmail.com>
---
drivers/iommu/io-pgtable-arm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c
index e6626004b323..05d63fe92e43 100644
--- a/drivers/iommu/io-pgtable-arm.c
+++ b/drivers/iommu/io-pgtable-arm.c
@@ -637,7 +637,7 @@ static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data,
pte = READ_ONCE(*ptep);
if (!pte) {
WARN_ON(!(data->iop.cfg.quirks & IO_PGTABLE_QUIRK_NO_WARN));
- return -ENOENT;
+ return 0;
}
/* If the size matches this level, we're in the right place */
--
2.40.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] iommu/io-pgtable-arm: fix size_t signedness bug in unmap path
2025-12-19 23:28 [PATCH] iommu/io-pgtable-arm: fix size_t signedness bug in unmap path Chaitanya Kulkarni
@ 2025-12-20 14:35 ` Rob Clark
2026-01-05 19:07 ` Jason Gunthorpe
2026-01-05 21:25 ` Will Deacon
2 siblings, 0 replies; 5+ messages in thread
From: Rob Clark @ 2025-12-20 14:35 UTC (permalink / raw)
To: Chaitanya Kulkarni
Cc: will, robin.murphy, joro, linux-arm-kernel, kch, stable
On Fri, Dec 19, 2025 at 3:29 PM Chaitanya Kulkarni
<ckulkarnilinux@gmail.com> wrote:
>
> __arm_lpae_unmap() returns size_t but was returning -ENOENT (negative
> error code) when encountering an unmapped PTE. Since size_t is unsigned,
> -ENOENT (typically -2) becomes a huge positive value (0xFFFFFFFFFFFFFFFE
> on 64-bit systems).
>
> This corrupted value propagates through the call chain:
> __arm_lpae_unmap() returns -ENOENT as size_t
> -> arm_lpae_unmap_pages() returns it
> -> __iommu_unmap() adds it to iova address
> -> iommu_pgsize() triggers BUG_ON due to corrupted iova
>
> This can cause IOVA address overflow in __iommu_unmap() loop and
> trigger BUG_ON in iommu_pgsize() from invalid address alignment.
>
> Fix by returning 0 instead of -ENOENT. The WARN_ON already signals
> the error condition, and returning 0 (meaning "nothing unmapped")
> is the correct semantic for size_t return type. This matches the
> behavior of other io-pgtable implementations (io-pgtable-arm-v7s,
> io-pgtable-dart) which return 0 on error conditions.
>
> Fixes: 3318f7b5cefb ("iommu/io-pgtable-arm: Add quirk to quiet WARN_ON()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Chaitanya Kulkarni <ckulkarnilinux@gmail.com>
Reviewed-by: Rob Clark <robin.clark@oss.qualcomm.com>
> ---
> drivers/iommu/io-pgtable-arm.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c
> index e6626004b323..05d63fe92e43 100644
> --- a/drivers/iommu/io-pgtable-arm.c
> +++ b/drivers/iommu/io-pgtable-arm.c
> @@ -637,7 +637,7 @@ static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data,
> pte = READ_ONCE(*ptep);
> if (!pte) {
> WARN_ON(!(data->iop.cfg.quirks & IO_PGTABLE_QUIRK_NO_WARN));
> - return -ENOENT;
> + return 0;
> }
>
> /* If the size matches this level, we're in the right place */
> --
> 2.40.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] iommu/io-pgtable-arm: fix size_t signedness bug in unmap path
2025-12-19 23:28 [PATCH] iommu/io-pgtable-arm: fix size_t signedness bug in unmap path Chaitanya Kulkarni
2025-12-20 14:35 ` Rob Clark
@ 2026-01-05 19:07 ` Jason Gunthorpe
2026-01-05 21:25 ` Will Deacon
2 siblings, 0 replies; 5+ messages in thread
From: Jason Gunthorpe @ 2026-01-05 19:07 UTC (permalink / raw)
To: Chaitanya Kulkarni
Cc: will, robin.murphy, joro, robin.clark, linux-arm-kernel, kch,
stable
On Fri, Dec 19, 2025 at 03:28:58PM -0800, Chaitanya Kulkarni wrote:
> __arm_lpae_unmap() returns size_t but was returning -ENOENT (negative
> error code) when encountering an unmapped PTE. Since size_t is unsigned,
> -ENOENT (typically -2) becomes a huge positive value (0xFFFFFFFFFFFFFFFE
> on 64-bit systems).
>
> This corrupted value propagates through the call chain:
> __arm_lpae_unmap() returns -ENOENT as size_t
> -> arm_lpae_unmap_pages() returns it
> -> __iommu_unmap() adds it to iova address
> -> iommu_pgsize() triggers BUG_ON due to corrupted iova
>
> This can cause IOVA address overflow in __iommu_unmap() loop and
> trigger BUG_ON in iommu_pgsize() from invalid address alignment.
>
> Fix by returning 0 instead of -ENOENT. The WARN_ON already signals
> the error condition, and returning 0 (meaning "nothing unmapped")
> is the correct semantic for size_t return type. This matches the
> behavior of other io-pgtable implementations (io-pgtable-arm-v7s,
> io-pgtable-dart) which return 0 on error conditions.
>
> Fixes: 3318f7b5cefb ("iommu/io-pgtable-arm: Add quirk to quiet WARN_ON()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Chaitanya Kulkarni <ckulkarnilinux@gmail.com>
> ---
> drivers/iommu/io-pgtable-arm.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
At least the iommu_pgsize() path runs with !IO_PGTABLE_QUIRK_NO_WARN
and we don't hit that WARN_ON() before the return, but the GPU folks
using this NO_WARN path might have an issue so it should be fixed..
Jason
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] iommu/io-pgtable-arm: fix size_t signedness bug in unmap path
2025-12-19 23:28 [PATCH] iommu/io-pgtable-arm: fix size_t signedness bug in unmap path Chaitanya Kulkarni
2025-12-20 14:35 ` Rob Clark
2026-01-05 19:07 ` Jason Gunthorpe
@ 2026-01-05 21:25 ` Will Deacon
2026-01-15 22:08 ` Chaitanya Kulkarni
2 siblings, 1 reply; 5+ messages in thread
From: Will Deacon @ 2026-01-05 21:25 UTC (permalink / raw)
To: Chaitanya Kulkarni, joro
Cc: robin.murphy, robin.clark, linux-arm-kernel, kch, stable
On Fri, Dec 19, 2025 at 03:28:58PM -0800, Chaitanya Kulkarni wrote:
> __arm_lpae_unmap() returns size_t but was returning -ENOENT (negative
> error code) when encountering an unmapped PTE. Since size_t is unsigned,
> -ENOENT (typically -2) becomes a huge positive value (0xFFFFFFFFFFFFFFFE
> on 64-bit systems).
>
> This corrupted value propagates through the call chain:
> __arm_lpae_unmap() returns -ENOENT as size_t
> -> arm_lpae_unmap_pages() returns it
> -> __iommu_unmap() adds it to iova address
> -> iommu_pgsize() triggers BUG_ON due to corrupted iova
>
> This can cause IOVA address overflow in __iommu_unmap() loop and
> trigger BUG_ON in iommu_pgsize() from invalid address alignment.
>
> Fix by returning 0 instead of -ENOENT. The WARN_ON already signals
> the error condition, and returning 0 (meaning "nothing unmapped")
> is the correct semantic for size_t return type. This matches the
> behavior of other io-pgtable implementations (io-pgtable-arm-v7s,
> io-pgtable-dart) which return 0 on error conditions.
>
> Fixes: 3318f7b5cefb ("iommu/io-pgtable-arm: Add quirk to quiet WARN_ON()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Chaitanya Kulkarni <ckulkarnilinux@gmail.com>
> ---
> drivers/iommu/io-pgtable-arm.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c
> index e6626004b323..05d63fe92e43 100644
> --- a/drivers/iommu/io-pgtable-arm.c
> +++ b/drivers/iommu/io-pgtable-arm.c
> @@ -637,7 +637,7 @@ static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data,
> pte = READ_ONCE(*ptep);
> if (!pte) {
> WARN_ON(!(data->iop.cfg.quirks & IO_PGTABLE_QUIRK_NO_WARN));
> - return -ENOENT;
> + return 0;
> }
>
> /* If the size matches this level, we're in the right place */
Acked-by: Will Deacon <will@kernel.org>
Joerg -- please can you pick this one up for 6.19-rc?
Cheers,
Will
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] iommu/io-pgtable-arm: fix size_t signedness bug in unmap path
2026-01-05 21:25 ` Will Deacon
@ 2026-01-15 22:08 ` Chaitanya Kulkarni
0 siblings, 0 replies; 5+ messages in thread
From: Chaitanya Kulkarni @ 2026-01-15 22:08 UTC (permalink / raw)
To: Will Deacon, Chaitanya Kulkarni, joro@8bytes.org
Cc: robin.murphy@arm.com, robin.clark@oss.qualcomm.com,
linux-arm-kernel@lists.infradead.org, Chaitanya Kulkarni,
stable@vger.kernel.org
On 1/5/26 13:25, Will Deacon wrote:
> On Fri, Dec 19, 2025 at 03:28:58PM -0800, Chaitanya Kulkarni wrote:
>> __arm_lpae_unmap() returns size_t but was returning -ENOENT (negative
>> error code) when encountering an unmapped PTE. Since size_t is unsigned,
>> -ENOENT (typically -2) becomes a huge positive value (0xFFFFFFFFFFFFFFFE
>> on 64-bit systems).
>>
>> This corrupted value propagates through the call chain:
>> __arm_lpae_unmap() returns -ENOENT as size_t
>> -> arm_lpae_unmap_pages() returns it
>> -> __iommu_unmap() adds it to iova address
>> -> iommu_pgsize() triggers BUG_ON due to corrupted iova
>>
>> This can cause IOVA address overflow in __iommu_unmap() loop and
>> trigger BUG_ON in iommu_pgsize() from invalid address alignment.
>>
>> Fix by returning 0 instead of -ENOENT. The WARN_ON already signals
>> the error condition, and returning 0 (meaning "nothing unmapped")
>> is the correct semantic for size_t return type. This matches the
>> behavior of other io-pgtable implementations (io-pgtable-arm-v7s,
>> io-pgtable-dart) which return 0 on error conditions.
>>
>> Fixes: 3318f7b5cefb ("iommu/io-pgtable-arm: Add quirk to quiet WARN_ON()")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Chaitanya Kulkarni <ckulkarnilinux@gmail.com>
>> ---
>> drivers/iommu/io-pgtable-arm.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c
>> index e6626004b323..05d63fe92e43 100644
>> --- a/drivers/iommu/io-pgtable-arm.c
>> +++ b/drivers/iommu/io-pgtable-arm.c
>> @@ -637,7 +637,7 @@ static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data,
>> pte = READ_ONCE(*ptep);
>> if (!pte) {
>> WARN_ON(!(data->iop.cfg.quirks & IO_PGTABLE_QUIRK_NO_WARN));
>> - return -ENOENT;
>> + return 0;
>> }
>>
>> /* If the size matches this level, we're in the right place */
> Acked-by: Will Deacon <will@kernel.org>
>
> Joerg -- please can you pick this one up for 6.19-rc?
>
> Cheers,
>
> Will
Joerg, gentle reminder on this if this is not already applied.
In case it is please ignore this.
-ck
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-01-15 22:08 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-19 23:28 [PATCH] iommu/io-pgtable-arm: fix size_t signedness bug in unmap path Chaitanya Kulkarni
2025-12-20 14:35 ` Rob Clark
2026-01-05 19:07 ` Jason Gunthorpe
2026-01-05 21:25 ` Will Deacon
2026-01-15 22:08 ` Chaitanya Kulkarni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox