Skip to content

Commit 4c46413

Browse files
Mani-Sadhasivamgregkh
authored andcommitted
net: qrtr: ns: Limit the total number of nodes
[ Upstream commit 27d5e84 ] Currently, the nameserver doesn't limit the number of nodes it handles. This can be an attack vector if a malicious client starts registering random nodes, leading to memory exhaustion. Hence, limit the maximum number of nodes to 64. Note that, limit of 64 is chosen based on the current platform requirements. If requirement changes in the future, this limit can be increased. Cc: stable@vger.kernel.org Fixes: 0c2204a ("net: qrtr: Migrate nameservice to kernel from userspace") Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com> Link: https://patch.msgid.link/20260409-qrtr-fix-v3-4-00a8a5ff2b51@oss.qualcomm.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> [ dropped comment/define changes for missing QRTR_NS_MAX_SERVERS/LOOKUPS prereqs and kept plain kzalloc instead of kzalloc_obj ] Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0dbec10 commit 4c46413

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

net/qrtr/ns.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ struct qrtr_node {
8282
*/
8383
#define QRTR_NS_MAX_LOOKUPS 64
8484

85+
/* Max nodes limit is chosen based on the current platform requirements.
86+
* If the requirement changes in the future, this value can be increased.
87+
*/
88+
#define QRTR_NS_MAX_NODES 64
89+
90+
static u8 node_count;
91+
8592
static struct qrtr_node *node_get(unsigned int node_id)
8693
{
8794
struct qrtr_node *node;
@@ -90,6 +97,11 @@ static struct qrtr_node *node_get(unsigned int node_id)
9097
if (node)
9198
return node;
9299

100+
if (node_count >= QRTR_NS_MAX_NODES) {
101+
pr_err_ratelimited("QRTR clients exceed max node limit!\n");
102+
return NULL;
103+
}
104+
93105
/* If node didn't exist, allocate and insert it to the tree */
94106
node = kzalloc(sizeof(*node), GFP_KERNEL);
95107
if (!node)
@@ -103,6 +115,8 @@ static struct qrtr_node *node_get(unsigned int node_id)
103115
return NULL;
104116
}
105117

118+
node_count++;
119+
106120
return node;
107121
}
108122

@@ -406,6 +420,7 @@ static int ctrl_cmd_bye(struct sockaddr_qrtr *from)
406420
delete_node:
407421
xa_erase(&nodes, from->sq_node);
408422
kfree(node);
423+
node_count--;
409424

410425
return ret;
411426
}

0 commit comments

Comments
 (0)