Subject: Re: [PATCH] net: qrtr: free memory on error path in radix_tree_insert()

From: Manivannan Sadhasivam <[email-masked]>
Date: Fri, 27 Jan 2023 11:25:09 +0530

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 <[email-masked]>

Reviewed-by: Manivannan Sadhasivam <[email-masked]>

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

Cc: <[email-masked]> # 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
> 

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