Re: [PATCH net] net/smc: fix panic smc_tcp_syn_recv_sock() while closing listen socket

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 9/22/23 7:59 AM, Wenjia Zhang wrote:


On 20.09.23 14:08, D. Wythe wrote:
From: "D. Wythe" <alibuda@xxxxxxxxxxxxxxxxx>

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@xxxxxxxxxxxxxxxxx>
---
  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













[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux