From: Robin Murphy <robin.murphy@arm.com>
To: Krzysztof Karas <krzysztof.karas@intel.com>
Cc: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
iommu@lists.linux.dev, "Joerg Roedel" <joro@8bytes.org>,
"Will Deacon" <will@kernel.org>,
"Andi Shyti" <andi.shyti@linux.intel.com>,
"Michał Grzelak" <michal.grzelak@intel.com>,
"Janusz Krzysztofik" <janusz.krzysztofik@linux.intel.com>,
"Sebastian Brzezinka" <sebastian.brzezinka@intel.com>,
"Krzysztof Niemiec" <krzysztof.niemiec@intel.com>
Subject: Re: [PATCH v2 3/3] drivers/iommu: Catch scatterlist length overflows
Date: Thu, 2 Jul 2026 13:17:23 +0100 [thread overview]
Message-ID: <73b486cb-e082-4c3e-a193-6629960efede@arm.com> (raw)
In-Reply-To: <bbh4gbq6eolkqwhcuou2fufcbpthxklb2nmawglhhxdzea6tpg@2j7xekrl64pj>
On 02/07/2026 7:22 am, Krzysztof Karas wrote:
> Hi Robin,
>
> thanks for a quick response!
>
> On 2026-07-01 at 12:59:29 +0100, Robin Murphy wrote:
>> On 01/07/2026 11:44 am, Krzysztof Karas wrote:
>>> It is possible, when a very large mapping uses a single
>>> scatterlist, that padding overflows scatterlist's length field.
>>> This results in:
>>> 1) silently wrapping the value
>>> 2) smaller than desired mappings produced by iommu_map_sg
>>> 3) leaving mapped bytes in memory (no iommu_unmap)
>>>
>>> Address this issue by adding overflow detection for previous
>>> scatterlist length field.
>>
>> Awesome, thanks for figuring it out! Looks like this must date all the way
>> back:
>>
>> Fixes: 809eac54cdd6 ("iommu/dma: Implement scatterlist segment merging")
> Okay, thanks for pinpointing this commit, I'll add the tag in
> the next version of this series.
>
>>
>>> Signed-off-by: Krzysztof Karas <krzysztof.karas@intel.com>
>>> ---
>>> v2:
>>> * Address overflows instead of unmapping erroneously mapped
>>> memory (Robin).
>>> * Put this patch last for easier reproduction of the issue.
>>>
>>> drivers/iommu/dma-iommu.c | 14 ++++++++++++--
>>> 1 file changed, 12 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
>>> index 9abaec0703ef..c403057577df 100644
>>> --- a/drivers/iommu/dma-iommu.c
>>> +++ b/drivers/iommu/dma-iommu.c
>>> @@ -1493,8 +1493,18 @@ int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
>>> * time through here (i.e. before it has a meaningful value).
>>> */
>>> if (pad_len && pad_len < s_length - 1) {
>>> - prev->length += pad_len;
>>> - iova_len += pad_len;
>>> + if (overflows_type(prev->length + pad_len, prev->length)) {
>>> + /*
>>> + * For large mappings spanning multiple GBs we
>>> + * may not be able to fit all needed padding into
>>> + * sg->length.
>>> + */
>>> + ret = -EOVERFLOW;
>>> + goto out_restore_sg;
>>> + } else {
>>
>> Nit: we don't really need an "else" after a goto, but it's hardly a big deal
>> (however if you did want to respin, note also that the preferred title tag
>> here is "iommu/dma: ...").
> I'll be making another version anyway, so I can remove the
> "else" and change the title :)
Cool :)
>> Either way,
>>
>> Reviewed-by: Robin Murphy <robin.murphy@arm.com>
> Thanks!
>
> would this r-b still hold after above minor changes, or would
> you prefer to have one final look at the finished change and
> then decide whether you give your r-b?
Indeed if it's just those tweaks then feel free to keep it, that's
usually what I mean by "either way".
Cheers,
Robin.
>
>>
>> I'd imagine Joerg can take this as an IOMMU fix, but FWIW if you did want an
>> ack to take it through drm-fixes to keep it with the i915 patches, I
>> wouldn't foresee any significant risk of conflicts.
>>
>> Thanks,
>> Robin.
>>
>>> + prev->length += pad_len;
>>> + iova_len += pad_len;
>>> + }
>>> }
>>> iova_len += s_length;
>>
>
next prev parent reply other threads:[~2026-07-02 12:17 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-01 10:44 [PATCH v2 0/3] drivers: Improve memory management for large object allocations when i915/shmem is used with iommu Krzysztof Karas
2026-07-01 10:44 ` [PATCH v2 1/3] drm/i915/gem: split shared memory allocation table logic Krzysztof Karas
2026-07-01 14:38 ` Andi Shyti
2026-07-02 6:18 ` Krzysztof Karas
2026-07-02 12:01 ` Robin Murphy
2026-07-01 10:44 ` [PATCH v2 2/3] drm/i915/shmem: Count mapped pages in a folio Krzysztof Karas
2026-07-01 10:44 ` [PATCH v2 3/3] drivers/iommu: Catch scatterlist length overflows Krzysztof Karas
2026-07-01 11:59 ` Robin Murphy
2026-07-02 6:22 ` Krzysztof Karas
2026-07-02 12:17 ` Robin Murphy [this message]
[not found] ` <20260703162236.GX7525@ziepe.ca>
2026-07-03 18:58 ` Robin Murphy
[not found] ` <20260703203502.GC1978949@ziepe.ca>
2026-07-06 7:43 ` Krzysztof Karas
2026-07-06 13:08 ` Robin Murphy
[not found] ` <20260706144546.GE107792@ziepe.ca>
2026-07-09 7:18 ` Krzysztof Karas
2026-07-01 15:36 ` [PATCH v2 0/3] drivers: Improve memory management for large object allocations when i915/shmem is used with iommu Andi Shyti
2026-07-02 6:10 ` Krzysztof Karas
2026-07-01 15:44 ` ✓ i915.CI.BAT: success for drivers: Improve memory management for large object allocations when i915/shmem is used with iommu (rev3) Patchwork
2026-07-02 6:33 ` ✓ i915.CI.Full: " Patchwork
2026-07-09 8:23 ` ✗ i915.CI.BAT: failure for drivers: Improve memory management for large object allocations when i915/shmem is used with iommu (rev4) Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=73b486cb-e082-4c3e-a193-6629960efede@arm.com \
--to=robin.murphy@arm.com \
--cc=andi.shyti@linux.intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=iommu@lists.linux.dev \
--cc=janusz.krzysztofik@linux.intel.com \
--cc=joro@8bytes.org \
--cc=krzysztof.karas@intel.com \
--cc=krzysztof.niemiec@intel.com \
--cc=michal.grzelak@intel.com \
--cc=sebastian.brzezinka@intel.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox