Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Changyul Lee" <lcy8047@gmail.com>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH] scsi: iscsi: Remove the endpoint ID only once when device_register() fails
Date: Mon, 09 Nov 2026 16:59:04 +0000	[thread overview]
Message-ID: <sashiko-outbox-205259@kernel.org> (raw)
In-Reply-To: <20261109163649.1092897-1-lcy8047@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] scsi: iscsi: failed ep left in iscsi_ep_idr in
  iscsi_create_endpoint()
--

commit bcf1b2eaf3554e78f33bb71b87b333ff7a9501a1
Author: Changyul Lee <lcy8047@gmail.com>

scsi: iscsi: Remove the endpoint ID only once when device_register() fails

This commit drops the explicit idr_remove() from the device_register()
error path in iscsi_create_endpoint() so that iscsi_endpoint_release()
removes the endpoint ID once.

> diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
> index b094af7c997e2..6e38fbfd5a9de 100644
> --- a/drivers/scsi/scsi_transport_iscsi.c
> +++ b/drivers/scsi/scsi_transport_iscsi.c
> @@ -246,9 +246,6 @@ iscsi_create_endpoint(int dd_size)
>  	return NULL;
>  
>  put_dev:
> -	mutex_lock(&iscsi_ep_idr_mutex);
> -	idr_remove(&iscsi_ep_idr, id);
> -	mutex_unlock(&iscsi_ep_idr_mutex);
>  	put_device(&ep->dev);
>  	return NULL;
>  free_ep:

[Severity: Medium]
Does leaving ep in iscsi_ep_idr here allow iscsi_lookup_endpoint() to
find the failed endpoint after put_device() drops its reference count to
zero?

iscsi_create_endpoint() publishes ep in iscsi_ep_idr before calling
device_register(&ep->dev) and before setting ep->dd_data:

CPU0                                  CPU1
iscsi_create_endpoint()
  idr_alloc(&iscsi_ep_idr, ep, ...)
  device_register(&ep->dev) -> fails
  put_device(&ep->dev)
    kref_put(&kobj->kref, ...)
      /* kref reaches 0 */
                                      iscsi_lookup_endpoint()
                                        ep = idr_find(&iscsi_ep_idr, ...)
                                        get_device(&ep->dev)  <-- use-after-free
      iscsi_endpoint_release()
        mutex_lock(&iscsi_ep_idr_mutex)
        idr_remove(&iscsi_ep_idr, ep->id)
        kfree(ep)

In addition to the refcount addition on zero and use-after-free on ep,
ep->dd_data is still NULL because the error path skipped its
initialization, so callers of iscsi_lookup_endpoint() such as
iscsi_if_ep_disconnect() -> transport->ep_disconnect() will dereference a
NULL pointer.

Replacing the pointer with NULL via idr_replace(&iscsi_ep_idr, NULL, id)
under iscsi_ep_idr_mutex before put_device(&ep->dev) would hide the
failed endpoint from lookups while keeping the ID reserved until
iscsi_endpoint_release() removes it.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261109163649.1092897-1-lcy8047@gmail.com?part=1

      reply	other threads:[~2026-11-09 16:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09 16:36 [PATCH] scsi: iscsi: Remove the endpoint ID only once when device_register() fails Changyul Lee
2026-11-09 16:59 ` sashiko-bot [this message]

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=sashiko-outbox-205259@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=lcy8047@gmail.com \
    --cc=linux-scsi@vger.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