From: Baolu Lu <baolu.lu@linux.intel.com>
To: Shirong Zhao <shxzhaosr@163.com>,
dwmw2@infradead.org, joro@8bytes.org, will@kernel.org
Cc: baolu.lu@linux.intel.com, robin.murphy@arm.com,
iommu@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iommu: intel: Apply the device scope length check to every device scope walk
Date: Fri, 16 Oct 2026 08:45:09 +0800 [thread overview]
Message-ID: <0ba4e7ba-c412-44ca-837c-13075d745843@linux.intel.com> (raw)
In-Reply-To: <20261012084102.18-1-shxzhaosr@163.com>
On 10/12/2026 4:41 PM, Shirong Zhao wrote:
> dmar_walk_remapping_entries() already refuses to step by a zero length:
>
> next = (void *)iter + iter->length;
> if (iter->length == 0) {
> /* Avoid looping forever on bad ACPI tables */
> pr_debug(FW_BUG "Invalid 0-length structure\n");
> break;
> }
>
> Five walks over the same DMAR structures do not:
>
> dmar_alloc_dev_scope() - counts namespace/endpoint/bridge scopes
> dmar_insert_dev_scope() - attaches a scope to a PCI path
> dmar_acpi_insert_dev_scope() - same, by ANDD enumeration id
> dmar_acpi_dev_scope_init() - the ANDD entries at the end of the table
> ir_parse_ioapic_hpet_scope() - IOAPIC and HPET scopes
>
> Each advances its cursor by a length read out of the DMAR table, and
> nothing constrains it. A zero length leaves the cursor where it is and
> the walk never ends; a short one steps through table payload a byte at a
> time, reinterpreting it as scopes. dmar_alloc_dev_scope() and
> dmar_acpi_dev_scope_init() run on every boot with the IOMMU enabled, and a
> short length in the latter hands andd->device_name to acpi_get_handle().
>
> Use the check dmar_walk_remapping_entries() already uses.
>
> Checked against torvalds/linux at HEAD; both files are unmodified there.
>
> Found by EFSM.R17, which reports a loop whose cursor advances by a step
> memory can supply as zero while the exit condition depends on that cursor.
> Signed-off-by: Shirong Zhao<shxzhaosr@163.com>
>
> ---
> drivers/iommu/intel/dmar.c | 16 ++++++++++++++++
> drivers/iommu/intel/irq_remapping.c | 5 +++++
> 2 files changed, 21 insertions(+)
A zero length is never valid under the VT-d spec, so such a DMAR table
is a firmware bug.
The existing check in dmar_walk_remapping_entries() already rejects a
zero-length top-level structure before any of these walks run, and I'm
not aware of any shipping platform with a malformed device scope.
Without a real-world report, I'd rather not add more checks for this.
Thanks for looking at this, though.
Thanks,
baolu
prev parent reply other threads:[~2026-10-16 0:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-12 8:41 Shirong Zhao
2026-10-16 0:45 ` Baolu Lu [this message]
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=0ba4e7ba-c412-44ca-837c-13075d745843@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=dwmw2@infradead.org \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robin.murphy@arm.com \
--cc=shxzhaosr@163.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
all inboxes | Powered by JetHome®