Article View: linux.kernel.netdev
Article #25978[PATCH net 9/9] mptcp: don't charge the backlog twice at accept()
From: "Matthieu Baerts (NGI0)"
Date: Wed, 02 Dec 2026 21:29
Date: Wed, 02 Dec 2026 21:29
137 lines
13694 bytes
13694 bytes
From: Chris Mason <mason@kernel.org>
accept() can permanently overcharge the memory cgroup of an MPTCP
server, so the server can be OOM killed, if the new connection received
data while its MPTCP socket was locked.
The sockets of an MPTCP connection have no memory cgroup before
accept(), which then charges the sk_forward_alloc and the sk_rmem_alloc
of the MPTCP socket (msk) and of each subflow. mptcp_graft_subflows()
also charges msk->backlog_unaccounted: the truesize of the skbs that
__mptcp_add_backlog() queued while the socket lock of the msk was held
and their subflow had no memory cgroup. But the first charge already
covers each of these skbs that has not been freed, in the sk_rmem_alloc
of its subflow or of the msk, so no later uncharge matches the extra
charge.
The fix used here is to remove msk->backlog_unaccounted, its charge in
mptcp_graft_subflows() and the warning that tests it in
mptcp_can_spool_backlog(). An RFC patch [1] removes the same lines, as
part of another approach.
This issue has been found with the help of an LLM, and reproduced in a
VM, with the reproducer shared with the original version of this patch,
on a kernel with the previous patch: 100,000 connections to an MPTCP
server in a memory cgroup. Without this patch, about 63 MB stayed
charged to this memory cgroup once all the connections were closed, and
to its parent after its removal:
SNAP label=after-100000 rounds=100000 sockets_left_in_srv=0 tcp_mem_pages=0 [...] c_sock=63295488 [...]
[...]
SNAP label=c-removed rounds=100000 sockets_left_in_srv=0 tcp_mem_pages=0 c=removed [...] p_sock=63295488 [...]
And about 12 MB with only 50 connections, each getting 20,000 one-byte
segments before accept(), new for TCP but with the same data sequence
number, so the msk drops them as duplicates. Bare ACKs with RM_ADDR,
sent at the same time, make the MPTCP worker take the socket lock, so
that some of these segments go through the backlog:
SNAP label=after-50 rounds=50 sockets_left_in_srv=0 tcp_mem_pages=256 [...] c_sock=12881920 [...]
Fixes: 6228efe0cc01 ("mptcp: leverage the backlog for RX packet processing")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/all/20260924080219.1036588-4-caixinchen1@huawei.com/ [1]
Signed-off-by: Chris Mason <mason@kernel.org>
[ No comment change: the commit message explains why the backlog is
covered. Commit message: refer to the RFC [1] removing the same lines
+ how the issue was found, and its symptoms. ]
Reviewed-by: Mat Martineau <martineau@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
net/mptcp/protocol.c | 35 +----------------------------------
net/mptcp/protocol.h | 1 -
2 files changed, 1 insertion(+), 35 deletions(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index ed8606fb1a90..cef861ea026e 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -795,12 +795,6 @@ static void __mptcp_add_backlog(struct sock *sk,
account:
WRITE_ONCE(msk->backlog_len, msk->backlog_len + delta);
-
- /* Possibly not accept()ed yet, keep track of memory not CG
- * accounted, mptcp_graft_subflows() will handle it.
- */
- if (!mem_cgroup_from_sk(ssk))
- msk->backlog_unaccounted += delta;
}
static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk,
@@ -2334,12 +2328,6 @@ static bool mptcp_can_spool_backlog(struct sock *sk, struct list_head *skbs)
{
struct mptcp_sock *msk = mptcp_sk(sk);
- /* After CG initialization, subflows should never add skb before
- * gaining the CG themself.
- */
- DEBUG_NET_WARN_ON_ONCE(msk->backlog_unaccounted && sk->sk_socket &&
- mem_cgroup_from_sk(sk));
-
if (list_empty(&msk->backlog_list))
return false;
@@ -4508,8 +4496,7 @@ static void mptcp_graft_subflows(struct sock *sk)
/* Subflows joining after __inet_accept() will get the
* mem CG properly initialized at mptcp_finish_join() time,
* but subflows pending in join_list need explicit
- * initialization before flushing `backlog_unaccounted`
- * or MPTCP can later unexpectedly observe unaccounted memory.
+ * initialization by the loop below.
*/
mptcp_data_lock(sk);
list_splice_init(&msk->join_list, &join_list);
@@ -4541,26 +4528,6 @@ static void mptcp_graft_subflows(struct sock *sk)
unlock:
release_sock(ssk);
}
-
- if (mem_cgroup_sk_enabled(sk)) {
- gfp_t gfp = GFP_KERNEL | __GFP_NOFAIL;
- int amt;
-
- /* Account the backlog memory; prior accept() is aware of
- * fwd and rmem only.
- */
- mptcp_data_lock(sk);
- amt = sk_mem_pages(sk->sk_forward_alloc +
- msk->backlog_unaccounted +
- atomic_read(&sk->sk_rmem_alloc)) -
- sk_mem_pages(sk->sk_forward_alloc +
- atomic_read(&sk->sk_rmem_alloc));
- msk->backlog_unaccounted = 0;
- mptcp_data_unlock(sk);
-
- if (amt)
- mem_cgroup_sk_charge(sk, amt, gfp);
- }
}
static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 05bf9c3f11b4..73bd9a3008f6 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -392,7 +392,6 @@ struct mptcp_sock {
struct list_head backlog_list; /* protected by the data lock */
u32 backlog_len;
- u32 backlog_unaccounted;
};
#define mptcp_data_lock(sk) spin_lock_bh(&(sk)->sk_lock.slock)
--
2.55.0
Technical Details
Message-ID:
<20261202-net-mptcp-misc-fixes-7-4-rc7-v1-9-9f03efcb1a17@kernel.org>Path:
mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376069-linux-kernel-netdev=dewy.ruReferences:
<20261202-net-mptcp-misc-fixes-7-4-rc7-v1-0-9f03efcb1a17@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376069-linux-kernel-netdev=dewy.ru
From: matttbe@kernel.org ("Matthieu Baerts (NGI0)")
Newsgroups: linux.kernel.netdev
Subject: [PATCH net 9/9] mptcp: don't charge the backlog twice at accept()
Date: Wed, 02 Dec 2026 22:29:39 +0100
Organization: Usenet Network
Message-ID: <20261202-net-mptcp-misc-fixes-7-4-rc7-v1-9-9f03efcb1a17@kernel.org>
References: <20261202-net-mptcp-misc-fixes-7-4-rc7-v1-0-9f03efcb1a17@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
logging-data="2066157"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:SxhcdGMwLnwvN30A5RN067CX0oA= sha256:iuq9Z3mlLSTXu4YmVAqC7g23AGoAyTLpNhBVeFQ/1eY=
sha1:cF9WsVr/udG4X/vSSVvxzXffbIc= sha256:przVmlOo/H/Rwii2Y0PmWnZlMuNtxG4cxZMYdukc3Rc=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 93BB611773D; Thu, 3 Dec 2026 00:32:46 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id BujPuJCCgkP4;
Thu, 3 Dec 2026 00:32:43 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-376069-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
by mail.dewy.ru (Postfix) with ESMTPS id EB03E117723; Thu, 3 Dec 2026 00:32:34 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sin.lore.kernel.org (Postfix) with ESMTP id A8F8E2508A; Wed, 2 Dec 2026 21:32:28 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1796247138;
b=UUo9+diQvR+ZaPatA9jsSQYguvGoxiS/kEWNCfemkybqKhF55nydM92n2ZqGa2x4NST2
Na26fuBu/NUR0WS7CeyXqCo4VaEmvsLPIy6Cns3cluNfr8XB7XEmv5+R2Mz2VSRqtDuXe
dFDD85F3KafduPnigQWilT2Nih24mOPepNoK+mpbfgbyBIcPV/UrHeF2iSNw+JMMjVcfW
smeRdkpXgSYqrWzIq1+pjGFfa7z4X00d9JTVJgn71RyntlB3lQbV3qd42+gBc1YsqiKm1
MjIG8AXtkvJdgl94tr/MPjOZ+JXIg38eQ9hKJGE6J6a4blJQk61+1VS5ZzVktj4+3TA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796247138;
h=X-Original-To:Received:Received:DKIM-Signature:From:Date:Subject:
X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc:
X-Mailer:X-Developer-Signature:X-Developer-Key;
bh=0ANvI99rKQcf0LNeRNLGISp+njNcPfTEXiZ7cLLvQxA=;
b=fNUUWLok2Bug05LYetxloyU98/dDgeLYYfRcwCh2WN4lcrsn7dmKRelsy1hbIzMKTF1q
OYuK4AamX4cH30le0O8Ddt3hcyNFClaIaHLsYtCB3d3utZXXS+99WktDJMajPuwuvsoFB
zPIE1XOCjNCGSzGcNDAZoqt3hsq7Tt+L+NIym8G7CkSYQhzUEM9xGhGeKohHMfbRPBbO9
Ks013LSUdyydGS9L+ZALU8poN1qf7zBmiGMEAMAJ6rjFQwlmxtjEoQEh8SbG2G6k3sN3K
6QFhr2sqhh3pt9kslawnROBlWNfHARzAMx5i1gEJtSqYXkz3UqTkOAJWoB/MCIfjnMg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="STp/ws6e";
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 4354F606A695;
Wed, 2 Dec 2026 21:32:18 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=STp/ws6e
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1796247137;
b=taNc2RqN2/b3CnoqebTFnaYONZE+ZIdv8k+KN14PD2KlGTgmjlrk0zocRGf5aKNNWqVO
sfai5kd6vQz4anA6Eqe27GFV5pvFjMf5FlvqkWoBug9w2aoWrgmIJPI9JGCmFrxzYgqe3
hAbMwNyE+H+/DXIMnLunkKd2YO8a3T3v5Fq0FNG8IDdTzpNs+H3pbltNIh7qja3l1ZAJA
HErxq3HQ8Eq/HzgpPMiqGKErKNNG+KT8zNPospubylmX/tQ5ygLovGrAzmz9AKbSY5PDb
wyqIeTQNjGFRpnfjVBicWtaNphgZxwfUuJ6bl4/p0RCYwow0gkovtgOrBHko5goR1zw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796247137;
h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type:
Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc:
X-Mailer:X-Developer-Signature:X-Developer-Key;
bh=0ANvI99rKQcf0LNeRNLGISp+njNcPfTEXiZ7cLLvQxA=;
b=juSCygD7Z7X2E0ZtK1KH2cSBGoB3zopCQ2sdlpKZFSYK0pOBLYY8bY6OgXKyaUWj5iHJ
nJwmE2SWwwXvfa1Q1W9vFhAkuMNr5Fbyqyh5dofnQ+aq6lm4Q4N8ZqSo3vx2UBKIgEO65
dr9DJbDC2kZOKh/oZ2RQN0Y7OFuWHFA23YjOGUQUqrrn5bvUhlPqCbyHDperNaFtDnPXv
2sLj/LUPA2ZzNG3mjryx4Fr7LNJiSrXg5ZnHLYmQN4Us3gPL9niYXxhwUELcNPNn+mma1
si93ZvguyIA+lX6Wj9Nkx8dY/Rh2aZ6KabCP1vnZGexUkxaul539/Uo/nMdh4vHIqbg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="STp/ws6e";
arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature ECDSA (prime256v1))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64CC7606A33E;
Wed, 2 Dec 2026 21:32:17 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF0B31F0092A;
Wed, 2 Dec 2026 21:32:14 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
s=k20260515; t=1796247137;
bh=0ANvI99rKQcf0LNeRNLGISp+njNcPfTEXiZ7cLLvQxA=;
h=From:Date:Subject:References:In-Reply-To:To:Cc;
b=STp/ws6eWcoz3/lucWWV6USmB7JPTNTiTOL2lEmtcagZMK11drvbbCkcYC2GNojiL
YOhvsDYelyQGweeshrgHte/cKMJa0+PQoJx3r0TP6pYxkyHK5luJkoe8OjRwg2wSd0
M2n99d4x80ye39EMexEsx+vyJp4byQiwLtti8/C45AzF8yP0F0r/N0UDj6iemE1pGa
3mKXrGxNKNpM9t/yKV6Uacc9Lubfo6SMrtMsyXv8FNLFfGTy3ehfLE10qz46BpvAHL
AVq+wOCyr7/92j2Juf0MoBybf6KUeOw7KTAeodac61tzIU+3MdiyXlEGrOHaHIBM8F
TH0TLxoHrD79A==
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <20261202-net-mptcp-misc-fixes-7-4-rc7-v1-0-9f03efcb1a17@kernel.org>
X-Cc: netdev@vger.kernel.org, mptcp@lists.linux.dev,
"Matthieu Baerts (NGI0)" <matttbe@kernel.org>,
Chris Mason <mason@kernel.org>, stable@vger.kernel.org
X-Mailer: b4 0.16.0
X-Developer-Signature: v=1; a=openpgp-sha256; l=5413; i=matttbe@kernel.org;
h=from:subject:message-id; bh=JTTVu33PCaZdem1obu6qfXZ8r6czdoRo939zl9L5oeA=;
b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLIF+pzjpeYcdlq7yHTBnAxvOw2JxAqd5VUbRNy2mAuJ+
Fq5P5bpKGVhEONikBVTZJFui8yf+byKt8TLzwJmDisTyBAGLk4BmMj7HEaGpjd/3T87qZk839SR
8U5z77SjdqyF8ZbyOwuuT5h6Orcxl+F/7XvWGK3d79l3Fyw2eSB/+N7XWXGBXtcF98h1Hcsoy77
PDQA=
X-Developer-Key: i=matttbe@kernel.org; a=openpgp;
fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073