* [PATCH] scsi: megaraid_sas: Protect megasas_get_ctrl_info() in megasas_resume()
@ 2026-08-28 18:19 Bart Van Assche
2026-08-28 18:35 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Bart Van Assche @ 2026-08-28 18:19 UTC (permalink / raw)
To: Martin K . Petersen
Cc: linux-scsi, Bart Van Assche, Kashyap Desai, Sumit Saxena,
Shivasharan S, Chandrakanth patil, James E.J. Bottomley
Protect the megasas_get_ctrl_info() call in megasas_resume() with
instance->reset_mutex using scoped_guard().
megasas_get_ctrl_info() submits a DCMD command and modifies shared
controller information (instance->ctrl_info_buf). Calling it without
holding reset_mutex can race with adapter reset and other DCMD
operations.
Fixes: c3b10a55abc9 ("scsi: megaraid_sas: Update controller info during resume")
Cc: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: Sumit Saxena <sumit.saxena@broadcom.com>
Cc: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Cc: Chandrakanth patil <chandrakanth.patil@broadcom.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
drivers/scsi/megaraid/megaraid_sas_base.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index f0152b043e18..f345fb266db0 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -7875,8 +7875,9 @@ megasas_resume(struct device *dev)
goto fail_init_mfi;
}
- if (megasas_get_ctrl_info(instance) != DCMD_SUCCESS)
- goto fail_init_mfi;
+ scoped_guard(mutex, &instance->reset_mutex)
+ if (megasas_get_ctrl_info(instance) != DCMD_SUCCESS)
+ goto fail_init_mfi;
tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet,
(unsigned long)instance);
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] scsi: megaraid_sas: Protect megasas_get_ctrl_info() in megasas_resume()
2026-08-28 18:19 [PATCH] scsi: megaraid_sas: Protect megasas_get_ctrl_info() in megasas_resume() Bart Van Assche
@ 2026-08-28 18:35 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-08-28 18:35 UTC (permalink / raw)
To: Bart Van Assche; +Cc: linux-scsi
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [Medium] Mixing goto-based error handling and scoped_guard in the same function violates the kernel cleanup guidelines.
Pre-existing issues:
- [High] The error path in `megasas_resume` fails to deregister IRQs while freeing critical control structures, leading to a Use-After-Free.
--
commit 29ed10a7540b21ede13952240b8d781f1bdf89ab
Author: Bart Van Assche <bvanassche@acm.org>
scsi: megaraid_sas: Protect megasas_get_ctrl_info() in megasas_resume()
Protect the megasas_get_ctrl_info() call in megasas_resume() with
instance->reset_mutex using scoped_guard().
> diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
> index f0152b043e18c..f345fb266db05 100644
> --- a/drivers/scsi/megaraid/megaraid_sas_base.c
> +++ b/drivers/scsi/megaraid/megaraid_sas_base.c
> @@ -7875,8 +7875,9 @@ megasas_resume(struct device *dev)
> goto fail_init_mfi;
> }
>
> - if (megasas_get_ctrl_info(instance) != DCMD_SUCCESS)
> - goto fail_init_mfi;
> + scoped_guard(mutex, &instance->reset_mutex)
> + if (megasas_get_ctrl_info(instance) != DCMD_SUCCESS)
[Severity: Medium]
Does this mix goto-based error handling and scoped_guard() in the same
function?
The cleanup guidelines explicitly state that goto and cleanup helpers should
never be mixed in the same function to avoid confusing ownership semantics.
Should the other resources in megasas_resume() using goto cleanup be
converted to scope-based cleanup, or should this scoped_guard() be changed
to standard mutex_lock() and mutex_unlock()?
> + goto fail_init_mfi;
[Severity: High]
This isn't a bug introduced by this patch, but could this error path lead
to a use-after-free?
If megasas_resume() fails here, it jumps to the fail_init_mfi label:
fail_init_mfi:
megasas_free_ctrl_dma_buffers(instance);
megasas_free_ctrl_mem(instance);
scsi_host_put(host);
Since IRQs are requested earlier in the function but megasas_destroy_irqs()
is not called in this error path, could an interrupt fire and execute the
handler while structures like instance->reply_queue (freed in
megasas_free_ctrl_mem()) are accessed?
>
> tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet,
> (unsigned long)instance);
--
Sashiko AI review · https://sashiko.dev/#/patchset/6e802da5e402b1d304ab753da77d27f118d0f61b.1787941140.git.bvanassche@acm.org?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-08-28 18:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-28 18:19 [PATCH] scsi: megaraid_sas: Protect megasas_get_ctrl_info() in megasas_resume() Bart Van Assche
2026-08-28 18:35 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox