All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Krzysztof Karas" <krzysztof.karas@intel.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v4 2/5] iommu/dma: Catch scatterlist length overflows
Date: Thu, 23 Jul 2026 11:01:15 +0000	[thread overview]
Message-ID: <20260723110115.857041F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260723102542.3245495-3-krzysztof.karas@intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] The newly added scatterlist length overflow check `(s_length & UINT_MAX) == 0` is mathematically flawed. It fails to catch integer overflow on both 32-bit and 64-bit systems, leaving the critical truncation bug unpatched, and introduces a regression by falsely rejecting legitimate zero-length mappings.
--

--- Patch [2]: [PATCH v4 2/5] iommu/dma: Catch scatterlist length overflows ---
commit 4c74567e86992a6211d4380e8e5bea4668d3e722
Author: Krzysztof Karas <krzysztof.karas@intel.com>

iommu/dma: Catch scatterlist length overflows

It is possible, when a very large mapping uses only one scatterlist,
that padding overflows scatterlist's length field. This results in
silently wrapping the value, smaller than desired mappings, and leaving
mapped bytes in memory. This commit addresses this issue by adding
overflow detection.

> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
> index 9abaec0703efb..5be5d1f3c9f82 100644
> --- a/drivers/iommu/dma-iommu.c
> +++ b/drivers/iommu/dma-iommu.c
> @@ -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) {

[Severity: Critical]
Does this check actually catch integer overflows?

On 64-bit systems, s_length is a size_t, so this bitwise AND merely checks
if the lowest 32 bits are exactly zero. It will fail to detect an overflow
unless the aligned size is an exact multiple of 4GB.

On 32-bit systems, s_length + s_iova_off wraps before this check, so
s_length would just be a small wrapped value and bypass the check entirely.

Additionally, won't this incorrectly reject legitimate zero-length mappings?

If the overflow check is bypassed on a 64-bit system, s_length is truncated
to 32 bits when assigned to s->length below. iommu_map_sg() will then map
the truncated size while iova_len accumulates the full 64-bit size. The
partial mapping will trigger the error path later in the function:

	ret = iommu_map_sg(domain, iova, sg, nents, prot, GFP_ATOMIC);
	if (ret < 0 || ret < iova_len)
		goto out_free_iova;

	return __finalise_sg(dev, sg, nents, iova);

out_free_iova:
	iommu_dma_free_iova(domain, iova, iova_len, NULL);

This frees the IOVA back to the allocator without calling iommu_unmap(),
leaving the pages mapped and potentially causing device isolation breakdown
when the IOVA is reallocated.

> +			/* Prevent possible wrapping upon assignment to s->length. */
> +			ret = -EOVERFLOW;
> +			goto out_restore_sg;
> +		}
> +
>  		s->length = s_length;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260723102542.3245495-1-krzysztof.karas@intel.com?part=2

  reply	other threads:[~2026-07-23 11:01 UTC|newest]

Thread overview: 12+ 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-23 10:51   ` sashiko-bot
2026-07-23 10:25 ` [PATCH v4 2/5] iommu/dma: Catch scatterlist length overflows Krzysztof Karas
2026-07-23 11:01   ` sashiko-bot [this message]
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 11:14   ` sashiko-bot
2026-07-23 10:25 ` [PATCH v4 4/5] drm/i915/gem: Read and shrink memory in " Krzysztof Karas
2026-07-23 11:26   ` sashiko-bot
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   ` sashiko-bot
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

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=20260723110115.857041F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=krzysztof.karas@intel.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.