From: Dave Marquardt <davemarq@linux.ibm.com>
To: sashiko-bot@kernel.org
Cc: sashiko-reviews@lists.linux.dev, linux-scsi@vger.kernel.org
Subject: Re: [PATCH v15 03/11] scsi: ibmvfc: fix potential NULL pointer dereference on failed queue allocation
Date: Tue, 20 Oct 2026 09:26:51 -0500 [thread overview]
Message-ID: <87fqy0la6s.fsf@linux.ibm.com> (raw)
In-Reply-To: <sashiko-outbox-178320@kernel.org> (sashiko-bot@kernel.org's message of "Mon, 19 Oct 2026 22:29:27 +0000")
sashiko-bot@kernel.org writes:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] scsi: ibmvfc: scrq->cookie not cleared on H_REG_SUB_CRQ failure in ibmvfc_register_channel()
> --
>
> commit 09a8086d40f44887491493f172cd7dd44285d18d
> Author: Tyrel Datwyler <tyreld@linux.ibm.com>
>
> scsi: ibmvfc: fix potential NULL pointer dereference on failed queue allocation
>
> This commit guards ibmvfc_deregister_channel() against calling H_FREE_SUB_CRQ
> on an unregistered sub-CRQ queue and against zeroing an unallocated message
> buffer. It also adds a KUnit test suite to verify the deregistration guards.
>
>> diff --git a/drivers/scsi/ibmvscsi/ibmvfc-core.c b/drivers/scsi/ibmvscsi/ibmvfc-core.c
>> index 145d559041f12..0fe6b6f4260ba 100644
>> --- a/drivers/scsi/ibmvscsi/ibmvfc-core.c
>> +++ b/drivers/scsi/ibmvscsi/ibmvfc-core.c
>> @@ -6449,12 +6449,24 @@ static int ibmvfc_register_channel(struct ibmvfc_host *vhost,
>> do {
>> hcall_rc = plpar_hcall_norets(H_FREE_SUB_CRQ, vdev->unit_address, scrq->cookie);
>> } while (hcall_rc == H_BUSY || H_IS_LONG_BUSY(hcall_rc));
>> + scrq->cookie = 0;
>> reg_failed:
>> LEAVE;
>> return rc;
>> }
>
> [Severity: Medium]
> Should scrq->cookie = 0 be placed after the reg_failed label (or should
> h_reg_sub_crq() avoid writing *cookie on error)?
>
> Looking at h_reg_sub_crq() in drivers/scsi/ibmvscsi/ibmvfc-core.c, it
> unconditionally writes retbuf[0] into *cookie regardless of the return code:
>
> static long h_reg_sub_crq(unsigned long unit_address, unsigned long ioba,
> unsigned long length, unsigned long *cookie,
> unsigned long *irq)
> {
> unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
> long rc;
>
> rc = plpar_hcall(H_REG_SUB_CRQ, retbuf, unit_address, ioba, length);
> *cookie = retbuf[0];
> *irq = retbuf[1];
>
> return rc;
> }
>
> In plpar_hcall() (arch/powerpc/platforms/pseries/hvCall.S), r5 (unit_address)
> is moved into r4 before HVSC and r4 is unconditionally stored into retbuf[0]
> after HVSC, even when HVSC returns an error such as H_PARAMETER or H_RESOURCE.
>
> When h_reg_sub_crq() fails in ibmvfc_register_channel():
>
> rc = h_reg_sub_crq(vdev->unit_address, scrq->msg_token, PAGE_SIZE,
> &scrq->cookie, &scrq->hw_irq);
>
> /* H_CLOSED indicates successful register, but no CRQ partner */
> if (rc && rc != H_CLOSED) {
> dev_warn(dev, "Error registering sub-crq: %d\n", rc);
> if (rc == H_PARAMETER)
> dev_warn_once(dev, "Firmware may not support MQ\n");
> goto reg_failed;
> }
>
> jumping to reg_failed skips scrq->cookie = 0, leaving a non-zero value in
> scrq->cookie. If ibmvfc_deregister_channel() is later called on this queue
> during reset or teardown (via ibmvfc_dereg_sub_crqs()), won't the new
> if (scrq->cookie) check evaluate to true and issue H_FREE_SUB_CRQ on a queue
> that failed registration?
Yes. I will move clearing scrq->cookie after the reg_failed label.
-Dave
next prev parent reply other threads:[~2026-10-20 14:27 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-19 22:15 [PATCH v15 00/11] scsi: ibmvfc: make ibmvfc support FPIN messages Dave Marquardt via B4 Relay
2026-10-19 22:15 ` [PATCH v15 01/11] scsi: ibmvfc: fix IRQ leak and guard deregister on channel reg failure Dave Marquardt via B4 Relay
2026-10-19 22:15 ` [PATCH v15 02/11] scsi: ibmvfc: fix potential clobbering of rc after failed irq setup Dave Marquardt via B4 Relay
2026-10-19 22:15 ` [PATCH v15 03/11] scsi: ibmvfc: fix potential NULL pointer dereference on failed queue allocation Dave Marquardt via B4 Relay
2026-10-19 22:29 ` sashiko-bot
2026-10-20 14:26 ` Dave Marquardt [this message]
2026-10-19 22:15 ` [PATCH v15 04/11] scsi: ibmvfc: add basic FPIN support Dave Marquardt via B4 Relay
2026-10-19 22:35 ` sashiko-bot
2026-10-20 15:49 ` Dave Marquardt
2026-10-19 22:15 ` [PATCH v15 05/11] scsi: ibmvfc: add NOOP command support Dave Marquardt via B4 Relay
2026-10-19 22:15 ` [PATCH v15 06/11] scsi: ibmvfc: add FPIN extended flag and async sub-CRQ queue handle Dave Marquardt via B4 Relay
2026-10-19 22:15 ` [PATCH v15 07/11] scsi: ibmvfc: extend async event handlers for async sub-CRQ events Dave Marquardt via B4 Relay
2026-10-19 22:15 ` [PATCH v15 08/11] scsi: ibmvfc: add interrupt routine for asynchronous sub CRQ Dave Marquardt via B4 Relay
2026-10-19 22:15 ` [PATCH v15 09/11] scsi: ibmvfc: extend channel reg/dereg helpers for async sub-CRQ Dave Marquardt via B4 Relay
2026-10-19 22:15 ` [PATCH v15 10/11] scsi: ibmvfc: register and use asynchronous sub CRQ for events Dave Marquardt via B4 Relay
2026-10-19 22:26 ` sashiko-bot
2026-10-19 22:15 ` [PATCH v15 11/11] scsi: ibmvfc: handle extended FPIN events Dave Marquardt via B4 Relay
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=87fqy0la6s.fsf@linux.ibm.com \
--to=davemarq@linux.ibm.com \
--cc=linux-scsi@vger.kernel.org \
--cc=sashiko-bot@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox