From: sashiko-bot@kernel.org
To: "Krzysztof Karas" <krzysztof.karas@intel.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2 3/3] drivers/iommu: Catch scatterlist length overflows
Date: Wed, 01 Jul 2026 10:59:23 +0000 [thread overview]
Message-ID: <20260701105923.C341D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260701104437.236979-4-krzysztof.karas@intel.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The newly added `overflows_type` check fails to detect integer overflow on 32-bit architectures.
- [Medium] Explicitly assigned error code `-EOVERFLOW` is dead code because it is unconditionally clobbered by the cleanup path.
--
commit 97ce5598e53bd4b56cac94c57bc68e63d7d39019
Author: Krzysztof Karas <krzysztof.karas@intel.com>
drivers/iommu: Catch scatterlist length overflows
This commit adds an overflow check to prevent scatterlist length fields
from silently wrapping when adding padding for large mappings. This helps
avoid truncated mappings and memory leaks in the IOMMU layer.
> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
> index e8d4c2dac4da8..02ff84e9c0427 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)) {
[Severity: High]
Does this check work correctly on 32-bit architectures?
Because prev->length + pad_len is evaluated before the macro checks it, on a
32-bit architecture this addition will silently wrap before overflows_type
receives it. The macro would then check if the already-wrapped 32-bit value
fits into a 32-bit integer, which trivially succeeds.
Would it be better to use check_add_overflow(prev->length, pad_len,
&prev->length) here instead?
> + /*
> + * 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;
[Severity: Medium]
Will this -EOVERFLOW error code ever actually be returned?
Looking at the error handling path at the end of iommu_dma_map_sg():
out_restore_sg:
__invalidate_sg(sg, nents);
out:
if (ret != -ENOMEM && ret != -EREMOTEIO)
return -EINVAL;
return ret;
It appears the explicitly assigned -EOVERFLOW is unconditionally clobbered
and replaced by -EINVAL.
> + } else {
> + prev->length += pad_len;
> + iova_len += pad_len;
> + }
> }
>
> iova_len += s_length;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260701104437.236979-1-krzysztof.karas@intel.com?part=3
next prev parent reply other threads:[~2026-07-01 10:59 UTC|newest]
Thread overview: 24+ 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 10:59 ` sashiko-bot [this message]
2026-07-01 11:59 ` Robin Murphy
2026-07-02 6:22 ` Krzysztof Karas
2026-07-02 12:17 ` Robin Murphy
2026-07-03 16:22 ` Jason Gunthorpe
2026-07-03 18:58 ` Robin Murphy
2026-07-03 20:35 ` Jason Gunthorpe
2026-07-06 7:43 ` Krzysztof Karas
2026-07-06 12:31 ` Jason Gunthorpe
2026-07-06 13:08 ` Robin Murphy
2026-07-06 14:45 ` Jason Gunthorpe
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=20260701105923.C341D1F000E9@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.