From: Sebastian Brzezinka <sebastian.brzezinka@intel.com>
To: Krzysztof Karas <krzysztof.karas@intel.com>,
<intel-gfx@lists.freedesktop.org>,
<dri-devel@lists.freedesktop.org>, <iommu@lists.linux.dev>
Cc: "Andi Shyti" <andi.shyti@linux.intel.com>,
"Robin Murphy" <robin.murphy@arm.com>,
"Jason Gunthorpe" <jgg@ziepe.ca>,
"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 v4 2/5] iommu/dma: Catch scatterlist length overflows
Date: Wed, 29 Jul 2026 14:07:16 +0200 [thread overview]
Message-ID: <DKB1JMBPFCNM.2PUIUI31WOCHF@intel.com> (raw)
In-Reply-To: <20260723102542.3245495-3-krzysztof.karas@intel.com>
Hi,
On Thu Jul 23, 2026 at 12:25 PM CEST, Krzysztof Karas wrote:
> It is possible, when a very large mapping uses only one
> 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 scatterlist
> length field.
>
> Fixes: 809eac54cdd6 ("iommu/dma: Implement scatterlist segment merging")
> Signed-off-by: Krzysztof Karas <krzysztof.karas@intel.com>
> Reviewed-by: Robin Murphy <robin.murphy@arm.com>
> ---
> v4:
> * Added value wrap check before s->length assignment (Robin);
>
> drivers/iommu/dma-iommu.c | 20 +++++++++++++++++++-
> 1 file changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
> index 381b60d9e7ce..3ca3196a41b0 100644
> --- a/drivers/iommu/dma-iommu.c
> +++ b/drivers/iommu/dma-iommu.c
> @@ -21,6 +21,7 @@
> #include <linux/iommu-dma.h>
> #include <linux/iova.h>
> #include <linux/irq.h>
> +#include <linux/limits.h>
> #include <linux/list_sort.h>
> #include <linux/memremap.h>
> #include <linux/mm.h>
> @@ -1477,6 +1478,12 @@ int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
> sg_dma_len(s) = s_length;
> s->offset -= s_iova_off;
> s_length = iova_align(iovad, s_length + s_iova_off);
> + if ((s_length & UINT_MAX) == 0) {
Might be better to go with s_length > UINT_MAX . Right now it's 64 &
32, so only the lower bits count. Or just ignore this comment it if
it's intended.
--
Best regards,
Sebastian
next prev parent reply other threads:[~2026-07-29 12:06 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-23 10:25 [PATCH v4 0/5] drivers: Improve memory management for large object allocations when i915/shmem is used with iommu Krzysztof Karas
2026-07-23 10:25 ` [PATCH v4 1/5] drm/i915/gem: Count mapped pages in a folio Krzysztof Karas
2026-07-29 11:32 ` Sebastian Brzezinka
2026-07-23 10:25 ` [PATCH v4 2/5] iommu/dma: Catch scatterlist length overflows Krzysztof Karas
2026-07-29 12:07 ` Sebastian Brzezinka [this message]
2026-07-29 12:43 ` Robin Murphy
2026-07-23 10:25 ` [PATCH v4 3/5] drm/i915/gem: Pull out size validation into a separate function Krzysztof Karas
2026-07-23 10:25 ` [PATCH v4 4/5] drm/i915/gem: Read and shrink memory in " Krzysztof Karas
2026-07-23 10:25 ` [PATCH v4 5/5] drm/i915/gem: Remove iterator and use while loop Krzysztof Karas
2026-07-23 11:39 ` ✓ i915.CI.BAT: success for drivers: Improve memory management for large object allocations when i915/shmem is used with iommu Patchwork
2026-07-24 12:38 ` ✓ i915.CI.Full: " 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=DKB1JMBPFCNM.2PUIUI31WOCHF@intel.com \
--to=sebastian.brzezinka@intel.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=jgg@ziepe.ca \
--cc=krzysztof.karas@intel.com \
--cc=krzysztof.niemiec@intel.com \
--cc=michal.grzelak@intel.com \
--cc=robin.murphy@arm.com \
/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