mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [BUG] mptcp: pm: WARNING in mptcp_check_listen_stop() when listen fails on a new endpoint listener
@ 2026-11-18 16:59 Kyuwon Cho
  2026-11-18 18:18 ` Matthieu Baerts
  0 siblings, 1 reply; 3+ messages in thread
From: Kyuwon Cho @ 2026-11-18 16:59 UTC (permalink / raw)
  To: Matthieu Baerts, Mat Martineau, Geliang Tang
  Cc: Paolo Abeni, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Simon Horman, mptcp, netdev, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 3620 bytes --]

Hi Matthieu, Mat, Geliang,

While testing v7.4-rc3 with an LLM-guided test generator that we are
developing as a research prototype, we found that adding a "signal"
endpoint with a port can trigger the WARN_ON_ONCE() in
mptcp_check_listen_stop(). It happens when __inet_listen_sk() fails on
the subflow of the listener that mptcp_pm_nl_create_listen_socket()
creates, here because another socket took the port after the subflow's
bind:

  ------------[ cut here ]------------
  WARNING: net/mptcp/protocol.c:3451 at mptcp_check_listen_stop.part.0+0x15c/0x220, CPU#0: test/116
  CPU: 0 UID: 65534 PID: 116 Comm: test Not tainted 7.4.0-rc3 #1 PREEMPT(lazy)
  RIP: 0010:mptcp_check_listen_stop.part.0+0x15c/0x220
  Call Trace:
   <TASK>
   __mptcp_close+0x552/0x840
   mptcp_close+0x1e/0xc0
   inet_release+0x104/0x230
   sock_release+0x87/0x1b0
   mptcp_pm_nl_add_addr_doit+0x546/0xb00
   genl_family_rcv_msg_doit+0x1e0/0x2c0
   genl_rcv_msg+0x42d/0x6f0
   netlink_rcv_skb+0x11f/0x350
   genl_rcv+0x23/0x30
   netlink_unicast+0x518/0x870
   netlink_sendmsg+0x849/0xe20
   __sys_sendto+0x36a/0x3c0
   __x64_sys_sendto+0xdb/0x1b0
   do_syscall_64+0x116/0x630
   entry_SYSCALL_64_after_hwframe+0x77/0x7f
   </TASK>

mptcp_pm_nl_create_listen_socket() binds the subflow, sets the MPTCP
socket to TCP_LISTEN, and only then calls __inet_listen_sk() on the
subflow:

	inet_sk_state_store(newsk, TCP_LISTEN);
	sock_set_flag(newsk, SOCK_RCU_FREE);
	lock_sock(ssk);
	WRITE_ONCE(mptcp_subflow_ctx(ssk)->pm_listener, true);
	err = __inet_listen_sk(ssk, backlog);
	...
	return err;

If __inet_listen_sk() fails, inet_csk_listen_start() puts the subflow
back to TCP_CLOSE, but the MPTCP socket stays in TCP_LISTEN.
mptcp_pm_nl_add_addr_doit() then releases the listener, and
mptcp_check_listen_stop() finds an MPTCP socket in TCP_LISTEN whose
first subflow is not:

	if (WARN_ON_ONCE(!ssk || inet_sk_state_load(ssk) != TCP_LISTEN))
		return;

Matthieu's "mptcp: pm: kernel: count endpoint listeners as sockets in
use" (17/34 of the mptcp-net series posted on 2026-11-13) notes that
this socket stays in TCP_LISTEN when __inet_listen_sk() fails, and
counts it accordingly; it does not change the warning.

__inet_listen_sk() fails there when another socket binds the port
between the subflow's bind and its listen, and listen() then sees the
conflict. In the reproducer, one thread adds and flushes a signal
endpoint 127.0.0.1:10007 through the mptcp_pm genl family, and another
binds and listens on the same port with TCP_REPAIR sockets, whose
SK_FORCE_REUSE skips the conflict check at bind. About a quarter of the
3000 ADD_ADDR requests fail with EADDRINUSE; the warning comes from the
ones that fail at listen rather than at bind. It runs as an
unprivileged user (uid 65534) in its own user and network namespace.
On an x86_64 QEMU guest with 2 vCPUs and KASAN (gcc 13.3), the warning
shows up in every run (3 of 3 with the attached 168-line reproducer, 3
of 3 with our original test).

syzbot reported the same warning in 2023 through a different path, a
tcp diag request closing the listener's subflow, which 4c0288299fd0
("mptcp: prevent tcp diag from closing listener subflows") fixed. The
check and the TCP_LISTEN state of this listener both come from
57fc0f1ceaa4 ("mptcp: ensure listener is unhashed before updating the
sk status").

Checked against v7.4-rc3 (aebb72744764);
mptcp_pm_nl_create_listen_socket() and mptcp_check_listen_stop() are
the same in net (2a324a58a084). We searched lore and syzbot and found
no other report of this path.

The reproducer (repro.c) and the kernel config are attached.

Thanks,
Kyuwon Cho

[-- Attachment #2: repro.c --]
[-- Type: text/plain, Size: 5406 bytes --]

// WARNING in mptcp_check_listen_stop: mptcp_pm_nl_create_listen_socket() sets the msk to TCP_LISTEN, then
// __inet_listen_sk() on its subflow fails with EADDRINUSE because another socket took the port after the
// subflow's bind. The endpoint is not added, the listener is released with the msk in TCP_LISTEN and the
// subflow in TCP_CLOSE, and mptcp_check_listen_stop() warns.
// Thread 1 adds and flushes a "signal" endpoint 127.0.0.1:10007 through the mptcp_pm genl family.
// Thread 2 binds and listens on the same port with TCP_REPAIR sockets, which skip the bind conflict check.
// Runs as an unprivileged user in its own user and network namespace.
#define _GNU_SOURCE
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/genetlink.h>
#include <linux/if.h>
#include <linux/netlink.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <pthread.h>
#include <sched.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <unistd.h>

#define PORT 10007
#define ROUNDS 3000

static volatile int stop;
static int family;

static int put_attr(char *buf, int len, int type, const void *data, int n)
{
	struct nlattr *a = (struct nlattr *)(buf + len);

	a->nla_type = type;
	a->nla_len = NLA_HDRLEN + n;
	memcpy(buf + len + NLA_HDRLEN, data, n);
	return len + NLA_ALIGN(a->nla_len);
}

/* One genl request; returns the kernel's error code (0 on success). */
static int genl(int fd, int type, int cmd, char *buf, int len)
{
	struct nlmsghdr *nh = (struct nlmsghdr *)buf;
	struct genlmsghdr *gh = (struct genlmsghdr *)(buf + NLMSG_HDRLEN);
	char rb[4096];

	nh->nlmsg_len = len;
	nh->nlmsg_type = type;
	nh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
	gh->cmd = cmd;
	gh->version = 1;
	send(fd, buf, len, 0);
	if (recv(fd, rb, sizeof(rb), 0) < (int)NLMSG_HDRLEN)
		return -EIO;
	nh = (struct nlmsghdr *)rb;
	return nh->nlmsg_type == NLMSG_ERROR ? ((struct nlmsgerr *)NLMSG_DATA(nh))->error : 0;
}

static int resolve(int fd)
{
	char buf[256] = {0}, rb[4096];
	struct nlmsghdr *nh = (struct nlmsghdr *)rb;
	int len = put_attr(buf, NLMSG_HDRLEN + GENL_HDRLEN, CTRL_ATTR_FAMILY_NAME, "mptcp_pm", 9);

	((struct nlmsghdr *)buf)->nlmsg_len = len;
	((struct nlmsghdr *)buf)->nlmsg_type = GENL_ID_CTRL;
	((struct nlmsghdr *)buf)->nlmsg_flags = NLM_F_REQUEST;
	((struct genlmsghdr *)(buf + NLMSG_HDRLEN))->cmd = CTRL_CMD_GETFAMILY;
	send(fd, buf, len, 0);
	if (recv(fd, rb, sizeof(rb), 0) < (int)NLMSG_HDRLEN || nh->nlmsg_type == NLMSG_ERROR)
		return -1;
	for (char *p = rb + NLMSG_HDRLEN + GENL_HDRLEN; p < rb + nh->nlmsg_len;) {
		struct nlattr *a = (struct nlattr *)p;

		if (a->nla_type == CTRL_ATTR_FAMILY_ID)
			return *(uint16_t *)(p + NLA_HDRLEN);
		p += NLA_ALIGN(a->nla_len);
	}
	return -1;
}

static void *adder(void *arg)
{
	int fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC), inuse = 0;

	for (int i = 0; i < ROUNDS; i++) {
		char buf[256] = {0};
		struct nlattr *nest = (struct nlattr *)(buf + NLMSG_HDRLEN + GENL_HDRLEN);
		uint16_t af = AF_INET, port = PORT;	/* the kernel takes the port in host order */
		uint32_t flags = 1;			/* MPTCP_PM_ADDR_FLAG_SIGNAL */
		uint8_t id = 1 + i % 200;
		struct in_addr a;
		int len = NLMSG_HDRLEN + GENL_HDRLEN + NLA_HDRLEN;

		inet_pton(AF_INET, "127.0.0.1", &a);
		len = put_attr(buf, len, 1, &af, 2);		/* MPTCP_PM_ADDR_ATTR_FAMILY */
		len = put_attr(buf, len, 2, &id, 1);		/* MPTCP_PM_ADDR_ATTR_ID */
		len = put_attr(buf, len, 3, &a, 4);		/* MPTCP_PM_ADDR_ATTR_ADDR4 */
		len = put_attr(buf, len, 5, &port, 2);		/* MPTCP_PM_ADDR_ATTR_PORT */
		len = put_attr(buf, len, 6, &flags, 4);		/* MPTCP_PM_ADDR_ATTR_FLAGS */
		nest->nla_type = 1 | NLA_F_NESTED;		/* MPTCP_PM_ATTR_ADDR */
		nest->nla_len = len - (NLMSG_HDRLEN + GENL_HDRLEN);
		inuse += genl(fd, family, 1, buf, len) == -EADDRINUSE;	/* MPTCP_PM_CMD_ADD_ADDR */
		memset(buf, 0, sizeof(buf));
		genl(fd, family, 4, buf, NLMSG_HDRLEN + GENL_HDRLEN);	/* MPTCP_PM_CMD_FLUSH_ADDRS */
	}
	printf("add_addr failed with EADDRINUSE %d of %d times\n", inuse, ROUNDS);
	stop = 1;
	return NULL;
}

static void *binder(void *arg)
{
	struct sockaddr_in sa = { .sin_family = AF_INET, .sin_port = htons(PORT) };

	inet_pton(AF_INET, "127.0.0.1", &sa.sin_addr);
	while (!stop) {
		int s = socket(AF_INET, SOCK_STREAM, 0), one = 1;

		setsockopt(s, IPPROTO_TCP, TCP_REPAIR, &one, sizeof(one));
		if (!bind(s, (struct sockaddr *)&sa, sizeof(sa)))
			listen(s, 1);
		close(s);
	}
	return NULL;
}

static void write_file(const char *path, const char *s)
{
	int f = open(path, O_WRONLY);

	if (f < 0 || write(f, s, strlen(s)) < 0)
		exit(1);
	close(f);
}

int main(void)
{
	char map[32];
	struct ifreq ifr = {0};
	pthread_t a, b;
	int s, fd;

	snprintf(map, sizeof(map), "0 %d 1", getuid());
	if (unshare(CLONE_NEWUSER | CLONE_NEWNET))
		return 1;
	write_file("/proc/self/setgroups", "deny");
	write_file("/proc/self/uid_map", map);
	snprintf(map, sizeof(map), "0 %d 1", getgid());
	write_file("/proc/self/gid_map", map);

	s = socket(AF_INET, SOCK_DGRAM, 0);
	strcpy(ifr.ifr_name, "lo");
	ifr.ifr_flags = IFF_UP;
	ioctl(s, SIOCSIFFLAGS, &ifr);

	fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
	family = resolve(fd);
	printf("mptcp_pm family %d\n", family);
	pthread_create(&a, NULL, adder, NULL);
	pthread_create(&b, NULL, binder, NULL);
	pthread_join(a, NULL);
	pthread_join(b, NULL);
	return 0;
}

[-- Attachment #3: config.gz --]
[-- Type: application/gzip, Size: 38966 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-18 18:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 16:59 [BUG] mptcp: pm: WARNING in mptcp_check_listen_stop() when listen fails on a new endpoint listener Kyuwon Cho
2026-11-18 18:18 ` Matthieu Baerts
2026-11-18 18:31   ` Kyuwon Cho

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®