From: Ivy Lopez <skunkolee@gmail.com>
To: James.Bottomley@HansenPartnership.com, martin.petersen@oracle.com
Cc: viro@zeniv.linux.org.uk, axboe@kernel.dk, bvanassche@acm.org,
ching2048@areca.com.tw, linux-scsi@vger.kernel.org,
linux-kernel@vger.kernel.org, Ivy Lopez <skunkolee@gmail.com>
Subject: [PATCH] scsi: arcmsr: fix NULL deref on dma_alloc_coherent() failure in arcmsr_alloc_xor_buffer()
Date: Thu, 6 Aug 2026 23:25:43 -0600 [thread overview]
Message-ID: <20260807052543.62545-1-skunkolee@gmail.com> (raw)
arcmsr_alloc_xor_buffer() does not check the return value of the
initial dma_alloc_coherent() call before using it. If the allocation
fails, the code performs pointer arithmetic on the NULL base
(computing pXorPhys and pXorVirt) and later unconditionally
dereferences it through pRamBuf to write hrbSignature and other
fields, causing a NULL pointer dereference.
Additionally, acb->xor_mega is set unconditionally before the
allocation attempt, based only on firmware status bits. If the
allocation fails, acb->xor_mega remains nonzero, so the later
cleanup path in arcmsr_free_ccb_pool() and the message-config code
in arcmsr_iop_confirm() will still enter their "if (acb->xor_mega)"
branches and dereference the never-set acb->xorVirt/acb->xorPhys,
a second NULL pointer dereference on the allocation failure path.
Fix this by checking the initial dma_alloc_coherent() result and, on
failure, resetting acb->xor_mega to 0 before returning -ENOMEM, so
that no code path treats the XOR buffer as present when it was never
allocated.
Found by static analysis; no hardware reproducer.
Signed-off-by: Ivy Lopez <skunkolee@gmail.com>
Cc: ching Huang <ching2048@areca.com.tw>
---
drivers/scsi/arcmsr/arcmsr_hba.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
index 8aa948f06cac..40407b281839 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -771,6 +771,12 @@ 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) {
+ pr_info("arcmsr%d: alloc init2cfg buffer failed\n",
+ acb->host->host_no);
+ acb->xor_mega = 0;
+ return -ENOMEM;
+ }
acb->xorVirt = dma_coherent;
acb->xorPhys = dma_coherent_handle;
pXorPhys = (struct Xor_sg *)((unsigned long)dma_coherent +
--
2.55.0
next reply other threads:[~2026-08-07 5:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 5:25 Ivy Lopez [this message]
2026-08-07 5:50 ` [PATCH] scsi: arcmsr: fix NULL deref on dma_alloc_coherent() failure in arcmsr_alloc_xor_buffer() sashiko-bot
2026-08-07 18:39 ` Ivy Lopez
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=20260807052543.62545-1-skunkolee@gmail.com \
--to=skunkolee@gmail.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=axboe@kernel.dk \
--cc=bvanassche@acm.org \
--cc=ching2048@areca.com.tw \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=viro@zeniv.linux.org.uk \
/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.