diff mbox series

[v2] tipc: stop tipc crypto on failure in tipc_node_create

Message ID 20230725214628.25246-1-pchelkin@ispras.ru (mailing list archive)
State Accepted
Commit de52e17326c3e9a719c9ead4adb03467b8fae0ef
Delegated to: Netdev Maintainers
Headers show
Series [v2] tipc: stop tipc crypto on failure in tipc_node_create | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1342 this patch: 1342
netdev/cc_maintainers success CCed 9 of 9 maintainers
netdev/build_clang success Errors and warnings before: 1365 this patch: 1365
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 1365 this patch: 1365
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Fedor Pchelkin July 25, 2023, 9:46 p.m. UTC
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(-)

Comments

Xin Long July 25, 2023, 9:55 p.m. UTC | #1
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>
patchwork-bot+netdevbpf@kernel.org July 27, 2023, 10:10 a.m. UTC | #2
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!
diff mbox series

Patch

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;
 	}