Skip to content

Commit f7c330a

Browse files
vfalanisJassi Brar
authored andcommitted
mailbox: mchp-ipc-sbi: fix out-of-bounds access in mchp_ipc_get_cluster_aggr_irq()
The cluster_cfg array is dynamically allocated to hold per-CPU configuration structures, with its size based on the number of online CPUs. Previously, this array was indexed using hartid, which may be non-contiguous or exceed the bounds of the array, leading to out-of-bounds access. Switch to using cpuid as the index, as it is guaranteed to be within the valid range provided by for_each_online_cpu(). Signed-off-by: Valentina Fernandez <valentina.fernandezalanis@microchip.com> Reviewed-by: Conor Dooley <conor.dooley@microchip.com> Signed-off-by: Jassi Brar <jassisinghbrar@gmail.com>
1 parent d96ebba commit f7c330a

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

drivers/mailbox/mailbox-mchp-ipc-sbi.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,20 +180,20 @@ static irqreturn_t mchp_ipc_cluster_aggr_isr(int irq, void *data)
180180
/* Find out the hart that originated the irq */
181181
for_each_online_cpu(i) {
182182
hartid = cpuid_to_hartid_map(i);
183-
if (irq == ipc->cluster_cfg[hartid].irq)
183+
if (irq == ipc->cluster_cfg[i].irq)
184184
break;
185185
}
186186

187187
status_msg.cluster = hartid;
188-
memcpy(ipc->cluster_cfg[hartid].buf_base, &status_msg, sizeof(struct mchp_ipc_status));
188+
memcpy(ipc->cluster_cfg[i].buf_base, &status_msg, sizeof(struct mchp_ipc_status));
189189

190-
ret = mchp_ipc_sbi_send(SBI_EXT_IPC_STATUS, ipc->cluster_cfg[hartid].buf_base_addr);
190+
ret = mchp_ipc_sbi_send(SBI_EXT_IPC_STATUS, ipc->cluster_cfg[i].buf_base_addr);
191191
if (ret < 0) {
192192
dev_err_ratelimited(ipc->dev, "could not get IHC irq status ret=%d\n", ret);
193193
return IRQ_HANDLED;
194194
}
195195

196-
memcpy(&status_msg, ipc->cluster_cfg[hartid].buf_base, sizeof(struct mchp_ipc_status));
196+
memcpy(&status_msg, ipc->cluster_cfg[i].buf_base, sizeof(struct mchp_ipc_status));
197197

198198
/*
199199
* Iterate over each bit set in the IHC interrupt status register (IRQ_STATUS) to identify
@@ -385,21 +385,21 @@ static int mchp_ipc_get_cluster_aggr_irq(struct mchp_ipc_sbi_mbox *ipc)
385385
if (ret <= 0)
386386
continue;
387387

388-
ipc->cluster_cfg[hartid].irq = ret;
389-
ret = devm_request_irq(ipc->dev, ipc->cluster_cfg[hartid].irq,
388+
ipc->cluster_cfg[cpuid].irq = ret;
389+
ret = devm_request_irq(ipc->dev, ipc->cluster_cfg[cpuid].irq,
390390
mchp_ipc_cluster_aggr_isr, IRQF_SHARED,
391391
"miv-ihc-irq", ipc);
392392
if (ret)
393393
return ret;
394394

395-
ipc->cluster_cfg[hartid].buf_base = devm_kmalloc(ipc->dev,
396-
sizeof(struct mchp_ipc_status),
397-
GFP_KERNEL);
395+
ipc->cluster_cfg[cpuid].buf_base = devm_kmalloc(ipc->dev,
396+
sizeof(struct mchp_ipc_status),
397+
GFP_KERNEL);
398398

399-
if (!ipc->cluster_cfg[hartid].buf_base)
399+
if (!ipc->cluster_cfg[cpuid].buf_base)
400400
return -ENOMEM;
401401

402-
ipc->cluster_cfg[hartid].buf_base_addr = __pa(ipc->cluster_cfg[hartid].buf_base);
402+
ipc->cluster_cfg[cpuid].buf_base_addr = __pa(ipc->cluster_cfg[cpuid].buf_base);
403403

404404
irq_found = true;
405405
}

0 commit comments

Comments
 (0)