public inbox for linux-s390@vger.kernel.org
 help / color / mirror / Atom feed
From: "D. Wythe" <alibuda@linux.alibaba.com>
To: Wenjia Zhang <wenjia@linux.ibm.com>,
	kgraul@linux.ibm.com, jaka@linux.ibm.com
Cc: kuba@kernel.org, davem@davemloft.net, netdev@vger.kernel.org,
	linux-s390@vger.kernel.org, linux-rdma@vger.kernel.org
Subject: Re: [PATCH net] net/smc: fix panic smc_tcp_syn_recv_sock() while closing listen socket
Date: Mon, 25 Sep 2023 16:29:53 +0800	[thread overview]
Message-ID: <ee2a5f8c-4119-c84a-05bc-03015e6c9bea@linux.alibaba.com> (raw)
In-Reply-To: <0902f55b-0d51-7f4d-0a9e-4b9423217fcf@linux.ibm.com>



On 9/22/23 7:59 AM, Wenjia Zhang wrote:
>
>
> On 20.09.23 14:08, D. Wythe wrote:
>> From: "D. Wythe" <alibuda@linux.alibaba.com>
>>
>> Consider the following scenarios:
>>
>> smc_release
>>     smc_close_active
>> write_lock_bh(&smc->clcsock->sk->sk_callback_lock);
>>         smc->clcsock->sk->sk_user_data = NULL;
>> write_unlock_bh(&smc->clcsock->sk->sk_callback_lock);
>>
>> smc_tcp_syn_recv_sock
>>     smc = smc_clcsock_user_data(sk);
>>     /* now */
>>     /* smc == NULL */
>>
>> Hence, we may read the a NULL value in smc_tcp_syn_recv_sock(). And
>> since we only unset sk_user_data during smc_release, it's safe to
>> drop the incoming tcp reqsock.
>>
>> Fixes:  ("net/smc: net/smc: Limit backlog connections"
>> Signed-off-by: D. Wythe <alibuda@linux.alibaba.com>
>> ---
>>   net/smc/af_smc.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
>> index bacdd97..b4acf47 100644
>> --- a/net/smc/af_smc.c
>> +++ b/net/smc/af_smc.c
>> @@ -125,6 +125,8 @@ static struct sock *smc_tcp_syn_recv_sock(const 
>> struct sock *sk,
>>       struct sock *child;
>>         smc = smc_clcsock_user_data(sk);
>> +    if (unlikely(!smc))
>> +        goto drop;
>>         if (READ_ONCE(sk->sk_ack_backlog) + 
>> atomic_read(&smc->queued_smc_hs) >
>>                   sk->sk_max_ack_backlog)

Hi Wenjia,

>
> this is unfortunately not sufficient for this fix. You have to make 
> sure that is not a life-time problem. Even so, READ_ONCE() is also 
> needed in this case.
>

Life-time problem? If you means the smc will still be NULL in the 
future,  I don't really think so, smc is a local variable assigned by 
smc_clcsock_user_data.
it's either NULL or a valid and unchanged value.

And READ_ONCE() is needed indeed, considering not make too much change, 
maybe we can protected following

smc = smc_clcsock_user_data(sk);

with sk_callback_lock, which solves the same problem. What do you think?

Best Wishes
D. Wythe











  reply	other threads:[~2023-09-25  8:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-20 12:08 [PATCH net] net/smc: fix panic smc_tcp_syn_recv_sock() while closing listen socket D. Wythe
2023-09-21  3:19 ` Dust Li
2023-09-21 21:43 ` Simon Horman
2023-09-21 23:59 ` Wenjia Zhang
2023-09-25  8:29   ` D. Wythe [this message]
2023-09-25  9:43     ` Alexandra Winter
2023-09-26  3:00       ` D. Wythe
2023-09-26  7:18         ` Alexandra Winter
2023-09-26  9:06           ` D. Wythe
2023-09-27  8:14             ` Alexandra Winter
2023-10-05 18:14             ` Wenjia Zhang
2023-10-08  8:22               ` D. Wythe
2023-10-11 12:39               ` Wenjia Zhang

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=ee2a5f8c-4119-c84a-05bc-03015e6c9bea@linux.alibaba.com \
    --to=alibuda@linux.alibaba.com \
    --cc=davem@davemloft.net \
    --cc=jaka@linux.ibm.com \
    --cc=kgraul@linux.ibm.com \
    --cc=kuba@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=wenjia@linux.ibm.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