* [PATCH] scsi: arcmsr: Fix potential DMA leaks on XOR allocation failure
@ 2026-11-17 14:51 Guangshuo Li
2026-11-17 15:17 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Guangshuo Li @ 2026-11-17 14:51 UTC (permalink / raw)
To: James E.J. Bottomley, Martin K. Petersen; +Cc: linux-scsi, linux-kernel
XOR allocation failure is returned after the CCB pool has been allocated,
but probe skips pool cleanup on this error. Free the pool before returning
and handle a failed XOR header allocation without dereferencing it.
This issue was found by our static analysis tool under development.
Fixes: 14ef4b001ae7 ("scsi: arcmsr: Support new RAID controller ARC-1688")
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
drivers/scsi/arcmsr/arcmsr_hba.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
index 8aa948f06cac..52caa800397e 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -771,6 +771,10 @@ static int arcmsr_alloc_xor_buffer(struct AdapterControlBlock *acb)
(sizeof(struct XorHandle) * acb->xor_mega);
dma_coherent = dma_alloc_coherent(&pdev->dev, acb->init2cfg_size,
&dma_coherent_handle, GFP_KERNEL);
+ if (!dma_coherent) {
+ acb->xor_mega = 0;
+ return -ENOMEM;
+ }
acb->xorVirt = dma_coherent;
acb->xorPhys = dma_coherent_handle;
pXorPhys = (struct Xor_sg *)((unsigned long)dma_coherent +
@@ -895,8 +899,10 @@ static int arcmsr_alloc_ccb_pool(struct AdapterControlBlock *acb)
break;
}
if ((acb->firm_PicStatus >> 24) & 0x0f) {
- if (arcmsr_alloc_xor_buffer(acb))
+ if (arcmsr_alloc_xor_buffer(acb)) {
+ arcmsr_free_ccb_pool(acb);
return -ENOMEM;
+ }
}
return 0;
}
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] scsi: arcmsr: Fix potential DMA leaks on XOR allocation failure
2026-11-17 14:51 [PATCH] scsi: arcmsr: Fix potential DMA leaks on XOR allocation failure Guangshuo Li
@ 2026-11-17 15:17 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-17 15:17 UTC (permalink / raw)
To: Guangshuo Li; +Cc: linux-scsi
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] scsi: arcmsr: hardware-controlled pointer dereference in
arcmsr_ccb_complete() [1]
--
commit 5ed92826e96263be26f2281fb2284bdbe1e52cb8
Author: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
scsi: arcmsr: Fix potential DMA leaks on XOR allocation failure
This commit checks for DMA allocation failure in arcmsr_alloc_xor_buffer()
and frees the CCB pool in arcmsr_alloc_ccb_pool() if XOR buffer allocation
fails.
> diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
> index 8aa948f06cacf..52caa800397e3 100644
> --- a/drivers/scsi/arcmsr/arcmsr_hba.c
> +++ b/drivers/scsi/arcmsr/arcmsr_hba.c
[ ... ]
> @@ -895,8 +899,10 @@ static int arcmsr_alloc_ccb_pool(struct AdapterControlBlock *acb)
> break;
> }
> if ((acb->firm_PicStatus >> 24) & 0x0f) {
> - if (arcmsr_alloc_xor_buffer(acb))
> + if (arcmsr_alloc_xor_buffer(acb)) {
> + arcmsr_free_ccb_pool(acb);
> return -ENOMEM;
> + }
> }
> return 0;
> }
[Severity: Critical]
This problem wasn't introduced by this patch, but can a compromised or
malicious PCI device overwrite the kernel pointers embedded in struct
CommandControlBlock [1]?
arcmsr_alloc_ccb_pool() allocates the CommandControlBlock array in
DMA-coherent memory via dma_alloc_coherent(), and those structures hold
host pointers including ccb->acb, ccb->pcmd, and ccb->list:
drivers/scsi/arcmsr/arcmsr_hba.c:arcmsr_alloc_ccb_pool() {
...
dma_coherent = dma_alloc_coherent(&pdev->dev, acb->uncache_size, &dma_coherent_handle, GFP_KERNEL);
...
ccb_tmp = dma_coherent;
...
for(i = 0; i < acb->maxFreeCCB; i++){
...
ccb_tmp->acb = acb;
...
INIT_LIST_HEAD(&ccb_tmp->list);
...
}
On I/O completion, arcmsr_ccb_complete() trusts those device-accessible
fields and passes them to atomic_dec(), scsi_dma_unmap(),
spin_lock_irqsave(), list_add_tail(), and scsi_done():
drivers/scsi/arcmsr/arcmsr_hba.c:arcmsr_ccb_complete() {
struct AdapterControlBlock *acb = ccb->acb;
struct scsi_cmnd *pcmd = ccb->pcmd;
unsigned long flags;
atomic_dec(&acb->ccboutstandingcount);
scsi_dma_unmap(ccb->pcmd);
ccb->startdone = ARCMSR_CCB_DONE;
spin_lock_irqsave(&acb->ccblist_lock, flags);
list_add_tail(&ccb->list, &acb->ccb_free_list);
spin_unlock_irqrestore(&acb->ccblist_lock, flags);
scsi_done(pcmd);
}
Overwriting these pointers via DMA allows arbitrary kernel memory writes
and control-flow hijacking. Host-only metadata should be kept in regular
kernel memory rather than inside the DMA-coherent CCB buffer.
[1] https://sashiko.dev/#/bug/linux-a10df3d7-0d0e-4b31-a2dd-416f0ee6e806
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117-571e631490-scsi-arcmsr-0@mail.sdu.edu.cn?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-17 15:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 14:51 [PATCH] scsi: arcmsr: Fix potential DMA leaks on XOR allocation failure Guangshuo Li
2026-11-17 15:17 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox