Skip to content

Commit 8072908

Browse files
committed
irqchip/gic-v4: Don't allow a VMOVP on a dying VPE
jira LE-2177 cve CVE-2024-50192 Rebuild_History Non-Buildable kernel-5.14.0-503.19.1.el9_5 commit-author Marc Zyngier <maz@kernel.org> commit 1442ee0 Kunkun Jiang reported that there is a small window of opportunity for userspace to force a change of affinity for a VPE while the VPE has already been unmapped, but the corresponding doorbell interrupt still visible in /proc/irq/. Plug the race by checking the value of vmapp_count, which tracks whether the VPE is mapped ot not, and returning an error in this case. This involves making vmapp_count common to both GICv4.1 and its v4.0 ancestor. Fixes: 64edfaa ("irqchip/gic-v4.1: Implement the v4.1 flavour of VMAPP") Reported-by: Kunkun Jiang <jiangkunkun@huawei.com> Signed-off-by: Marc Zyngier <maz@kernel.org> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/c182ece6-2ba0-ce4f-3404-dba7a3ab6c52@huawei.com Link: https://lore.kernel.org/all/20241002204959.2051709-1-maz@kernel.org (cherry picked from commit 1442ee0) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent 8b484ed commit 8072908

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

drivers/irqchip/irq-gic-v3-its.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,8 @@ static struct its_vpe *its_build_vmapp_cmd(struct its_node *its,
794794
its_encode_valid(cmd, desc->its_vmapp_cmd.valid);
795795

796796
if (!desc->its_vmapp_cmd.valid) {
797+
alloc = !atomic_dec_return(&desc->its_vmapp_cmd.vpe->vmapp_count);
797798
if (is_v4_1(its)) {
798-
alloc = !atomic_dec_return(&desc->its_vmapp_cmd.vpe->vmapp_count);
799799
its_encode_alloc(cmd, alloc);
800800
}
801801

@@ -809,13 +809,13 @@ static struct its_vpe *its_build_vmapp_cmd(struct its_node *its,
809809
its_encode_vpt_addr(cmd, vpt_addr);
810810
its_encode_vpt_size(cmd, LPI_NRBITS - 1);
811811

812+
alloc = !atomic_fetch_inc(&desc->its_vmapp_cmd.vpe->vmapp_count);
813+
812814
if (!is_v4_1(its))
813815
goto out;
814816

815817
vconf_addr = virt_to_phys(page_address(desc->its_vmapp_cmd.vpe->its_vm->vprop_page));
816818

817-
alloc = !atomic_fetch_inc(&desc->its_vmapp_cmd.vpe->vmapp_count);
818-
819819
its_encode_alloc(cmd, alloc);
820820

821821
/*
@@ -3820,6 +3820,13 @@ static int its_vpe_set_affinity(struct irq_data *d,
38203820
int from, cpu = cpumask_first(mask_val);
38213821
unsigned long flags;
38223822

3823+
/*
3824+
* Check if we're racing against a VPE being destroyed, for
3825+
* which we don't want to allow a VMOVP.
3826+
*/
3827+
if (!atomic_read(&vpe->vmapp_count))
3828+
return -EINVAL;
3829+
38233830
/*
38243831
* Changing affinity is mega expensive, so let's be as lazy as
38253832
* we can and only do it if we really have to. Also, if mapped
@@ -4453,9 +4460,8 @@ static int its_vpe_init(struct its_vpe *vpe)
44534460
raw_spin_lock_init(&vpe->vpe_lock);
44544461
vpe->vpe_id = vpe_id;
44554462
vpe->vpt_page = vpt_page;
4456-
if (gic_rdists->has_rvpeid)
4457-
atomic_set(&vpe->vmapp_count, 0);
4458-
else
4463+
atomic_set(&vpe->vmapp_count, 0);
4464+
if (!gic_rdists->has_rvpeid)
44594465
vpe->vpe_proxy_event = -1;
44604466

44614467
return 0;

include/linux/irqchip/arm-gic-v4.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ struct its_vpe {
5858
bool enabled;
5959
bool group;
6060
} sgi_config[16];
61-
atomic_t vmapp_count;
6261
};
6362
};
6463

64+
/* Track the VPE being mapped */
65+
atomic_t vmapp_count;
66+
6567
/*
6668
* Ensures mutual exclusion between affinity setting of the
6769
* vPE and vLPI operations using vpe->col_idx.

0 commit comments

Comments
 (0)