irqchip/gic-v3: Memory-safety fixes on the probe paths
Subsystems (2)
v2 cover irqchip/gic-v3: Memory-safety fixes on the probe paths
Hi folks,
Changes since v1 [1]:
- Patch 3 marks the skipped CPU in broken_rdists, so it's kept offline. (Marc, sashiko)
Three probe-time bugs in the GICv3 drivers. The kernel keeps running after each of them, so the memory involved is live rather than on the way to a reset.
The first two free memory an enabled ITS still points at. Boot carries on because its_init() discards a failed probe and gic_init_bases() discards what its_init() returns. The third is a write past the end of redist_regs[] for an enabled GICC with a zero GICR base, on a MADT with no GICR entries. fa2dabe57220e's commit message says such tables exist, and I haven't seen one.
Based on Linux 7.3-rc4 (93f51579e7df2).
Cheers,
/fuad
[1] https://lore.kernel.org/all/[email protected]/
Fuad Tabba (3):
irqchip/gic-v3-its: Don't free a vPE table shared with another ITS irqchip/gic-v3-its: Don't free the tables of an enabled ITS irqchip/gic-v3: Don't register a redistributor that was never counted
drivers/irqchip/irq-gic-v3-its.c | 16 +++++++++++----- drivers/irqchip/irq-gic-v3.c | 11 +++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-)
base-commit: 93f51579e7df248780214094418f205253383cc5
Signature · 1 line
2.39.5
PATCH v2 1/3 irqchip/gic-v3-its: Don't free a vPE table shared with another ITS
On GICv4.1, its_alloc_tables() copies a sibling's vPE table baser rather than allocating one, but its_free_tables() frees it like the rest. A probe failure on the copying ITS then frees pages the enabled sibling still points GITS_BASER2 at, and the kernel comes up running on that sibling.
Mark a shared table so its_free_tables() skips it.
--- drivers/irqchip/irq-gic-v3-its.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3-its.c +5 -1
@@ -87,6 +87,8 @@ struct its_baser {u64 val;u32 order;u32 psz; +/* Inherited from a sibling ITS, not freed here */ +bool shared; };struct its_device ;
@@ -2604,7 +2606,8 @@ static void its_free_tables(struct its_node *its)for (i =0 ; i <GITS_BASER_NR_REGS ; i++) {if (its->tables[i].base) { -its_free_pages (its->tables[i].base, its->tables[i].order); +if (!its->tables[i].shared) +its_free_pages (its->tables[i].base, its->tables[i].order); its->tables[i].base =NULL ; } }
@@ -2703,6 +2706,7 @@ static int its_alloc_tables(struct its_node *its)WARN_ON (i !=2 );if ((sibling =find_sibling_its (its))) { *baser = sibling->tables[2 ]; + baser->shared = true;its_write_baser (its, baser, baser->val);continue ; }
Signature · 1 line
2.39.5
[tip: irq/drivers] irqchip/gic-v3-its: Don't free a vPE table shared with another ITS
The following commit has been merged into the irq/drivers branch of tip:
The following commit has been merged into the irq/drivers branch of tip:
Commit-ID: 496375c937cc76d36bacaf62b4d599c3ee41115d Gitweb: https://git.kernel.org/tip/496375c937cc76d36bacaf62b4d599c3ee41115d Author: Fuad Tabba <[email protected]> AuthorDate: Fri, 25 Sep 2026 09:49:58 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 15 Oct 2026 11:50:48 +02:00
irqchip/gic-v3-its: Don't free a vPE table shared with another ITS
On GICv4.1, its_alloc_tables() copies a sibling's vPE table baser rather than allocating one, but its_free_tables() frees it like the rest. A probe failure on the copying ITS then frees pages the enabled sibling still points GITS_BASER2 at, and the kernel comes up running on that sibling.
Mark a shared table so its_free_tables() skips it.
--- drivers/irqchip/irq-gic-v3-its.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3-its.c +5 -1
@@ -87,6 +87,8 @@ struct its_baser {u64 val;u32 order;u32 psz; +/* Inherited from a sibling ITS, not freed here */ +bool shared; };struct its_device ;
@@ -2605,7 +2607,8 @@ static void its_free_tables(struct its_node *its)for (i =0 ; i <GITS_BASER_NR_REGS ; i++) {if (its->tables[i].base) { -its_free_pages (its->tables[i].base, its->tables[i].order); +if (!its->tables[i].shared) +its_free_pages (its->tables[i].base, its->tables[i].order); its->tables[i].base =NULL ; } }
@@ -2704,6 +2707,7 @@ static int its_alloc_tables(struct its_node *its)WARN_ON (i !=2 );if ((sibling =find_sibling_its (its))) { *baser = sibling->tables[2 ]; + baser->shared = true;its_write_baser (its, baser, baser->val);continue ; }
[tip: irq/drivers] irqchip/gic-v3-its: Don't free a vPE table shared with another ITS
In reply to Fuad TabbaThe following commit has been merged into the irq/drivers branch of tip:
The following commit has been merged into the irq/drivers branch of tip:
Commit-ID: 32e056cc1d1582951f981113ca8b98914f29c32a Gitweb: https://git.kernel.org/tip/32e056cc1d1582951f981113ca8b98914f29c32a Author: Fuad Tabba <[email protected]> AuthorDate: Fri, 25 Sep 2026 09:49:58 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 15 Oct 2026 11:55:41 +02:00
irqchip/gic-v3-its: Don't free a vPE table shared with another ITS
On GICv4.1, its_alloc_tables() copies a sibling's vPE table baser rather than allocating one, but its_free_tables() frees it like the rest. A probe failure on the copying ITS then frees pages the enabled sibling still points GITS_BASER2 at, and the kernel comes up running on that sibling.
Mark a shared table so its_free_tables() skips it.
--- drivers/irqchip/irq-gic-v3-its.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3-its.c +5 -1
@@ -87,6 +87,8 @@ struct its_baser {u64 val;u32 order;u32 psz; +/* Inherited from a sibling ITS, not freed here */ +bool shared; };struct its_device ;
@@ -2605,7 +2607,8 @@ static void its_free_tables(struct its_node *its)for (i =0 ; i <GITS_BASER_NR_REGS ; i++) {if (its->tables[i].base) { -its_free_pages (its->tables[i].base, its->tables[i].order); +if (!its->tables[i].shared) +its_free_pages (its->tables[i].base, its->tables[i].order); its->tables[i].base =NULL ; } }
@@ -2704,6 +2707,7 @@ static int its_alloc_tables(struct its_node *its)WARN_ON (i !=2 );if ((sibling =find_sibling_its (its))) { *baser = sibling->tables[2 ]; + baser->shared = true;its_write_baser (its, baser, baser->val);continue ; }
PATCH v2 2/3 irqchip/gic-v3-its: Don't free the tables of an enabled ITS
In reply to Fuad Tabbaits_probe_one() enables the ITS before its_init_domain(), the last step that can fail, and the unwind from there frees the tables and the command queue without disabling it. The kernel comes up with an enabled ITS pointing at freed pages.
Enable the ITS last. Nothing reaches the new domain before then: this runs from init_IRQ(), and the ITS joins its_nodes only after the enable.
--- drivers/irqchip/irq-gic-v3-its.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +6 -4
@@ -5332,16 +5332,18 @@ static int __init its_probe_one(struct its_node *its) }gits_write_cwriter (0 , its->base +GITS_CWRITER ); + + err =its_init_domain (its); +if (err) + goto out_free_collection; + +/* Enable last: the unwind frees memory an enabled ITS may access */ ctlr =readl_relaxed (its->base +GITS_CTLR ); ctlr |=GITS_CTLR_ENABLE ;if (is_v4 (its)) ctlr |= GITS_CTLR_ImDe;writel_relaxed (ctlr, its->base +GITS_CTLR ); - err =its_init_domain (its); -if (err) - goto out_free_collection; -raw_spin_lock (&its_lock);list_add (&its->entry, &its_nodes);raw_spin_unlock (&its_lock);
Signature · 1 line
2.39.5
[tip: irq/drivers] irqchip/gic-v3-its: Don't free the tables of an enabled ITS
The following commit has been merged into the irq/drivers branch of tip:
The following commit has been merged into the irq/drivers branch of tip:
Commit-ID: a5b8c23c5c93438d62f81a034fa4e39001d283fb Gitweb: https://git.kernel.org/tip/a5b8c23c5c93438d62f81a034fa4e39001d283fb Author: Fuad Tabba <[email protected]> AuthorDate: Fri, 25 Sep 2026 09:49:59 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 15 Oct 2026 11:50:48 +02:00
irqchip/gic-v3-its: Don't free the tables of an enabled ITS
its_probe_one() enables the ITS before its_init_domain(), the last step that can fail, and the unwind from there frees the tables and the command queue without disabling it. The kernel comes up with an enabled ITS pointing at freed pages.
Enable the ITS last. Nothing reaches the new domain before then: this runs from init_IRQ(), and the ITS joins its_nodes only after the enable.
--- drivers/irqchip/irq-gic-v3-its.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +6 -4
@@ -5337,16 +5337,18 @@ static int __init its_probe_one(struct its_node *its) }gits_write_cwriter (0 , its->base +GITS_CWRITER ); + + err =its_init_domain (its); +if (err) + goto out_free_collection; + +/* Enable last: the unwind frees memory an enabled ITS may access */ ctlr =readl_relaxed (its->base +GITS_CTLR ); ctlr |=GITS_CTLR_ENABLE ;if (is_v4 (its)) ctlr |= GITS_CTLR_ImDe;writel_relaxed (ctlr, its->base +GITS_CTLR ); - err =its_init_domain (its); -if (err) - goto out_free_collection; -raw_spin_lock (&its_lock);list_add (&its->entry, &its_nodes);raw_spin_unlock (&its_lock);
[tip: irq/drivers] irqchip/gic-v3-its: Don't free the tables of an enabled ITS
In reply to Fuad TabbaThe following commit has been merged into the irq/drivers branch of tip:
The following commit has been merged into the irq/drivers branch of tip:
Commit-ID: d09b36d8e0e60f35bd1cd7d63aadc6dfad61700c Gitweb: https://git.kernel.org/tip/d09b36d8e0e60f35bd1cd7d63aadc6dfad61700c Author: Fuad Tabba <[email protected]> AuthorDate: Fri, 25 Sep 2026 09:49:59 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 15 Oct 2026 11:55:41 +02:00
irqchip/gic-v3-its: Don't free the tables of an enabled ITS
its_probe_one() enables the ITS before its_init_domain(), the last step that can fail, and the unwind from there frees the tables and the command queue without disabling it. The kernel comes up with an enabled ITS pointing at freed pages.
Enable the ITS last. Nothing reaches the new domain before then: this runs from init_IRQ(), and the ITS joins its_nodes only after the enable.
--- drivers/irqchip/irq-gic-v3-its.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +6 -4
@@ -5337,16 +5337,18 @@ static int __init its_probe_one(struct its_node *its) }gits_write_cwriter (0 , its->base +GITS_CWRITER ); + + err =its_init_domain (its); +if (err) + goto out_free_collection; + +/* Enable last: the unwind frees memory an enabled ITS may access */ ctlr =readl_relaxed (its->base +GITS_CTLR ); ctlr |=GITS_CTLR_ENABLE ;if (is_v4 (its)) ctlr |= GITS_CTLR_ImDe;writel_relaxed (ctlr, its->base +GITS_CTLR ); - err =its_init_domain (its); -if (err) - goto out_free_collection; -raw_spin_lock (&its_lock);list_add (&its->entry, &its_nodes);raw_spin_unlock (&its_lock);
PATCH v2 3/3 irqchip/gic-v3: Don't register a redistributor that was never counted
In reply to Fuad Tabbagic_acpi_match_gicc() counts only the enabled GICCs with a non-zero gicr_base_address, and that count sizes redist_regs[], but gic_acpi_parse_madt_gicc() registers every enabled one. On a MADT with no GICR entries, an enabled GICC with a zero GICR base therefore makes gic_acpi_register_redist() write a struct redist_region past the end of the array.
Commit fa2dabe57220e ("irqchip/gic-v3: Don't return errors from gic_acpi_match_gicc()") removed the check that kept the two consistent. Its message says such entries are still caught by gic_populate_rdist(), but that runs from gic_cpu_init(), after the write.
Skip the entry instead, and mark the CPU's redistributor broken as the online-capable path does, so that gic_check_rdist() rejects the CPU. gic_starting_cpu() runs past cpuhp's last failure point, so without the mark the CPU would come online with its redistributor and CPU interface unconfigured. With an ITS, its_cpu_init() would then dereference a NULL rd_base.
--- drivers/irqchip/irq-gic-v3.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/irqchip/irq-gic-v3.c +11 -0
@@ -2344,6 +2344,17 @@ gic_acpi_parse_madt_gicc(union acpi_subtable_headers *header,return 0 ; } +/* Not counted by gic_acpi_match_gicc(), so there is no slot for it */ +if (!gicc->gicr_base_address) { +int cpu =get_cpu_for_acpi_id (gicc->uid); + +pr_warn (FW_BUG "GICC entry with ACPI UID %u has no GICR base address, CPU kept offline\n" , + gicc->uid); +if (cpu >=0 ) +cpumask_set_cpu (cpu, &broken_rdists); +return 0 ; + } + redist_base =ioremap (gicc->gicr_base_address, size);if (!redist_base)return -ENOMEM ;
Signature · 1 line
2.39.5
[tip: irq/drivers] irqchip/gic-v3: Don't register a redistributor that was never counted
The following commit has been merged into the irq/drivers branch of tip:
The following commit has been merged into the irq/drivers branch of tip:
Commit-ID: 7bcd2fa22186587e06c456d1c2e3d336c83136f6 Gitweb: https://git.kernel.org/tip/7bcd2fa22186587e06c456d1c2e3d336c83136f6 Author: Fuad Tabba <[email protected]> AuthorDate: Fri, 25 Sep 2026 09:50:00 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 15 Oct 2026 11:50:48 +02:00
irqchip/gic-v3: Don't register a redistributor that was never counted
gic_acpi_match_gicc() counts only the enabled GICCs with a non-zero gicr_base_address, and that count sizes redist_regs[], but gic_acpi_parse_madt_gicc() registers every enabled one. On a MADT with no GICR entries, an enabled GICC with a zero GICR base therefore makes gic_acpi_register_redist() write a struct redist_region past the end of the array.
Commit fa2dabe57220e ("irqchip/gic-v3: Don't return errors from gic_acpi_match_gicc()") removed the check that kept the two consistent. Its message says such entries are still caught by gic_populate_rdist(), but that runs from gic_cpu_init(), after the write.
Skip the entry instead, and mark the CPU's redistributor broken as the online-capable path does, so that gic_check_rdist() rejects the CPU. gic_starting_cpu() runs past cpuhp's last failure point, so without the mark the CPU would come online with its redistributor and CPU interface unconfigured. With an ITS, its_cpu_init() would then dereference a NULL rd_base.
--- drivers/irqchip/irq-gic-v3.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/irqchip/irq-gic-v3.c +11 -0
@@ -2344,6 +2344,17 @@ gic_acpi_parse_madt_gicc(union acpi_subtable_headers *header,return 0 ; } +/* Not counted by gic_acpi_match_gicc(), so there is no slot for it */ +if (!gicc->gicr_base_address) { +int cpu =get_cpu_for_acpi_id (gicc->uid); + +pr_warn (FW_BUG "GICC entry with ACPI UID %u has no GICR base address, CPU kept offline\n" , + gicc->uid); +if (cpu >=0 ) +cpumask_set_cpu (cpu, &broken_rdists); +return 0 ; + } + redist_base =ioremap (gicc->gicr_base_address, size);if (!redist_base)return -ENOMEM ;
[tip: irq/drivers] irqchip/gic-v3: Don't register a redistributor that was never counted
In reply to Fuad TabbaThe following commit has been merged into the irq/drivers branch of tip:
The following commit has been merged into the irq/drivers branch of tip:
Commit-ID: 6a21693b97ee5cb0a21d04bfd051a05dde5aa783 Gitweb: https://git.kernel.org/tip/6a21693b97ee5cb0a21d04bfd051a05dde5aa783 Author: Fuad Tabba <[email protected]> AuthorDate: Fri, 25 Sep 2026 09:50:00 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 15 Oct 2026 11:55:41 +02:00
irqchip/gic-v3: Don't register a redistributor that was never counted
gic_acpi_match_gicc() counts only the enabled GICCs with a non-zero gicr_base_address, and that count sizes redist_regs[], but gic_acpi_parse_madt_gicc() registers every enabled one. On a MADT with no GICR entries, an enabled GICC with a zero GICR base therefore makes gic_acpi_register_redist() write a struct redist_region past the end of the array.
Commit fa2dabe57220e ("irqchip/gic-v3: Don't return errors from gic_acpi_match_gicc()") removed the check that kept the two consistent. Its message says such entries are still caught by gic_populate_rdist(), but that runs from gic_cpu_init(), after the write.
Skip the entry instead, and mark the CPU's redistributor broken as the online-capable path does, so that gic_check_rdist() rejects the CPU. gic_starting_cpu() runs past cpuhp's last failure point, so without the mark the CPU would come online with its redistributor and CPU interface unconfigured. With an ITS, its_cpu_init() would then dereference a NULL rd_base.
--- drivers/irqchip/irq-gic-v3.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/irqchip/irq-gic-v3.c +11 -0
@@ -2344,6 +2344,17 @@ gic_acpi_parse_madt_gicc(union acpi_subtable_headers *header,return 0 ; } +/* Not counted by gic_acpi_match_gicc(), so there is no slot for it */ +if (!gicc->gicr_base_address) { +int cpu =get_cpu_for_acpi_id (gicc->uid); + +pr_warn (FW_BUG "GICC entry with ACPI UID %u has no GICR base address, CPU kept offline\n" , + gicc->uid); +if (cpu >=0 ) +cpumask_set_cpu (cpu, &broken_rdists); +return 0 ; + } + redist_base =ioremap (gicc->gicr_base_address, size);if (!redist_base)return -ENOMEM ;
Quoted 30 lines · Fuad Tabba
Hi folks,
Changes since v1 [1]:
- Patch 3 marks the skipped CPU inbroken_rdists, so it's kept offline. (Marc, sashiko)Three probe-time bugs in the GICv3 drivers. The kernel keeps running after each of them, so the memory involved is live rather than on the way to a reset.
The first two free memory an enabled ITS still points at. Boot carries on because
its_init()discards a failed probe andgic_init_bases()discards whatits_init()returns. The third is a write past the end of redist_regs[] for an enabled GICC with a zero GICR base, on a MADT with no GICR entries. fa2dabe57220e's commit message says such tables exist, and I haven't seen one.Based on Linux 7.3-rc4 (
93f51579e7df2).Cheers,
/fuad[1] https://lore.kernel.org/all/[email protected]/
Fuad Tabba (3):
irqchip/gic-v3-its: Don't free a vPE table shared with another ITS irqchip/gic-v3-its: Don't free the tables of an enabled ITS irqchip/gic-v3: Don't register a redistributor that was never counted
Quoted 6 lines
drivers/irqchip/irq-gic-v3-its.c | 16 +++++++++++----- drivers/irqchip/irq-gic-v3.c | 11 +++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-)base-commit:
93f51579e7df248780214094418f205253383cc5
M.
Signature · 1 line
Jazz isn't dead. It just smells funny.
Hi Thomas,
Gentle ping on this series, which Marc has reviewed, and on the lifetime and range fixes [1], which he has also reviewed.
Cheers,
/fuad
Thomas Gleixner
maintainerQuoted 4 lines · Fuad Tabba
Hi Thomas,
Gentle ping on this series, which Marc has reviewed, and on the lifetime and range fixes [1], which he has also reviewed.
All of that is in my todo list which contains the backlog of vacation and conference travel. I'll get there in the foreseeable future...