netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tipc: fix a potential deadlock on &tx->lock
@ 2023-09-27 18:14 Chengfeng Ye
  2023-09-29 18:29 ` Jacob Keller
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Chengfeng Ye @ 2023-09-27 18:14 UTC (permalink / raw)
  To: jmaloy, ying.xue, davem, edumazet, kuba, pabeni
  Cc: netdev, tipc-discussion, linux-kernel, Chengfeng Ye

It seems that tipc_crypto_key_revoke() could be be invoked by
wokequeue tipc_crypto_work_rx() under process context and
timer/rx callback under softirq context, thus the lock acquisition
on &tx->lock seems better use spin_lock_bh() to prevent possible
deadlock.

This flaw was found by an experimental static analysis tool I am
developing for irq-related deadlock.

tipc_crypto_work_rx() <workqueue>
--> tipc_crypto_key_distr()
--> tipc_bcast_xmit()
--> tipc_bcbase_xmit()
--> tipc_bearer_bc_xmit()
--> tipc_crypto_xmit()
--> tipc_ehdr_build()
--> tipc_crypto_key_revoke()
--> spin_lock(&tx->lock)
<timer interrupt>
   --> tipc_disc_timeout()
   --> tipc_bearer_xmit_skb()
   --> tipc_crypto_xmit()
   --> tipc_ehdr_build()
   --> tipc_crypto_key_revoke()
   --> spin_lock(&tx->lock) <deadlock here>

Signed-off-by: Chengfeng Ye <dg573847474@gmail.com>
---
 net/tipc/crypto.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/tipc/crypto.c b/net/tipc/crypto.c
index 302fd749c424..43c3f1c971b8 100644
--- a/net/tipc/crypto.c
+++ b/net/tipc/crypto.c
@@ -1441,14 +1441,14 @@ static int tipc_crypto_key_revoke(struct net *net, u8 tx_key)
 	struct tipc_crypto *tx = tipc_net(net)->crypto_tx;
 	struct tipc_key key;
 
-	spin_lock(&tx->lock);
+	spin_lock_bh(&tx->lock);
 	key = tx->key;
 	WARN_ON(!key.active || tx_key != key.active);
 
 	/* Free the active key */
 	tipc_crypto_key_set_state(tx, key.passive, 0, key.pending);
 	tipc_crypto_key_detach(tx->aead[key.active], &tx->lock);
-	spin_unlock(&tx->lock);
+	spin_unlock_bh(&tx->lock);
 
 	pr_warn("%s: key is revoked\n", tx->name);
 	return -EKEYREVOKED;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] tipc: fix a potential deadlock on &tx->lock
  2023-09-27 18:14 [PATCH] tipc: fix a potential deadlock on &tx->lock Chengfeng Ye
@ 2023-09-29 18:29 ` Jacob Keller
  2023-10-01 17:46 ` Simon Horman
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Jacob Keller @ 2023-09-29 18:29 UTC (permalink / raw)
  To: Chengfeng Ye, jmaloy, ying.xue, davem, edumazet, kuba, pabeni
  Cc: netdev, tipc-discussion, linux-kernel



On 9/27/2023 11:14 AM, Chengfeng Ye wrote:
> It seems that tipc_crypto_key_revoke() could be be invoked by
> wokequeue tipc_crypto_work_rx() under process context and
> timer/rx callback under softirq context, thus the lock acquisition
> on &tx->lock seems better use spin_lock_bh() to prevent possible
> deadlock.
> 
> This flaw was found by an experimental static analysis tool I am
> developing for irq-related deadlock.
> 

Interesting.

> tipc_crypto_work_rx() <workqueue>
> --> tipc_crypto_key_distr()
> --> tipc_bcast_xmit()
> --> tipc_bcbase_xmit()
> --> tipc_bearer_bc_xmit()
> --> tipc_crypto_xmit()
> --> tipc_ehdr_build()
> --> tipc_crypto_key_revoke()
> --> spin_lock(&tx->lock)
> <timer interrupt>
>    --> tipc_disc_timeout()
>    --> tipc_bearer_xmit_skb()
>    --> tipc_crypto_xmit()
>    --> tipc_ehdr_build()
>    --> tipc_crypto_key_revoke()
>    --> spin_lock(&tx->lock) <deadlock here>
> 
> Signed-off-by: Chengfeng Ye <dg573847474@gmail.com>
> ---

Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>

>  net/tipc/crypto.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/net/tipc/crypto.c b/net/tipc/crypto.c
> index 302fd749c424..43c3f1c971b8 100644
> --- a/net/tipc/crypto.c
> +++ b/net/tipc/crypto.c
> @@ -1441,14 +1441,14 @@ static int tipc_crypto_key_revoke(struct net *net, u8 tx_key)
>  	struct tipc_crypto *tx = tipc_net(net)->crypto_tx;
>  	struct tipc_key key;
>  
> -	spin_lock(&tx->lock);
> +	spin_lock_bh(&tx->lock);
>  	key = tx->key;
>  	WARN_ON(!key.active || tx_key != key.active);
>  
>  	/* Free the active key */
>  	tipc_crypto_key_set_state(tx, key.passive, 0, key.pending);
>  	tipc_crypto_key_detach(tx->aead[key.active], &tx->lock);
> -	spin_unlock(&tx->lock);
> +	spin_unlock_bh(&tx->lock);
>  
>  	pr_warn("%s: key is revoked\n", tx->name);
>  	return -EKEYREVOKED;

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tipc: fix a potential deadlock on &tx->lock
  2023-09-27 18:14 [PATCH] tipc: fix a potential deadlock on &tx->lock Chengfeng Ye
  2023-09-29 18:29 ` Jacob Keller
@ 2023-10-01 17:46 ` Simon Horman
  2023-10-02 20:30 ` Jon Maloy
  2023-10-04 20:30 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 6+ messages in thread
From: Simon Horman @ 2023-10-01 17:46 UTC (permalink / raw)
  To: Chengfeng Ye
  Cc: jmaloy, ying.xue, davem, edumazet, kuba, pabeni, netdev,
	tipc-discussion, linux-kernel

On Wed, Sep 27, 2023 at 06:14:14PM +0000, Chengfeng Ye wrote:
> It seems that tipc_crypto_key_revoke() could be be invoked by
> wokequeue tipc_crypto_work_rx() under process context and
> timer/rx callback under softirq context, thus the lock acquisition
> on &tx->lock seems better use spin_lock_bh() to prevent possible
> deadlock.
> 
> This flaw was found by an experimental static analysis tool I am
> developing for irq-related deadlock.
> 
> tipc_crypto_work_rx() <workqueue>
> --> tipc_crypto_key_distr()
> --> tipc_bcast_xmit()
> --> tipc_bcbase_xmit()
> --> tipc_bearer_bc_xmit()
> --> tipc_crypto_xmit()
> --> tipc_ehdr_build()
> --> tipc_crypto_key_revoke()
> --> spin_lock(&tx->lock)
> <timer interrupt>
>    --> tipc_disc_timeout()
>    --> tipc_bearer_xmit_skb()
>    --> tipc_crypto_xmit()
>    --> tipc_ehdr_build()
>    --> tipc_crypto_key_revoke()
>    --> spin_lock(&tx->lock) <deadlock here>
> 
> Signed-off-by: Chengfeng Ye <dg573847474@gmail.com>


Hi Chengfeng Ye,

thanks for your patch.

As a fix for Networking this should probably be targeted at the
'net' tree. Which should be denoted in the subject.

        Subject: [PATCH net] ...

And as a fix this patch should probably have a Fixes tag.
This ones seem appropriate to me, but I could be wrong.

Fixes: fc1b6d6de220 ("tipc: introduce TIPC encryption & authentication")

I don't think it is necessary to repost just to address these issues,
but the Networking maintainers may think otherwise.

The code change itself looks good to me.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tipc: fix a potential deadlock on &tx->lock
  2023-09-27 18:14 [PATCH] tipc: fix a potential deadlock on &tx->lock Chengfeng Ye
  2023-09-29 18:29 ` Jacob Keller
  2023-10-01 17:46 ` Simon Horman
@ 2023-10-02 20:30 ` Jon Maloy
  2023-10-03  6:29   ` Chengfeng Ye
  2023-10-04 20:30 ` patchwork-bot+netdevbpf
  3 siblings, 1 reply; 6+ messages in thread
From: Jon Maloy @ 2023-10-02 20:30 UTC (permalink / raw)
  To: Chengfeng Ye, ying.xue, davem, edumazet, kuba, pabeni
  Cc: netdev, tipc-discussion, linux-kernel



On 2023-09-27 14:14, Chengfeng Ye wrote:
> It seems that tipc_crypto_key_revoke() could be be invoked by
> wokequeue tipc_crypto_work_rx() under process context and
> timer/rx callback under softirq context, thus the lock acquisition
> on &tx->lock seems better use spin_lock_bh() to prevent possible
> deadlock.
>
> This flaw was found by an experimental static analysis tool I am
> developing for irq-related deadlock.
>
> tipc_crypto_work_rx() <workqueue>
> --> tipc_crypto_key_distr()
> --> tipc_bcast_xmit()
> --> tipc_bcbase_xmit()
> --> tipc_bearer_bc_xmit()
> --> tipc_crypto_xmit()
> --> tipc_ehdr_build()
> --> tipc_crypto_key_revoke()
> --> spin_lock(&tx->lock)
> <timer interrupt>
>     --> tipc_disc_timeout()
>     --> tipc_bearer_xmit_skb()
>     --> tipc_crypto_xmit()
>     --> tipc_ehdr_build()
>     --> tipc_crypto_key_revoke()
>     --> spin_lock(&tx->lock) <deadlock here>
>
> Signed-off-by: Chengfeng Ye <dg573847474@gmail.com>
> ---
>   net/tipc/crypto.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/net/tipc/crypto.c b/net/tipc/crypto.c
> index 302fd749c424..43c3f1c971b8 100644
> --- a/net/tipc/crypto.c
> +++ b/net/tipc/crypto.c
> @@ -1441,14 +1441,14 @@ static int tipc_crypto_key_revoke(struct net *net, u8 tx_key)
>   	struct tipc_crypto *tx = tipc_net(net)->crypto_tx;
>   	struct tipc_key key;
>   
> -	spin_lock(&tx->lock);
> +	spin_lock_bh(&tx->lock);
>   	key = tx->key;
>   	WARN_ON(!key.active || tx_key != key.active);
>   
>   	/* Free the active key */
>   	tipc_crypto_key_set_state(tx, key.passive, 0, key.pending);
>   	tipc_crypto_key_detach(tx->aead[key.active], &tx->lock);
> -	spin_unlock(&tx->lock);
> +	spin_unlock_bh(&tx->lock);
>   
>   	pr_warn("%s: key is revoked\n", tx->name);
>   	return -EKEYREVOKED;
Acked-by: Jon Maloy <jmaloy@redhat.com>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tipc: fix a potential deadlock on &tx->lock
  2023-10-02 20:30 ` Jon Maloy
@ 2023-10-03  6:29   ` Chengfeng Ye
  0 siblings, 0 replies; 6+ messages in thread
From: Chengfeng Ye @ 2023-10-03  6:29 UTC (permalink / raw)
  To: Jon Maloy, Simon Horman
  Cc: ying.xue, davem, edumazet, kuba, pabeni, netdev, tipc-discussion,
	linux-kernel

Thanks much for your review.

Regards,
Chengfeng

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tipc: fix a potential deadlock on &tx->lock
  2023-09-27 18:14 [PATCH] tipc: fix a potential deadlock on &tx->lock Chengfeng Ye
                   ` (2 preceding siblings ...)
  2023-10-02 20:30 ` Jon Maloy
@ 2023-10-04 20:30 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-10-04 20:30 UTC (permalink / raw)
  To: Chengfeng Ye
  Cc: jmaloy, ying.xue, davem, edumazet, kuba, pabeni, netdev,
	tipc-discussion, linux-kernel

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 27 Sep 2023 18:14:14 +0000 you wrote:
> It seems that tipc_crypto_key_revoke() could be be invoked by
> wokequeue tipc_crypto_work_rx() under process context and
> timer/rx callback under softirq context, thus the lock acquisition
> on &tx->lock seems better use spin_lock_bh() to prevent possible
> deadlock.
> 
> This flaw was found by an experimental static analysis tool I am
> developing for irq-related deadlock.
> 
> [...]

Here is the summary with links:
  - tipc: fix a potential deadlock on &tx->lock
    https://git.kernel.org/netdev/net/c/08e50cf07184

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-10-04 20:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-27 18:14 [PATCH] tipc: fix a potential deadlock on &tx->lock Chengfeng Ye
2023-09-29 18:29 ` Jacob Keller
2023-10-01 17:46 ` Simon Horman
2023-10-02 20:30 ` Jon Maloy
2023-10-03  6:29   ` Chengfeng Ye
2023-10-04 20:30 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).