* [PATCH RFC] scsi: aacraid: free aborted management FIBs on late completion
@ 2026-11-24 11:04 Benjamin Saiz
2026-11-24 11:18 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Benjamin Saiz @ 2026-11-24 11:04 UTC (permalink / raw)
To: linux-scsi; +Cc: mkp, James.Bottomley, aacraid
When a signal interrupts a process waiting in aac_fib_send() for a
management command (for example FSACTL_SEND_FIB from arcconf, maxView
or smartctl), aac_fib_send() marks the FIB as abandoned (done = 2) and
returns -ERESTARTSYS. The ioctl handlers then deliberately keep the
FIB, because the controller still owns it: ioctl_send_fib() only calls
aac_fib_free() when retval != -ERESTARTSYS, and aac_send_raw_srb()
does the same. The interrupt handler is expected to release the FIB
when the late response arrives.
aac_intr_normal() handles that late response but only calls
aac_fib_complete(); it never calls aac_fib_free(). The FIB is
therefore never returned to the free list. Since commit 6bf3b630d0a7
("aacraid: SCSI blk tag support"), the free list only holds the
AAC_NUM_MGT_FIB (8) management FIBs, so eight interrupted management
commands exhaust it: aac_fib_alloc() returns NULL and every later
management ioctl fails with -ENOMEM until the adapter is reset or the
host is rebooted. management_fib_count is decremented normally, so the
"No management Fibs Available" check never fires and nothing is
logged.
The exhausted pool also prevents aac_send_shutdown() from allocating a
FIB, so VM_CloseAll is silently not sent at shutdown.
Observed on an Adaptec 6805 (Linux 5.10) with kprobes on aac_fib_send(),
aac_fib_complete() and aac_fib_free(). Before the test, 1000 management
commands all used the same FIB. arcconf was then killed (SIGKILL) while
waiting for a ContainerCommand:
54803.925692 arcconf-1091331, CPU 11: aac_fib_send() returns -512
54803.927570 <idle>-0, CPU 12, hardirq:
aac_fib_complete(fib=0xffff96570a8e7b00)
The late response arrived 1.9 ms later in hard interrupt context and
completed the FIB, but aac_fib_free() was never called for it. The next
812 management commands all used another FIB; 0xffff96570a8e7b00 was
never allocated again.
Commit cacb6dc3d7fe ("[SCSI] aacraid: fix File System going into
read-only mode") introduced the done = 2 handshake and freed the FIB
in both aac_response_normal() and aac_intr_normal(). Commit
6bf3b630d0a7 removed the aac_fib_free() calls from aac_intr_normal(),
as I/O FIBs became indexed by block layer tags and must not be put on
the management free list. The abandoned-FIB path, however, only ever
sees management FIBs: every synchronous sender (wait != 0, no
callback) gets its FIB from aac_fib_alloc(). Commit 423400e64d37
("scsi: aacraid: Include HBA direct interface") restored
aac_fib_free() for the callback-less async case but not for this one.
aac_response_normal() still frees the FIB.
Free the FIB after completing it in both the native HBA and the
regular branch. done is set to 1 before the call, so the early return
in aac_fib_free() for done == 2 does not apply.
The issue was found, and this patch and its changelog were drafted,
with the help of an AI coding assistant (Claude). I reviewed the
analysis and the change and take responsibility for them.
Fixes: 6bf3b630d0a7 ("aacraid: SCSI blk tag support")
Cc: stable@vger.kernel.org
Signed-off-by: Benjamin Saiz <benj.saiz@gmail.com>
---
RFC because the fix itself is only build-tested (x86_64, v7.0 headers,
W=1, no new warnings). The leak was reproduced on the affected host as
described above, but that host is a production NAS (Adaptec 6805,
Debian 11, Linux 5.10) and the patched module was not loaded there.
Every synchronous sender (wait != 0, no callback) in aachba.c,
commctrl.c, commsup.c and comminit.c gets its FIB from aac_fib_alloc(),
so the done == 2 path cannot return a block layer tagged FIB to the
management free list.
For reference, Microchip's out-of-tree driver 1.2.1-60001 frees the FIB
at the same place (both done == 2 branches of aac_intr_normal()); its
aac_fib_free() only returns pool FIBs to the free list.
Not addressed here: on -ERESTARTSYS, aac_send_raw_srb() also strands its
SG buffers and DMA mappings (bugzilla 220504).
drivers/scsi/aacraid/dpcsup.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/aacraid/dpcsup.c b/drivers/scsi/aacraid/dpcsup.c
index 169c41d..a965f18 100644
--- a/drivers/scsi/aacraid/dpcsup.c
+++ b/drivers/scsi/aacraid/dpcsup.c
@@ -379,8 +379,10 @@ unsigned int aac_intr_normal(struct aac_dev *dev, u32 index, int isAif,
mflags);
FIB_COUNTER_INCREMENT(aac_config.NativeRecved);
- if (completed)
+ if (completed) {
aac_fib_complete(fib);
+ aac_fib_free(fib);
+ }
}
} else {
struct hw_fib *hwfib = fib->hw_fib_va;
@@ -432,8 +434,10 @@ unsigned int aac_intr_normal(struct aac_dev *dev, u32 index, int isAif,
mflags);
FIB_COUNTER_INCREMENT(aac_config.NormalRecved);
- if (completed)
+ if (completed) {
aac_fib_complete(fib);
+ aac_fib_free(fib);
+ }
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH RFC] scsi: aacraid: free aborted management FIBs on late completion
2026-11-24 11:04 [PATCH RFC] scsi: aacraid: free aborted management FIBs on late completion Benjamin Saiz
@ 2026-11-24 11:18 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-24 11:18 UTC (permalink / raw)
To: Benjamin Saiz, linux-scsi
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] scsi: aacraid: race on fib->done in aac_hba_send() and
aac_intr_normal()
- [Medium] scsi: aacraid: double free on -ERESTARTSYS in
aac_send_safw_bmic_cmd()
--
commit bdfff41a3eec2c252b35e5b8c632cb03cf063779
Author: Benjamin Saiz <benj.saiz@gmail.com>
scsi: aacraid: free aborted management FIBs on late completion
This commit calls aac_fib_free() in aac_intr_normal() when completing a
management FIB whose caller was interrupted and marked fib->done == 2.
> diff --git a/drivers/scsi/aacraid/dpcsup.c b/drivers/scsi/aacraid/dpcsup.c
> index 169c41d080a15..a965f18fe4849 100644
> --- a/drivers/scsi/aacraid/dpcsup.c
> +++ b/drivers/scsi/aacraid/dpcsup.c
> @@ -379,8 +379,10 @@ unsigned int aac_intr_normal(struct aac_dev *dev, u32 index, int isAif,
> mflags);
>
> FIB_COUNTER_INCREMENT(aac_config.NativeRecved);
> - if (completed)
> + if (completed) {
> aac_fib_complete(fib);
> + aac_fib_free(fib);
> + }
> }
> } else {
> struct hw_fib *hwfib = fib->hw_fib_va;
[Severity: Medium]
Can freeing fib here cause a use-after-free and double free when a
synchronous native HBA command in aac_hba_send() is interrupted by a
signal?
In aac_hba_send(), fibptr->done = 2 is written outside fibptr->event_lock:
drivers/scsi/aacraid/commsup.c:aac_hba_send() {
...
if (wait_for_completion_interruptible(&fibptr->event_wait))
fibptr->done = 2;
fibptr->flags &= ~(FIB_CONTEXT_FLAG_WAIT);
spin_lock_irqsave(&fibptr->event_lock, flags);
if ((fibptr->done == 0) || (fibptr->done == 2)) {
fibptr->done = 2; /* Tell interrupt we aborted */
spin_unlock_irqrestore(&fibptr->event_lock, flags);
return -ERESTARTSYS;
}
spin_unlock_irqrestore(&fibptr->event_lock, flags);
...
}
If the completion interrupt arrives between the unlocked assignment and
spin_lock_irqsave(&fibptr->event_lock, flags), both sides free the FIB:
CPU0 CPU1 (<hardirq>)
aac_send_raw_srb()
aac_hba_send()
wait_for_completion_interruptible()
/* interrupted by signal */
fibptr->done = 2;
aac_intr_normal()
lock(&fib->event_lock)
if (fib->done == 2) {
fib->done = 1;
completed = 1;
}
unlock(&fib->event_lock)
aac_fib_complete(fib)
aac_fib_free(fib)
lock(&fibptr->event_lock)
/* fibptr->done is 1, returns 0 */
unlock(&fibptr->event_lock)
/* reads freed srbfib */ <-- use-after-free
if (rcode != -ERESTARTSYS)
aac_fib_free(srbfib) <-- double free
Because fibptr->done is now 1, the early return for done == 2 in
aac_fib_free() does not trigger, pushing srbfib onto dev->free_fib twice
and corrupting the management FIB free list into a cycle.
Also, unlike aac_fib_send(), neither aac_fib_alloc() nor aac_hba_send()
initializes fibptr->done = 0, so recycled FIBs enter aac_hba_send() with
fibptr->done == 1. If aac_intr_normal() runs after
wait_for_completion_interruptible() is interrupted but before
fibptr->done = 2 is written, aac_intr_normal() sees fib->done != 2 and
does not free the FIB, while aac_hba_send() overwrites fibptr->done = 2
and returns -ERESTARTSYS, leaking the FIB.
> @@ -432,8 +434,10 @@ unsigned int aac_intr_normal(struct aac_dev *dev, u32 index, int isAif,
> mflags);
>
> FIB_COUNTER_INCREMENT(aac_config.NormalRecved);
> - if (completed)
> + if (completed) {
> aac_fib_complete(fib);
> + aac_fib_free(fib);
> + }
> }
> }
>
[Severity: Medium]
Does this double free fibptr when aac_fib_send() is interrupted by a
signal in aac_send_safw_bmic_cmd()?
Unlike ioctl_send_fib() and aac_send_raw_srb(), aac_send_safw_bmic_cmd()
translates -ERESTARTSYS to -ERESTART and unconditionally cleans up:
drivers/scsi/aacraid/aachba.c:aac_send_safw_bmic_cmd() {
...
if (rcode == -ERESTARTSYS)
rcode = -ERESTART;
if (unlikely(rcode < 0))
goto bmic_error;
...
bmic_error:
dma_unmap_single(&dev->pdev->dev, addr, xfer_len, DMA_BIDIRECTIONAL);
fib_error:
aac_fib_complete(fibptr);
aac_fib_free(fibptr);
...
}
Previously, the early return for fibptr->done == 2 in aac_fib_complete()
and aac_fib_free() made those calls no-ops after an interrupted
aac_fib_send(). With this change, if aac_intr_normal() completes the
abandoned FIB before aac_send_safw_bmic_cmd() reaches aac_fib_free():
CPU0 CPU1 (<hardirq>)
aac_send_safw_bmic_cmd()
aac_fib_send()
/* interrupted, sets done = 2 */
return -ERESTARTSYS;
aac_intr_normal()
if (fib->done == 2) {
fib->done = 1;
completed = 1;
}
aac_fib_complete(fib)
aac_fib_free(fib)
dma_unmap_single(...)
aac_fib_complete(fibptr)
aac_fib_free(fibptr) <-- double free
fibptr->done is already reset to 1, so aac_fib_free() does not return
early and pushes fibptr onto dev->free_fib a second time.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124110444.3485-1-benj.saiz@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-24 11:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 11:04 [PATCH RFC] scsi: aacraid: free aborted management FIBs on late completion Benjamin Saiz
2026-11-24 11:18 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox