Skip to contentSkip to conversation

sctp: fix potential deadlock on &net->sctp.addr_wq_lock

PATCH Applied Chengfeng Ye 4 participants 4 messages Jun 27, 2023 – Jun 29, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sctp: fix potential deadlock on &net->sctp.addr_wq_lock

As &net->sctp.addr_wq_lock is also acquired by the timer sctp_addr_wq_timeout_handler() in protocal.c, the same lock acquisition at sctp_auto_asconf_init() seems should disable irq since it is called from sctp_accept() under process context.

Possible deadlock scenario:
sctp_accept()

    -> sctp_sock_migrate()
    -> sctp_auto_asconf_init()
    -> spin_lock(&net->sctp.addr_wq_lock)
        <timer interrupt>
        -> sctp_addr_wq_timeout_handler()
        -> spin_lock_bh(&net->sctp.addr_wq_lock); (deadlock here)

This flaw was found using an experimental static analysis tool we are developing for irq-related deadlock.

The tentative patch fix the potential deadlock by spin_lock_bh().

---
 net/sctp/socket.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/sctp/socket.c +2 -2
index cda8c2874691..b2c7d17ff848 100644
@@ -364,9 +364,9 @@ static void sctp_auto_asconf_init(struct sctp_sock *sp)
 	struct net *net = sock_net(&sp->inet.sk);
 
 	if (net->sctp.default_auto_asconf) {
-		spin_lock(&net->sctp.addr_wq_lock);
+		spin_lock_bh(&net->sctp.addr_wq_lock);
 		list_add_tail(&sp->auto_asconf_list, &net->sctp.auto_asconf_splist);
-		spin_unlock(&net->sctp.addr_wq_lock);
+		spin_unlock_bh(&net->sctp.addr_wq_lock);
 		sp->do_auto_asconf = 1;
 	}
 }
Signature · 1 line
2.17.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 42 lines · Chengfeng Ye

As &net->sctp.addr_wq_lock is also acquired by the timer sctp_addr_wq_timeout_handler() in protocal.c, the same lock acquisition at sctp_auto_asconf_init() seems should disable irq since it is called from sctp_accept() under process context.

Possible deadlock scenario:
sctp_accept()

    -> sctp_sock_migrate()
    -> sctp_auto_asconf_init()
    -> spin_lock(&net->sctp.addr_wq_lock)
        <timer interrupt>
        -> sctp_addr_wq_timeout_handler()
        -> spin_lock_bh(&net->sctp.addr_wq_lock); (deadlock here)

This flaw was found using an experimental static analysis tool we are developing for irq-related deadlock.

The tentative patch fix the potential deadlock by spin_lock_bh().

---
 net/sctp/socket.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/sctp/socket.c +2 -3
index cda8c2874691..b2c7d17ff848 100644
@@ -364,9 +364,9 @@ static void sctp_auto_asconf_init(struct sctp_sock *sp)
        struct net *net = sock_net(&sp->inet.sk);
 
        if (net->sctp.default_auto_asconf) {
-               spin_lock(&net->sctp.addr_wq_lock);
+               spin_lock_bh(&net->sctp.addr_wq_lock);
                list_add_tail(&sp->auto_asconf_list, &net->sctp.auto_asconf_splist);
-               spin_unlock(&net->sctp.addr_wq_lock);
+               spin_unlock_bh(&net->sctp.addr_wq_lock);
                sp->do_auto_asconf = 1;
        }
 }
--
Quoted 2 lines

2.17.1

Fixes 34e5b0118685 ("sctp: delay auto_asconf init until binding the

first addr")

Thanks.

maintainer
#2 lore raw
In reply to Chengfeng Ye
Quoted 14 lines · Chengfeng Ye

As &net->sctp.addr_wq_lock is also acquired by the timer sctp_addr_wq_timeout_handler() in protocal.c, the same lock acquisition at sctp_auto_asconf_init() seems should disable irq since it is called from sctp_accept() under process context.

Possible deadlock scenario:
sctp_accept()

    -> sctp_sock_migrate()
    -> sctp_auto_asconf_init()
    -> spin_lock(&net->sctp.addr_wq_lock)
        <timer interrupt>
        -> sctp_addr_wq_timeout_handler()
        -> spin_lock_bh(&net->sctp.addr_wq_lock); (deadlock here)
Quoted 4 lines

This flaw was found using an experimental static analysis tool we are developing for irq-related deadlock.

The tentative patch fix the potential deadlock by spin_lock_bh().

Patch LGTM.

Please note that the above suggests a possible net-next follow- up/cleanup, replacing the spin_lock_bh() in sctp_addr_wq_timeout_handler() with a simple/faster spin_lock() - since sctp_addr_wq_timeout_handler() runs with BH disabled. Anyhow net-next is closed now, it will have to wait a bit ;)

Cheers,

Paolo

#3 lore raw
In reply to Chengfeng Ye
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

Quoted 7 lines · On Tue, 27 Jun 2023 12:03:40 +0000 you wrote:

As &net->sctp.addr_wq_lock is also acquired by the timer sctp_addr_wq_timeout_handler() in protocal.c, the same lock acquisition at sctp_auto_asconf_init() seems should disable irq since it is called from sctp_accept() under process context.

Possible deadlock scenario:
sctp_accept()

Quoted 8 lines
    -> sctp_sock_migrate()
    -> sctp_auto_asconf_init()
    -> spin_lock(&net->sctp.addr_wq_lock)
        <timer interrupt>
        -> sctp_addr_wq_timeout_handler()
        -> spin_lock_bh(&net->sctp.addr_wq_lock); (deadlock here)

[...]

Here is the summary with links:
- sctp: fix potential deadlock on &net->sctp.addr_wq_lock

    https://git.kernel.org/netdev/net/c/6feb37b3b06e

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html