From: Natalia Petrova Date: Wed, 25 Jan 2023 13:48:31 +0000 (+0300) Subject: net: qrtr: free memory on error path in radix_tree_insert() X-Git-Tag: baikal/aarch64/sdk6.1~91 X-Git-Url: https://git.baikalelectronics.ru/sdk/?a=commitdiff_plain;h=c377a7c920216a6a1c8b9027e66c72193e3b33f0;p=kernel.git net: qrtr: free memory on error path in radix_tree_insert() commit 29de68c2b32ce58d64dea496d281e25ad0f551bd upstream. 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. Cc: # 5.7 Fixes: c2942963826d ("net: qrtr: Migrate nameservice to kernel from userspace") Signed-off-by: Natalia Petrova Reviewed-by: Simon Horman Reviewed-by: Manivannan Sadhasivam Link: https://lore.kernel.org/r/20230125134831.8090-1-n.petrova@fintech.ru Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- diff --git a/net/qrtr/ns.c b/net/qrtr/ns.c index 1990d496fcfc0..e595079c2cafe 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; }