From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D2B3256C61 for ; Mon, 4 May 2026 05:05:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777871120; cv=none; b=TNBq3Xi4DaR9vWMaijsIbjTeDjDJ+mV2MG0pijZ31cvsq/UajiK/rOHSNyrjlAgcqM5uDsZaV3XWG7kJOi0M6uPvdHckehlnKKm0WXrB2+NPxJyyEC45IBpfH1T/VqGEErFIUvXXn4dx5w/xaS1nje/PN0Lm4Tbekl1aIloFZIo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777871120; c=relaxed/simple; bh=M2sWS/gg3dwrAE97fSBa8c2uQW7Y0vw0Jt57zP5QY8Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ciITPns0/cs6Rm7lEG7598Cw8K/OPEd0KPAFf/28oNC0sLIEGagfjdbBkTCF53pYBwGIXYNHTcrfkrS8WgX50r6AGue5+gqYEG+RQF3bitEJUpJsg32dy691obrKra3vzWeq8sEwzicYxCdZSn3YrPEvJpvafPoafqfgxXaCQyg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FqzG6Dse; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FqzG6Dse" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ADF95C2BCB8; Mon, 4 May 2026 05:05:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777871119; bh=M2sWS/gg3dwrAE97fSBa8c2uQW7Y0vw0Jt57zP5QY8Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FqzG6Dsen3cIzBqtfsHFvK5CQTr9Z//pu14l78utWByGHpUo2jFmPNihPqtJo9uir 5Ghc6ZNOo3fBhi6mO+ja6QSG7V3ywNa5wLy2gzluQ/Xw9uKPDEZ13D3P9iD4nMzzaC 5rmWYMFi9H8qSlgQiFJXYq4PMh+AvJjXu7WMVWuG1cN18mi1Zk9eHRUP02YzSvtjtH k9EumhpBjT0dz3oE8xdXakxf7v7QJwoIC2qQnQOv/PZoP7LhcRpPwBZBoeQOUFA6eo 0C46eSW0bIuEmoycXEdjzZ8Re6qYqs6m3flh4BLih1j+5a4ZhHmMjFrT6CRXfzTaTt zOV9FU5KJtYiA== From: Sasha Levin To: stable@vger.kernel.org Cc: Manivannan Sadhasivam , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.15.y] net: qrtr: ns: Limit the maximum number of lookups Date: Mon, 4 May 2026 01:05:10 -0400 Message-ID: <20260504050510.1612332-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026050119-liking-frill-4504@gregkh> References: <2026050119-liking-frill-4504@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Manivannan Sadhasivam [ Upstream commit 5640227d9a21c6a8be249a10677b832e7f40dc55 ] Current code does no bound checking on the number of lookups a client can perform. Though the code restricts the lookups to local clients, there is still a possibility of a malicious local client sending a flood of NEW_LOOKUP messages over the same socket. Fix this issue by limiting the maximum number of lookups to 64 globally. Since the nameserver allows only atmost one local observer, this global lookup count will ensure that the lookups stay within the limit. 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: 0c2204a4ad71 ("net: qrtr: Migrate nameservice to kernel from userspace") Signed-off-by: Manivannan Sadhasivam Link: https://patch.msgid.link/20260409-qrtr-fix-v3-2-00a8a5ff2b51@oss.qualcomm.com Signed-off-by: Jakub Kicinski [ adapted comment block to only mention QRTR_NS_MAX_LOOKUPS and kept kzalloc() instead of kzalloc_obj() due to missing prerequisite commits ] Signed-off-by: Sasha Levin --- net/qrtr/ns.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/net/qrtr/ns.c b/net/qrtr/ns.c index 3c513e7ca2d5c..4c9982e80d460 100644 --- a/net/qrtr/ns.c +++ b/net/qrtr/ns.c @@ -21,6 +21,7 @@ static struct { struct socket *sock; struct sockaddr_qrtr bcast_sq; struct list_head lookups; + u32 lookup_count; struct workqueue_struct *workqueue; struct work_struct work; int local_node; @@ -68,6 +69,11 @@ struct qrtr_node { struct radix_tree_root servers; }; +/* Max lookup limit is chosen based on the current platform requirements. If the + * requirement changes in the future, this value can be increased. + */ +#define QRTR_NS_MAX_LOOKUPS 64 + static struct qrtr_node *node_get(unsigned int node_id) { struct qrtr_node *node; @@ -456,6 +462,7 @@ static int ctrl_cmd_del_client(struct sockaddr_qrtr *from, list_del(&lookup->li); kfree(lookup); + qrtr_ns.lookup_count--; } /* Remove the server belonging to this port but don't broadcast @@ -589,6 +596,11 @@ static int ctrl_cmd_new_lookup(struct sockaddr_qrtr *from, if (from->sq_node != qrtr_ns.local_node) return -EINVAL; + if (qrtr_ns.lookup_count >= QRTR_NS_MAX_LOOKUPS) { + pr_err_ratelimited("QRTR client node exceeds max lookup limit!\n"); + return -ENOSPC; + } + lookup = kzalloc(sizeof(*lookup), GFP_KERNEL); if (!lookup) return -ENOMEM; @@ -597,6 +609,7 @@ static int ctrl_cmd_new_lookup(struct sockaddr_qrtr *from, lookup->service = service; lookup->instance = instance; list_add_tail(&lookup->li, &qrtr_ns.lookups); + qrtr_ns.lookup_count++; memset(&filter, 0, sizeof(filter)); filter.service = service; @@ -663,6 +676,7 @@ static void ctrl_cmd_del_lookup(struct sockaddr_qrtr *from, list_del(&lookup->li); kfree(lookup); + qrtr_ns.lookup_count--; } } -- 2.53.0