mptcp: pm: WARNING in mptcp_check_listen_stop() when listen fails on a new endpoint listener
Subsystems (3)
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
// 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;
}Matthieu Baerts
maintainerHi Kyuwon,
Thank you for the bug report and the reproducer.
Quoted 10 lines · Kyuwon Cho
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()inmptcp_check_listen_stop(). It happens when__inet_listen_sk()fails on the subflow of the listener thatmptcp_pm_nl_create_listen_socket()creates, here because another socket took the port after the subflow's bind:
Quoted 2 lines
------------[ cut here ]------------ WARNING: net/mptcp/protocol.c:3451 at mptcp_check_listen_stop.part.0+0x15c/0x220, CPU#0: test/116
(...)
Please always decode stacktraces with ./scripts/decode_stacktrace.sh.
Quoted 18 lines
mptcp_pm_nl_create_listen_socket()binds the subflow, sets the MPTCP socket toTCP_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 toTCP_CLOSE, but the MPTCP socket stays inTCP_LISTEN.mptcp_pm_nl_add_addr_doit()then releases the listener, andmptcp_check_listen_stop()finds an MPTCP socket inTCP_LISTENwhose first subflow is not:
Quoted 7 lines
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_LISTENwhen__inet_listen_sk()fails, and counts it accordingly; it does not change the warning.
Indeed, v1 of this patch did not fix the warning. Sashiko spotted the same issue on v1, and I already fixed this issue locally (but the series is huge now due to all the new reports from Sashiko, etc...). The v2 will be sent to the MPTCP ML soon, and I will add your Reported-by tag.
Quoted 20 lines
__inet_listen_sk()fails there when another socket binds the port between the subflow's bind and its listen, andlisten()then sees the conflict. In the reproducer, one thread adds and flushes a signal endpoint 127.0.0.1:10007 through themptcp_pmgenl family, and another binds and listens on the same port withTCP_REPAIRsockets, whoseSK_FORCE_REUSEskips the conflict check at bind. About a quarter of the 3000ADD_ADDRrequests 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 anx86_64QEMU 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 theTCP_LISTENstate of this listener both come from57fc0f1ceaa4("mptcp: ensure listener is unhashed before updating the sk status").
Quoted 6 lines
Checked against v7.4-rc3 (
aebb72744764);mptcp_pm_nl_create_listen_socket()andmptcp_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.
Out of curiosity: if your LLM has already analysed the root cause and has a reproducer, why not ask to generate a fix and send this patch instead of the bug report? There are so many patches being shared today that it is already hard to keep up. If maintainers also have to create fixes for issues report by LLMs, that might not work. Sending a patch after having passed a series of reviews by an internal Sashiko instance on your side would be more helpful.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Hi Matt,
Quoted 1 line · Matthieu Baerts
Please always decode stacktraces with
./scripts/decode_stacktrace.sh.
I'll keep that in mind and decode them in my next reports.
Quoted 3 lines
Out of curiosity: if your LLM has already analysed the root cause and has a reproducer, why not ask to generate a fix and send this patch instead of the bug report?
I'm more used to communities like LLVM, which are cautious about LLM-generated patches, and I was hesitant to send a fix for code I don't know well, made in a way I couldn't fully judge. So I only sent the root cause analysis. Thanks for explaining; I'll send a tested patch with later reports when I can.
For this one we do have a small candidate fix, tested with the
reproducer: it puts the MPTCP socket back to TCP_CLOSE when __inet_listen_sk() fails. Since you already have a fix for v2, would it still help if we posted it, or should we leave it to your series?
Thanks,
Kyuwon Cho
Matthieu Baerts
maintainerHi Kyuwon,
Quoted 11 lines · Kyuwon Cho
Hi Matt,
Quoted 1 line · Matthieu Baerts
Please always decode stacktraces with
./scripts/decode_stacktrace.sh.I'll keep that in mind and decode them in my next reports.
Quoted 3 lines
Out of curiosity: if your LLM has already analysed the root cause and has a reproducer, why not ask to generate a fix and send this patch instead of the bug report?
Quoted 5 lines
I'm more used to communities like LLVM, which are cautious about LLM-generated patches, and I was hesitant to send a fix for code I don't know well, made in a way I couldn't fully judge. So I only sent the root cause analysis. Thanks for explaining; I'll send a tested patch with later reports when I can.
Thanks!
Quoted 4 lines
For this one we do have a small candidate fix, tested with the
reproducer: it puts the MPTCP socket back toTCP_CLOSEwhen__inet_listen_sk()fails. Since you already have a fix for v2, would it still help if we posted it, or should we leave it to your series?
In the meantime, I guess you saw the patch I sent to the MPTCP ML:
https://lore.kernel.org/[email protected]
If the fix was different and your reproducer still see the WARN with the patch I sent, feel free to share yours.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.