netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tipc: stop tipc crypto on failure in tipc_node_create
@ 2023-07-25 18:36 Fedor Pchelkin
  2023-07-25 19:46 ` Xin Long
  0 siblings, 1 reply; 6+ messages in thread
From: Fedor Pchelkin @ 2023-07-25 18:36 UTC (permalink / raw)
  To: Jon Maloy
  Cc: Fedor Pchelkin, Ying Xue, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Xin Long, netdev, tipc-discussion,
	linux-kernel, Alexey Khoroshilov, lvc-project

If tipc_link_bc_create() fails inside tipc_node_create() for a newly
allocated tipc node then we should stop its tipc crypto and free the
resources allocated with a call to tipc_crypto_start().

Call tipc_crypto_stop() in that case. Also extract the similar error exit
paths into a goto statement.

Found by Linux Verification Center (linuxtesting.org).

Fixes: cb8092d70a6f ("tipc: move bc link creation back to tipc_node_create")
Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
---
 net/tipc/node.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/net/tipc/node.c b/net/tipc/node.c
index 5e000fde8067..0d64005a803b 100644
--- a/net/tipc/node.c
+++ b/net/tipc/node.c
@@ -546,9 +546,7 @@ struct tipc_node *tipc_node_create(struct net *net, u32 addr, u8 *peer_id,
 #ifdef CONFIG_TIPC_CRYPTO
 	if (unlikely(tipc_crypto_start(&n->crypto_rx, net, n))) {
 		pr_warn("Failed to start crypto RX(%s)!\n", n->peer_id_string);
-		kfree(n);
-		n = NULL;
-		goto exit;
+		goto free_node;
 	}
 #endif
 	n->addr = addr;
@@ -583,9 +581,7 @@ struct tipc_node *tipc_node_create(struct net *net, u32 addr, u8 *peer_id,
 				 n->capabilities, &n->bc_entry.inputq1,
 				 &n->bc_entry.namedq, snd_l, &n->bc_entry.link)) {
 		pr_warn("Broadcast rcv link creation failed, no memory\n");
-		kfree(n);
-		n = NULL;
-		goto exit;
+		goto stop_crypto;
 	}
 	tipc_node_get(n);
 	timer_setup(&n->timer, tipc_node_timeout, 0);
@@ -610,6 +606,15 @@ struct tipc_node *tipc_node_create(struct net *net, u32 addr, u8 *peer_id,
 exit:
 	spin_unlock_bh(&tn->node_list_lock);
 	return n;
+stop_crypto:
+
+#ifdef CONFIG_TIPC_CRYPTO
+	tipc_crypto_stop(&n->crypto_rx);
+free_node:
+#endif
+	kfree(n);
+	spin_unlock_bh(&tn->node_list_lock);
+	return NULL;
 }
 
 static void tipc_node_calculate_timer(struct tipc_node *n, struct tipc_link *l)
-- 
2.41.0


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

* Re: [PATCH] tipc: stop tipc crypto on failure in tipc_node_create
  2023-07-25 18:36 [PATCH] tipc: stop tipc crypto on failure in tipc_node_create Fedor Pchelkin
@ 2023-07-25 19:46 ` Xin Long
  2023-07-25 21:38   ` Fedor Pchelkin
  0 siblings, 1 reply; 6+ messages in thread
From: Xin Long @ 2023-07-25 19:46 UTC (permalink / raw)
  To: Fedor Pchelkin
  Cc: Jon Maloy, Ying Xue, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, tipc-discussion,
	linux-kernel, Alexey Khoroshilov, lvc-project

On Tue, Jul 25, 2023 at 2:37 PM Fedor Pchelkin <pchelkin@ispras.ru> wrote:
>
> If tipc_link_bc_create() fails inside tipc_node_create() for a newly
> allocated tipc node then we should stop its tipc crypto and free the
> resources allocated with a call to tipc_crypto_start().
>
> Call tipc_crypto_stop() in that case. Also extract the similar error exit
> paths into a goto statement.
>
> Found by Linux Verification Center (linuxtesting.org).
>
> Fixes: cb8092d70a6f ("tipc: move bc link creation back to tipc_node_create")
> Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
> ---
>  net/tipc/node.c | 17 +++++++++++------
>  1 file changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/net/tipc/node.c b/net/tipc/node.c
> index 5e000fde8067..0d64005a803b 100644
> --- a/net/tipc/node.c
> +++ b/net/tipc/node.c
> @@ -546,9 +546,7 @@ struct tipc_node *tipc_node_create(struct net *net, u32 addr, u8 *peer_id,
>  #ifdef CONFIG_TIPC_CRYPTO
>         if (unlikely(tipc_crypto_start(&n->crypto_rx, net, n))) {
>                 pr_warn("Failed to start crypto RX(%s)!\n", n->peer_id_string);
> -               kfree(n);
> -               n = NULL;
> -               goto exit;
> +               goto free_node;
>         }
>  #endif
>         n->addr = addr;
> @@ -583,9 +581,7 @@ struct tipc_node *tipc_node_create(struct net *net, u32 addr, u8 *peer_id,
>                                  n->capabilities, &n->bc_entry.inputq1,
>                                  &n->bc_entry.namedq, snd_l, &n->bc_entry.link)) {
>                 pr_warn("Broadcast rcv link creation failed, no memory\n");
> -               kfree(n);
> -               n = NULL;
> -               goto exit;
> +               goto stop_crypto;
>         }
>         tipc_node_get(n);
Can you please try moving up tipc_node_get(n) ahead tipc_link_bc_create()
and use tipc_node_put(n) to replace kfree(n) to avoid the extra
tipc_crypto_stop() call below?

Thanks.

>         timer_setup(&n->timer, tipc_node_timeout, 0);
> @@ -610,6 +606,15 @@ struct tipc_node *tipc_node_create(struct net *net, u32 addr, u8 *peer_id,
>  exit:
>         spin_unlock_bh(&tn->node_list_lock);
>         return n;
> +stop_crypto:
> +
> +#ifdef CONFIG_TIPC_CRYPTO
> +       tipc_crypto_stop(&n->crypto_rx);
> +free_node:
> +#endif
> +       kfree(n);
> +       spin_unlock_bh(&tn->node_list_lock);
> +       return NULL;
>  }
>
>  static void tipc_node_calculate_timer(struct tipc_node *n, struct tipc_link *l)
> --
> 2.41.0
>

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

* Re: [PATCH] tipc: stop tipc crypto on failure in tipc_node_create
  2023-07-25 19:46 ` Xin Long
@ 2023-07-25 21:38   ` Fedor Pchelkin
  2023-07-25 21:46     ` [PATCH v2] " Fedor Pchelkin
  0 siblings, 1 reply; 6+ messages in thread
From: Fedor Pchelkin @ 2023-07-25 21:38 UTC (permalink / raw)
  To: Xin Long
  Cc: Jon Maloy, Ying Xue, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, tipc-discussion,
	linux-kernel, Alexey Khoroshilov, lvc-project

On 23/07/25 03:46PM, Xin Long wrote:
> On Tue, Jul 25, 2023 at 2:37 PM Fedor Pchelkin <pchelkin@ispras.ru> wrote:
> >
> > If tipc_link_bc_create() fails inside tipc_node_create() for a newly
> > allocated tipc node then we should stop its tipc crypto and free the
> > resources allocated with a call to tipc_crypto_start().
> >
> > Call tipc_crypto_stop() in that case. Also extract the similar error exit
> > paths into a goto statement.
> >
> > Found by Linux Verification Center (linuxtesting.org).
> >
> > Fixes: cb8092d70a6f ("tipc: move bc link creation back to tipc_node_create")
> > Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
> > ---
> >  net/tipc/node.c | 17 +++++++++++------
> >  1 file changed, 11 insertions(+), 6 deletions(-)
> >
> > diff --git a/net/tipc/node.c b/net/tipc/node.c
> > index 5e000fde8067..0d64005a803b 100644
> > --- a/net/tipc/node.c
> > +++ b/net/tipc/node.c
> > @@ -546,9 +546,7 @@ struct tipc_node *tipc_node_create(struct net *net, u32 addr, u8 *peer_id,
> >  #ifdef CONFIG_TIPC_CRYPTO
> >         if (unlikely(tipc_crypto_start(&n->crypto_rx, net, n))) {
> >                 pr_warn("Failed to start crypto RX(%s)!\n", n->peer_id_string);
> > -               kfree(n);
> > -               n = NULL;
> > -               goto exit;
> > +               goto free_node;
> >         }
> >  #endif
> >         n->addr = addr;
> > @@ -583,9 +581,7 @@ struct tipc_node *tipc_node_create(struct net *net, u32 addr, u8 *peer_id,
> >                                  n->capabilities, &n->bc_entry.inputq1,
> >                                  &n->bc_entry.namedq, snd_l, &n->bc_entry.link)) {
> >                 pr_warn("Broadcast rcv link creation failed, no memory\n");
> > -               kfree(n);
> > -               n = NULL;
> > -               goto exit;
> > +               goto stop_crypto;
> >         }
> >         tipc_node_get(n);
> Can you please try moving up tipc_node_get(n) ahead tipc_link_bc_create()
> and use tipc_node_put(n) to replace kfree(n) to avoid the extra
> tipc_crypto_stop() call below?
> 
> Thanks.
> 

Guess moving tipc_node_get() before tipc_link_bc_create() would not solve
the problem as ref is already initialized to 1 at that point. So just
replacing direct kfree() with tipc_node_put() will fix it.

Thank you for advice! I'll resend the v2 shortly.

> >         timer_setup(&n->timer, tipc_node_timeout, 0);
> > @@ -610,6 +606,15 @@ struct tipc_node *tipc_node_create(struct net *net, u32 addr, u8 *peer_id,
> >  exit:
> >         spin_unlock_bh(&tn->node_list_lock);
> >         return n;
> > +stop_crypto:
> > +
> > +#ifdef CONFIG_TIPC_CRYPTO
> > +       tipc_crypto_stop(&n->crypto_rx);
> > +free_node:
> > +#endif
> > +       kfree(n);
> > +       spin_unlock_bh(&tn->node_list_lock);
> > +       return NULL;
> >  }
> >
> >  static void tipc_node_calculate_timer(struct tipc_node *n, struct tipc_link *l)
> > --
> > 2.41.0
> >

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

* [PATCH v2] tipc: stop tipc crypto on failure in tipc_node_create
  2023-07-25 21:38   ` Fedor Pchelkin
@ 2023-07-25 21:46     ` Fedor Pchelkin
  2023-07-25 21:55       ` Xin Long
  2023-07-27 10:10       ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 6+ messages in thread
From: Fedor Pchelkin @ 2023-07-25 21:46 UTC (permalink / raw)
  To: Jon Maloy
  Cc: Fedor Pchelkin, Ying Xue, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Xin Long, netdev, tipc-discussion,
	linux-kernel, Alexey Khoroshilov, lvc-project

If tipc_link_bc_create() fails inside tipc_node_create() for a newly
allocated tipc node then we should stop its tipc crypto and free the
resources allocated with a call to tipc_crypto_start().

As the node ref is initialized to one to that point, just put the ref on
tipc_link_bc_create() error case that would lead to tipc_node_free() be
eventually executed and properly clean the node and its crypto resources.

Found by Linux Verification Center (linuxtesting.org).

Fixes: cb8092d70a6f ("tipc: move bc link creation back to tipc_node_create")
Suggested-by: Xin Long <lucien.xin@gmail.com>
Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
---
v1->v2: simplify the patch per Xin Long's advice: putting the ref on error
case would solve the problem more conveniently; update the patch
description accordingly.

 net/tipc/node.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/tipc/node.c b/net/tipc/node.c
index 5e000fde8067..a9c5b6594889 100644
--- a/net/tipc/node.c
+++ b/net/tipc/node.c
@@ -583,7 +583,7 @@ struct tipc_node *tipc_node_create(struct net *net, u32 addr, u8 *peer_id,
 				 n->capabilities, &n->bc_entry.inputq1,
 				 &n->bc_entry.namedq, snd_l, &n->bc_entry.link)) {
 		pr_warn("Broadcast rcv link creation failed, no memory\n");
-		kfree(n);
+		tipc_node_put(n);
 		n = NULL;
 		goto exit;
 	}
-- 
2.41.0


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

* Re: [PATCH v2] tipc: stop tipc crypto on failure in tipc_node_create
  2023-07-25 21:46     ` [PATCH v2] " Fedor Pchelkin
@ 2023-07-25 21:55       ` Xin Long
  2023-07-27 10:10       ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 6+ messages in thread
From: Xin Long @ 2023-07-25 21:55 UTC (permalink / raw)
  To: Fedor Pchelkin
  Cc: Jon Maloy, Ying Xue, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, tipc-discussion,
	linux-kernel, Alexey Khoroshilov, lvc-project

On Tue, Jul 25, 2023 at 5:46 PM Fedor Pchelkin <pchelkin@ispras.ru> wrote:
>
> If tipc_link_bc_create() fails inside tipc_node_create() for a newly
> allocated tipc node then we should stop its tipc crypto and free the
> resources allocated with a call to tipc_crypto_start().
>
> As the node ref is initialized to one to that point, just put the ref on
> tipc_link_bc_create() error case that would lead to tipc_node_free() be
> eventually executed and properly clean the node and its crypto resources.
>
> Found by Linux Verification Center (linuxtesting.org).
>
> Fixes: cb8092d70a6f ("tipc: move bc link creation back to tipc_node_create")
> Suggested-by: Xin Long <lucien.xin@gmail.com>
> Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
> ---
> v1->v2: simplify the patch per Xin Long's advice: putting the ref on error
> case would solve the problem more conveniently; update the patch
> description accordingly.
>
>  net/tipc/node.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/tipc/node.c b/net/tipc/node.c
> index 5e000fde8067..a9c5b6594889 100644
> --- a/net/tipc/node.c
> +++ b/net/tipc/node.c
> @@ -583,7 +583,7 @@ struct tipc_node *tipc_node_create(struct net *net, u32 addr, u8 *peer_id,
>                                  n->capabilities, &n->bc_entry.inputq1,
>                                  &n->bc_entry.namedq, snd_l, &n->bc_entry.link)) {
>                 pr_warn("Broadcast rcv link creation failed, no memory\n");
> -               kfree(n);
> +               tipc_node_put(n);
>                 n = NULL;
>                 goto exit;
>         }
> --
> 2.41.0
>
Reviewed-by: Xin Long <lucien.xin@gmail.com>

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

* Re: [PATCH v2] tipc: stop tipc crypto on failure in tipc_node_create
  2023-07-25 21:46     ` [PATCH v2] " Fedor Pchelkin
  2023-07-25 21:55       ` Xin Long
@ 2023-07-27 10:10       ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-07-27 10:10 UTC (permalink / raw)
  To: Fedor Pchelkin
  Cc: jmaloy, ying.xue, davem, edumazet, kuba, pabeni, lucien.xin,
	netdev, tipc-discussion, linux-kernel, khoroshilov, lvc-project

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Wed, 26 Jul 2023 00:46:25 +0300 you wrote:
> If tipc_link_bc_create() fails inside tipc_node_create() for a newly
> allocated tipc node then we should stop its tipc crypto and free the
> resources allocated with a call to tipc_crypto_start().
> 
> As the node ref is initialized to one to that point, just put the ref on
> tipc_link_bc_create() error case that would lead to tipc_node_free() be
> eventually executed and properly clean the node and its crypto resources.
> 
> [...]

Here is the summary with links:
  - [v2] tipc: stop tipc crypto on failure in tipc_node_create
    https://git.kernel.org/netdev/net/c/de52e17326c3

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-07-27 10:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-25 18:36 [PATCH] tipc: stop tipc crypto on failure in tipc_node_create Fedor Pchelkin
2023-07-25 19:46 ` Xin Long
2023-07-25 21:38   ` Fedor Pchelkin
2023-07-25 21:46     ` [PATCH v2] " Fedor Pchelkin
2023-07-25 21:55       ` Xin Long
2023-07-27 10:10       ` 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).