Skip to contentSkip to conversation

net/ceph/messenger: support IPv6 Link-Local with scope identifier

PATCH Superseded Max Kellermann 2 participants 2 messages Jul 6 Ceph common code (libceph)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net/ceph/messenger: support IPv6 Link-Local with scope identifier

Implement ceph_pton() using inet_pton_with_scope(). This minimal patch preserves the ceph_pton() API and thus requires copying the parameter to a null-terminated string.

---
v1->v2:
- check "ipend" before dereferencing it

---
 net/ceph/messenger.c | 37 ++++++++++++++++++++++++++++---------
 1 file changed, 28 insertions(+), 9 deletions(-)
net/ceph/messenger.c +28 -9
index 34b3097b4c7b..f7c7179589af 100644
@@ -1221,19 +1221,38 @@ void ceph_addr_set_port(struct ceph_entity_addr *addr, int p)
 static int ceph_pton(const char *str, size_t len, struct ceph_entity_addr *addr,
 		char delim, const char **ipend)
 {
-	memset(&addr->in_addr, 0, sizeof(addr->in_addr));
+	const char *delim_p;
+	char *copy;
+	struct sockaddr_storage stor = { 0 };
+	int ret;
 
-	if (in4_pton(str, len, (u8 *)&((struct sockaddr_in *)&addr->in_addr)->sin_addr.s_addr, delim, ipend)) {
-		put_unaligned(AF_INET, &addr->in_addr.ss_family);
-		return 0;
-	}
+	delim_p = memchr(str, delim, len);
+	if (delim_p)
+		/* delimiter was found - stop parsing there */
+		len = delim_p - str;
 
-	if (in6_pton(str, len, (u8 *)&((struct sockaddr_in6 *)&addr->in_addr)->sin6_addr.s6_addr, delim, ipend)) {
-		put_unaligned(AF_INET6, &addr->in_addr.ss_family);
-		return 0;
+	/* the input string might not be null terminated, so copy it
+	 * to a null-terminated string
+	 */
+	copy = kstrndup(str, len, GFP_NOFS);
+	if (!copy)
+		return -ENOMEM;
+
+	ret = inet_pton_with_scope(&init_net, AF_UNSPEC, copy, NULL, &stor);
+	kfree(copy);
+
+	if (!ret) {
+		/* ceph_entity_addr might be misaligned, so we have to
+		 * parse to a stack variable first
+		 */
+		memcpy(&addr->in_addr, &stor, sizeof(stor));
+
+		/* return the end of the parsed portion to the caller on success */
+		if (ipend)
+		    *ipend = str + len;
 	}
 
-	return -EINVAL;
+	return ret;
 }
 
 /*
Signature · 1 line
2.47.3
maintainer
#1 lore raw

Hi Max,

NACK for now. Thanks for the patch, but I have some concerns that need a v2:

1. [critical] net/ceph/messenger.c:1241: IPv4 addresses with explicit ports no longer parse correctly ceph_pton() now sets *ipend = str + len, where len extends to
the list delimiter (comma/end-of-string). For
10.0.0.1:7001,10.0.0.2:7001, ipend lands on the comma, not the
colon. The caller ceph_parse_ips() (line 1350) checks `*ipend ==
':'` to find the port — it never will. Depending on how
inet_pton_with_scope() handles the trailing :7001 in the
address string, this either silently defaults every monitor to
CEPH_MON_PORT or fails the parse entirely. Either way, existing
mount strings with explicit ports regress.
Suggested fix: Split the address from the port before passing to inet_pton_with_scope(), or set *ipend to where the address
portion actually ends (before the colon) so the caller's
port-parsing logic still works.
2. [major] net/ceph/messenger.c:1241: init_net instead of caller's network namespace The patch passes &init_net to inet_pton_with_scope(). The rest
of the file uses the caller's namespace: ceph_messenger_init()
saves current->nsproxy->net_ns into msgr->net (line 1695), sock_create_kern() uses read_pnet(&con->msgr->net) (line 448),
and dns_query() uses current->nsproxy->net_ns (line 1271).
Resolving %eth0 scope identifiers against init_net will
silently break in containers where the interface only exists in the
container's namespace — exactly where link-local addresses are most
commonly used.
Suggested fix: Use current->nsproxy->net_ns instead of
&init_net.
3. [nit] net/ceph/messenger.c:1252: Spaces instead of tab indentation
Line is indented with spaces instead of tabs. Kernel coding style
requires tabs.
Suggested fix: Replace the 4 spaces with a tab.

New ipend placement breaks IPv4 port parsing (regression); init_net wrong namespace for container use.

Signature · 1 line
Alex Markuze