From: Sidraya Jayagond <sidraya@linux.ibm.com>
To: dust.li@linux.alibaba.com, Breno Leitao <leitao@debian.org>
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, alibuda@linux.alibaba.com, horms@kernel.org,
mjambigi@linux.ibm.com, tonylu@linux.alibaba.com,
guwen@linux.alibaba.com, hidayath@linux.ibm.com,
pasic@linux.ibm.com, netdev@vger.kernel.org,
linux-s390@vger.kernel.org
Subject: Re: [PATCH net] net/smc: fix TOCTOU race between smc_listen_out() and listener close
Date: Wed, 5 Aug 2026 17:59:06 +0530 [thread overview]
Message-ID: <1f4251f0-0ab6-4f95-9658-d06ddedfae28@linux.ibm.com> (raw)
In-Reply-To: <anLkl5X2xYedflyt@linux.alibaba.com>
On 05/08/26 12:51 pm, Dust Li wrote:
> On 2026-08-04 12:52:12, Sidraya Jayagond wrote:
>>
>>
>> On 03/08/26 6:24 pm, Breno Leitao wrote:
>>>> @@ -1931,11 +1931,12 @@ static void smc_listen_out(struct smc_sock *new_smc)
>>>> atomic_dec(&lsmc->queued_smc_hs);
>>>>
>>>> release_sock(newsmcsk); /* lock in smc_listen_work() */
>>>> + lock_sock_nested(&lsmc->sk, SINGLE_DEPTH_NESTING);
>>>> if (lsmc->sk.sk_state == SMC_LISTEN) {
>>>> - lock_sock_nested(&lsmc->sk, SINGLE_DEPTH_NESTING);
>>>> smc_accept_enqueue(&lsmc->sk, newsmcsk);
>>>> release_sock(&lsmc->sk);
>>>> } else { /* no longer listening */
>>>> + release_sock(&lsmc->sk);
>>>> smc_close_non_accepted(newsmcsk);
>>>> }
>>>
>>> Do you need to call smc_close_non_accepted() without the lock? otherwise
>>> you can have the lock around the whole if/else clause.
>>
>> Yes, smc_close_non_accepted() calls __smc_release() in turn calls
>> smc_close_active(), which in the SMC_ACTIVE case hits
>> smc_close_stream_wait() a blocking wait that can sleep up to
>> SMC_MAX_STREAM_WAIT_TIMEOUT (2 minutes). Holding the listener lock
>> across that would stall any concurrent smc_accept(), smc_listen_out(),
>> or smc_release() on the listener for the same duration.
>>
>> The release_sock() is intentionally placed before
>> smc_close_non_accepted() to keep the critical section minimal:
>> lock
>> check state
>> enqueue or not
>> unlock
>> then do the slow close work without the listener lock held.
>
>
> That patch looks good to me.
>
> Reviewed-by: Dust Li <dust.li@linux.alibaba.com>
>
>
> Two corrections to the justification though:
>
> 1. This newsmcsk sock have never been given to userspace, so
> smc_close_stream_wait() should return immediately. I think the stronger
> argument for keeping smc_close_non_accepted() outside the listener
> lock is what follows in smc_close_active()/__smc_release():
> smc_close_final() can wait up to SMC_WR_TX_WAIT_FREE_SLOT_TIME (10s)
> for a WR slot, and smc_clcsock_release() tears down the TCP
> socket.
>
> 2. SMC_MAX_STREAM_WAIT_TIMEOUT is 2 * HZ, i.e. 2 seconds, not 2 minutes.
>
Thank you for the corrections,Dust. Both points are valid.
>
> Best regards,
> Dust
>
next prev parent reply other threads:[~2026-08-05 12:29 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-03 7:07 [PATCH net] net/smc: fix TOCTOU race between smc_listen_out() and listener close Sidraya Jayagond
2026-08-03 12:54 ` Breno Leitao
2026-08-04 7:22 ` Sidraya Jayagond
2026-08-04 8:02 ` Breno Leitao
2026-08-05 7:21 ` Dust Li
2026-08-05 12:29 ` Sidraya Jayagond [this message]
2026-08-06 11:40 ` patchwork-bot+netdevbpf
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=1f4251f0-0ab6-4f95-9658-d06ddedfae28@linux.ibm.com \
--to=sidraya@linux.ibm.com \
--cc=alibuda@linux.alibaba.com \
--cc=davem@davemloft.net \
--cc=dust.li@linux.alibaba.com \
--cc=edumazet@google.com \
--cc=guwen@linux.alibaba.com \
--cc=hidayath@linux.ibm.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=leitao@debian.org \
--cc=linux-s390@vger.kernel.org \
--cc=mjambigi@linux.ibm.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pasic@linux.ibm.com \
--cc=tonylu@linux.alibaba.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