linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: qrtr: free memory on error path in radix_tree_insert()
@ 2023-01-25 13:48 Natalia Petrova
  2023-01-25 15:04 ` Simon Horman
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Natalia Petrova @ 2023-01-25 13:48 UTC (permalink / raw)
  To: Manivannan Sadhasivam
  Cc: Natalia Petrova, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, linux-arm-msm, netdev, linux-kernel, lvc-project

Function radix_tree_insert() returns errors if the node hasn't
been initialized and added to the tree.

"kfree(node)" and return value "NULL" of node_get() help
to avoid using unclear node in other calls.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 0c2204a4ad71 ("net: qrtr: Migrate nameservice to kernel from userspace")
Signed-off-by: Natalia Petrova <n.petrova@fintech.ru>
---
 net/qrtr/ns.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/qrtr/ns.c b/net/qrtr/ns.c
index 1990d496fcfc..e595079c2caf 100644
--- a/net/qrtr/ns.c
+++ b/net/qrtr/ns.c
@@ -83,7 +83,10 @@ static struct qrtr_node *node_get(unsigned int node_id)
 
 	node->id = node_id;
 
-	radix_tree_insert(&nodes, node_id, node);
+	if (radix_tree_insert(&nodes, node_id, node)) {
+		kfree(node);
+		return NULL;
+	}
 
 	return node;
 }
-- 
2.34.1


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

* Re: [PATCH] net: qrtr: free memory on error path in radix_tree_insert()
  2023-01-25 13:48 [PATCH] net: qrtr: free memory on error path in radix_tree_insert() Natalia Petrova
@ 2023-01-25 15:04 ` Simon Horman
  2023-01-27  5:55 ` Manivannan Sadhasivam
  2023-01-28  8:40 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Simon Horman @ 2023-01-25 15:04 UTC (permalink / raw)
  To: Natalia Petrova
  Cc: Manivannan Sadhasivam, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, linux-arm-msm, netdev, linux-kernel,
	lvc-project

On Wed, Jan 25, 2023 at 04:48:31PM +0300, Natalia Petrova wrote:
> Function radix_tree_insert() returns errors if the node hasn't
> been initialized and added to the tree.
> 
> "kfree(node)" and return value "NULL" of node_get() help
> to avoid using unclear node in other calls.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Fixes: 0c2204a4ad71 ("net: qrtr: Migrate nameservice to kernel from userspace")
> Signed-off-by: Natalia Petrova <n.petrova@fintech.ru>

Reviewed-by: Simon Horman <simon.horman@corigine.com>


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

* Re: [PATCH] net: qrtr: free memory on error path in radix_tree_insert()
  2023-01-25 13:48 [PATCH] net: qrtr: free memory on error path in radix_tree_insert() Natalia Petrova
  2023-01-25 15:04 ` Simon Horman
@ 2023-01-27  5:55 ` Manivannan Sadhasivam
  2023-01-28  8:40 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Manivannan Sadhasivam @ 2023-01-27  5:55 UTC (permalink / raw)
  To: Natalia Petrova
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	linux-arm-msm, netdev, linux-kernel, lvc-project

On Wed, Jan 25, 2023 at 04:48:31PM +0300, Natalia Petrova wrote:
> Function radix_tree_insert() returns errors if the node hasn't
> been initialized and added to the tree.
> 
> "kfree(node)" and return value "NULL" of node_get() help
> to avoid using unclear node in other calls.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Fixes: 0c2204a4ad71 ("net: qrtr: Migrate nameservice to kernel from userspace")
> Signed-off-by: Natalia Petrova <n.petrova@fintech.ru>

Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>

This patch should also be backported to stable kernels. Could you please add,

Cc: <stable@vger.kernel.org> # 5.7

Thanks,
Mani

> ---
>  net/qrtr/ns.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/net/qrtr/ns.c b/net/qrtr/ns.c
> index 1990d496fcfc..e595079c2caf 100644
> --- a/net/qrtr/ns.c
> +++ b/net/qrtr/ns.c
> @@ -83,7 +83,10 @@ static struct qrtr_node *node_get(unsigned int node_id)
>  
>  	node->id = node_id;
>  
> -	radix_tree_insert(&nodes, node_id, node);
> +	if (radix_tree_insert(&nodes, node_id, node)) {
> +		kfree(node);
> +		return NULL;
> +	}
>  
>  	return node;
>  }
> -- 
> 2.34.1
> 

-- 
மணிவண்ணன் சதாசிவம்

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

* Re: [PATCH] net: qrtr: free memory on error path in radix_tree_insert()
  2023-01-25 13:48 [PATCH] net: qrtr: free memory on error path in radix_tree_insert() Natalia Petrova
  2023-01-25 15:04 ` Simon Horman
  2023-01-27  5:55 ` Manivannan Sadhasivam
@ 2023-01-28  8:40 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-01-28  8:40 UTC (permalink / raw)
  To: Natalia Petrova
  Cc: mani, davem, edumazet, kuba, pabeni, linux-arm-msm, netdev,
	linux-kernel, lvc-project

Hello:

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

On Wed, 25 Jan 2023 16:48:31 +0300 you wrote:
> Function radix_tree_insert() returns errors if the node hasn't
> been initialized and added to the tree.
> 
> "kfree(node)" and return value "NULL" of node_get() help
> to avoid using unclear node in other calls.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> [...]

Here is the summary with links:
  - net: qrtr: free memory on error path in radix_tree_insert()
    https://git.kernel.org/netdev/net/c/29de68c2b32c

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] 4+ messages in thread

end of thread, other threads:[~2023-01-28  8:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-25 13:48 [PATCH] net: qrtr: free memory on error path in radix_tree_insert() Natalia Petrova
2023-01-25 15:04 ` Simon Horman
2023-01-27  5:55 ` Manivannan Sadhasivam
2023-01-28  8:40 ` 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).