Skip to contentSkip to conversation

net: qrtr: ns: reject BYE from local sockets

PATCH New Murali Krishna 1 participant 1 message Dec 4

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: qrtr: ns: reject BYE from local sockets

ctrl_cmd_bye() acts on whichever node sent the BYE. Any local socket, including an unprivileged one, can send to the name server's control port, and a local sender's node is the local node. Such a BYE makes the name server delete every server registered on the local node, announce DEL_SERVER for each to the other nodes and to local lookups, and free the local node's record. The services stay unlisted until they register again.

The other handlers already stop a local sender from acting for anyone but itself: a local NEW_SERVER or DEL_SERVER applies to the sender's own port, a local DEL_CLIENT must come from the port being closed, and DEL_LOOKUP removes only the sender's lookups. A genuine BYE is always for a remote node: qrtr_endpoint_unregister() sends one for each node an endpoint carried, and a remote node can send its own. Reject a BYE from the local node.

Hui Peng reported this with a patch that required a BYE to come from the control port [1]. As its review noted, a remote BYE can carry the legacy control port 0xffff as its source, since qrtr_endpoint_post() maps the legacy value only for the destination port, so that check could also drop genuine BYEs. Checking for a local sender, as the review suggested, leaves remote BYEs alone.

It was found again by an AI coding assistant while working on an IPA fix that involves the same BYE path, and reproduced as an unprivileged user on a distribution 7.0 kernel: after one socket sends a QRTR_TYPE_BYE control packet to the local control port, the name server no longer lists a service registered by another socket, and a lookup client gets DEL_SERVER for it, while a PING sent the same way changes nothing. The fix itself is build-tested only (arm64, W=1). The fix and this message were drafted with an LLM coding assistant and reviewed by me.

Fixes 0c2204a4ad71 ("net: qrtr: Migrate nameservice to kernel from userspace")

---
Hui, your patch for this has been at changes-requested since September, so I picked it up and kept you as Reported-by. This version only rejects a BYE from a local sender, as the review of your patch suggested, and leaves its short-packet part alone.

I have a small unprivileged test program that shows the problem and can send it to the maintainers if it helps.

 net/qrtr/ns.c | 4 ++++
 1 file changed, 4 insertions(+)
net/qrtr/ns.c +4 -0
index 8209573221a5..ab75992224e0 100644
@@ -347,6 +347,10 @@ static int ctrl_cmd_bye(struct sockaddr_qrtr *from)
 	iv.iov_base = &pkt;
 	iv.iov_len = sizeof(pkt);
 
+	/* Only a remote node goes away; a local socket can't say BYE for one */
+	if (from->sq_node == qrtr_ns.local_node)
+		return -EINVAL;
+
 	node = node_get(from->sq_node);
 	if (!node)
 		return 0;

base-commit: c1c39137dcc3134010566ff29a81c93124efa539

Signature · 1 line
2.43.0