All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kristina Martšenko" <kristina.martsenko@arm.com>
Cc: "Marc Zyngier" <maz@kernel.org>,
	kvmarm@lists.linux.dev, "Oliver Upton" <oupton@kernel.org>
Subject: Re: [RFC 06/12] ACPI: TLBI: Parse domains from table
Date: Thu, 01 Oct 2026 12:04:31 +0000	[thread overview]
Message-ID: <20261001120431.A20421F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20261001110655.461473-7-kristina.martsenko@arm.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] acpi: tlbi: missing bounds check and integer overflow in structure getters
- [Medium] acpi: tlbi: memory leak of domains array on initialization error paths
- [Low] acpi: tlbi: dangling global pointer after ACPI table is unmapped
--

commit cbbbb2dad21c37d8cb180622bf2879e0d09c3f0d
Author: Kristina Martšenko <kristina.martsenko@arm.com>

ACPI: TLBI: Parse domains from table

This commit parses the Arm TLBI ACPI table to extract a hierarchy of TLBI
domains, identifying member CPUs and subdomains. It builds and validates
cpumasks for each domain so they can be used for domain management in
arm64 code.

> diff --git a/drivers/acpi/arm64/tlbi.c b/drivers/acpi/arm64/tlbi.c
> new file mode 100644
> index 0000000000000..b705a5b198426
> --- /dev/null
> +++ b/drivers/acpi/arm64/tlbi.c
> @@ -0,0 +1,188 @@

[ ... ]

> +struct acpi_table_tlbi *tlbi;
> +static struct tlbi_domain *domains;
> +static int domain_count;

[ ... ]

> +static struct acpi_tlbi_descendant *__init tlbi_get_descendant(u32 offset)
> +{
> +	struct acpi_tlbi_descendant *descendant;
> +
> +	descendant = ACPI_ADD_PTR(struct acpi_tlbi_descendant, tlbi, offset);
> +	if (descendant->length < sizeof(*descendant) ||
> +	    offset + descendant->length > tlbi->header.length)

[Severity: High]
Does this code safely access the descendant structure? If the offset
parameter provided by the ACPI table is larger than the table size,
the computed descendant pointer will point out of bounds. Reading
descendant->length before validating the offset will cause an
out-of-bounds memory read.

Additionally, since offset and descendant->length are 32-bit integers,
could the addition offset + descendant->length overflow? If a large
length is provided, the overflow could bypass this bounds check and
allow traversal into out-of-bounds memory.

> +		return NULL;
> +
> +	return descendant;
> +}
> +
> +static struct acpi_tlbi_domain *__init tlbi_get_domain(u32 offset)
> +{
> +	struct acpi_tlbi_domain *domain;
> +
> +	domain = ACPI_ADD_PTR(struct acpi_tlbi_domain, tlbi, offset);
> +	if (domain->length < sizeof(*domain) ||
> +	    offset + domain->length > tlbi->header.length)

[Severity: High]
Similarly to tlbi_get_descendant(), does this safely read domain->length?
Reading from the computed pointer before verifying the offset could cause
an out-of-bounds read, and the 32-bit addition here is also vulnerable to
integer overflow.

> +		return NULL;
> +
> +	return domain;
> +}

[ ... ]

> +static int __init parse_tlbi_table(void)
> +{
> +	struct acpi_table_header *table __free(acpi_put_table) =
> +		acpi_get_table_pointer(ACPI_SIG_TLBI, 0);
> +	u32 offset;
> +	int ret;
> +
> +	if (IS_ERR(table))
> +		return PTR_ERR(table);
> +
> +	tlbi = (struct acpi_table_tlbi *)table;

[Severity: Low]
Does this leave the global tlbi pointer dangling after the function
returns? The table variable uses the __free(acpi_put_table) cleanup
helper, which will unmap the ACPI table memory at the end of the scope.
However, the global tlbi pointer is assigned to this memory and never
cleared.

> +	if (tlbi->header.length < sizeof(*tlbi) ||
> +	    tlbi->domain_count > MAX_TLBI_DOMAINS)
> +		return -EINVAL;
> +	if (!tlbi->domain_count)
> +		return -ENOENT;
> +
> +	domain_count = tlbi->domain_count;
> +	domains = kcalloc(domain_count, sizeof(*domains), GFP_KERNEL);
> +	if (!domains)
> +		return -ENOMEM;
> +
> +	offset = tlbi->domains_offset;
> +
> +	for (int i = 0; i < domain_count; i++) {
> +		struct acpi_tlbi_domain *domain = tlbi_get_domain(offset);
> +
> +		if (!domain || domain->id > U16_MAX)
> +			return -EINVAL;

[Severity: Medium]
Do these early error paths leak the domains array and the already
allocated cpumasks? Once domains is allocated via kcalloc(), returning
directly without a cleanup path leaves the memory permanently leaked.

> +
> +		domains[i].id = domain->id;
> +		if (!zalloc_cpumask_var(&domains[i].cpus, GFP_KERNEL))
> +			return -ENOMEM;
> +
> +		ret = parse_tlbi_domain(domain, domains[i].cpus, 0);
> +		if (ret)
> +			return ret;
> +
> +		offset += domain->length;
> +	}
> +
> +	ret = validate_tlbi_domains();
> +	if (ret)
> +		return ret;
> +
> +	return 0;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261001110655.461473-1-kristina.martsenko@arm.com?part=6

  reply	other threads:[~2026-10-01 12:04 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-01 11:06 [RFC 00/12] arm64: Add support for TLBI domains Kristina Martšenko
2026-10-01 11:06 ` [RFC 01/12] arm64: sysreg: Add definitions for FEAT_TLBID Kristina Martšenko
2026-10-01 11:06 ` [RFC 02/12] arm64: Detect FEAT_TLBID Kristina Martšenko
2026-10-01 11:06 ` [RFC 03/12] KVM: arm64: Hide TLBID from guest sysregs Kristina Martšenko
2026-10-12  8:12   ` Steffen Eiden
2026-10-01 11:06 ` [RFC 04/12] KVM: arm64: Hide TLBID from guest instructions Kristina Martšenko
2026-10-01 11:06 ` [RFC 05/12] ACPICA: Add TLBI table definition Kristina Martšenko
2026-10-01 11:56   ` sashiko-bot
2026-10-01 11:06 ` [RFC 06/12] ACPI: TLBI: Parse domains from table Kristina Martšenko
2026-10-01 12:04   ` sashiko-bot [this message]
2026-10-01 11:06 ` [RFC 07/12] arm64: tlbid: Set up CPU domain bitmaps Kristina Martšenko
2026-10-01 11:06 ` [RFC 08/12] efi/arm: Check return value of init_new_context() Kristina Martšenko
2026-10-04  8:00   ` Ard Biesheuvel
2026-10-01 11:06 ` [RFC 09/12] arm64: tlbid: Track the TLBI domain of a task Kristina Martšenko
2026-10-01 11:06 ` [RFC 10/12] arm64: Support TLBIP instructions Kristina Martšenko
2026-10-01 12:40   ` sashiko-bot
2026-10-01 11:06 ` [RFC 11/12] arm64: tlbid: Pass domain to TLBI instructions Kristina Martšenko
2026-10-01 12:54   ` sashiko-bot
2026-10-01 11:06 ` [RFC 12/12] arm64: tlbid: Add documentation Kristina Martšenko
2026-10-03 16:12 ` [RFC 00/12] arm64: Add support for TLBI domains Marc Zyngier
2026-10-05  8:40   ` Oliver Upton
2026-10-04 18:06 ` Zi Yan
2026-10-05  6:29   ` Will Deacon
2026-10-05 18:13     ` Zi Yan
2026-10-05 11:07   ` Catalin Marinas

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=20261001120431.A20421F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kristina.martsenko@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=oupton@kernel.org \
    --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.