mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jason Yan <yanaijie@huawei.com>
To: Chaohai Chen <wdhh6@aliyun.com>, Damien Le Moal <dlemoal@kernel.org>
Cc: <john.g.garry@oracle.com>,
	<James.Bottomley@hansenpartnership.com>,
	<martin.petersen@oracle.com>, <johannes.thumshirn@wdc.com>,
	<mingo@kernel.org>, <cassel@kernel.org>, <tglx@kernel.org>,
	<linux-scsi@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] scsi: libsas: Fix dev_list race conditions with proper locking
Date: Mon, 2 Feb 2026 17:03:17 +0800	[thread overview]
Message-ID: <df7c11fd-f0f0-45aa-8c2b-0e286cd1f9d9@huawei.com> (raw)
In-Reply-To: <aYBT9ASycq4hA5U7@VM-209-93-tencentos>

在 2026/2/2 15:36, Chaohai Chen 写道:
> On Mon, Feb 02, 2026 at 10:21:43AM +0900, Damien Le Moal wrote:
>> On 1/31/26 20:19, Chaohai Chen wrote:
>>>>> +	 * We need to unlock before calling sas_unregister_dev() as it
>>>>> +	 * may sleep, but we hold a reference to prevent device removal.
>>>>
>>>> And why is that necessary ?
>>>>
>>> Because when unlocked, it is possible that the device has already been
>>> released by another thread. If there is no reference count, it will lead
>>> to used after free.
>>
>> Please clearly explain the problem path. Your statements about "another thread"
>> is too vague.
>>
> 1.
> CPU 1: disco_q                          CPU 2: event_q
> ==============================          ==============================
> sas_discover_domain()                   sas_phye_loss_of_signal()
> 
> sas_ex_level_discovery()                sas_deform_port(phy, true)
> 
> list_for_each_entry(dev,                sas_unregister_domain_devices()
>    &port->dev_list, ...)
> 
> NOP                                     list_for_each_entry_safe_reverse(
>                                          dev, n, &port->dev_list, ...)
> 
> NOP                                     sas_unregister_dev(port, dev)
> 
> NOP                                     kfree(dev)
> 
> if (dev_is_expander(dev->dev_type))(UAF)
> ...

DISCE_DISCOVER_DOMAIN(sas_discover_domain) event is queued and executed 
in sas_form_port() synchronously, and sas_form_port() is executed in 
event_q. So I don't think the race condition above will happen.

> 
> 2.
> CPU 1: disco_q                          CPU 2: event_q
> ==============================          ==============================
> sas_resume_devices()                    sas_porte_link_reset_err()
> 
> sas_resume_port()                       sas_deform_port(phy, true)
> 
> list_for_each_entry_safe(dev,           sas_unregister_domain_devices()
>    &port->dev_list, ...)
> 
> NOP                                     free dev
> 
> visit dev->ex_dev(UAF)

This may happen in theory.

Thanks,
祝一切顺利

  parent reply	other threads:[~2026-02-02  9:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-29  9:38 Chaohai Chen
2026-01-30  3:02 ` Damien Le Moal
2026-01-31 11:19   ` Chaohai Chen
2026-02-02  1:21     ` Damien Le Moal
2026-02-02  7:36       ` Chaohai Chen
2026-02-02  7:45         ` Damien Le Moal
2026-02-02  9:03         ` Jason Yan [this message]
2026-01-30  8:27 ` Jason Yan
2026-01-31 10:47   ` Chaohai Chen
2026-02-02  1:46     ` Damien Le Moal

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=df7c11fd-f0f0-45aa-8c2b-0e286cd1f9d9@huawei.com \
    --to=yanaijie@huawei.com \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=cassel@kernel.org \
    --cc=dlemoal@kernel.org \
    --cc=johannes.thumshirn@wdc.com \
    --cc=john.g.garry@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=mingo@kernel.org \
    --cc=tglx@kernel.org \
    --cc=wdhh6@aliyun.com \
    /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

all inboxes | Powered by JetHome®