Article View: linux.kernel.netdev
Article #25620[PATCH net v3] net/rds: tcp: bound the memory held for an incoming message
From: Weidong Wang via B4 Relay
Date: Wed, 02 Dec 2026 05:23
Date: Wed, 02 Dec 2026 05:23
165 lines
16727 bytes
16727 bytes
From: Weidong Wang <weidongw@illinois.edu>
rds_tcp_data_recv() queues pskb_extract() clones on the incoming
message until h_len bytes, taken from the peer's header, have arrived.
The clones are not charged to the socket, so a peer can make the
receiver hold up to 4 GiB by announcing a large h_len, or over 1 GiB
for a 1 MiB message sent one byte per segment, as each clone keeps the
truesize of the skb it was cut from.
Drop the connection when h_len exceeds RDS_MAX_MSG_SIZE, the limit
rds_sendmsg() enforces since v4.11, and discard the rest of the stream
until shutdown. Copy, rather than clone, pieces smaller than a quarter
of their skb's truesize, appending to a linear skb until it is full, so
that a message holds at most about four times its size.
Found by an AI code review agent and reproduced under QEMU. The fix and
changelog were drafted with AI assistance (Claude), then reviewed and
tested by the submitter.
Fixes: 70041088e3b9 ("RDS: Add TCP transport to RDS")
Cc: stable@vger.kernel.org
Cc: Zijie Zhao <zijie4@illinois.edu>
Signed-off-by: Weidong Wang <weidongw@illinois.edu>
---
Tested under QEMU with KASAN: a 1 MiB message sent one byte per segment
held 1239 MiB with v2; with v3 it is delivered intact at normal memory
use. The RDS selftests (-T tcp) pass. The reproducer can be shared on
request (AI-found issue).
Changes in v3:
- Also copy small pieces instead of cloning them (reported by Sashiko).
A truesize limit that drops the connection would also drop valid
messages, e.g. with a small MSS or 64 KiB pages. New subject.
- Link to v2: https://patch.msgid.link/20261125-h047-send-v2-1-b29031cf6b93@illinois.edu
Changes in v2:
- Drop the connection once, then discard the rest of the stream, so
that the shutdown is not held up (reported by Sashiko). Allison's
Reviewed-by is not carried over.
- Link to v1: https://patch.msgid.link/20261111-h047-send-v1-1-2727a38dbfcd@illinois.edu
---
net/rds/tcp.h | 1 +
net/rds/tcp_recv.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 61 insertions(+), 6 deletions(-)
diff --git a/net/rds/tcp.h b/net/rds/tcp.h
index 39c86347188c..2bdff97c815b 100644
--- a/net/rds/tcp.h
+++ b/net/rds/tcp.h
@@ -22,6 +22,7 @@ struct rds_tcp_net {
struct rds_tcp_incoming {
struct rds_incoming ti_inc;
struct sk_buff_head ti_skb_list;
+ bool ti_tail_copy; /* last skb is a copy, can be appended to */
};
struct rds_tcp_connection {
diff --git a/net/rds/tcp_recv.c b/net/rds/tcp_recv.c
index ffe843ca219c..372218e5ab76 100644
--- a/net/rds/tcp_recv.c
+++ b/net/rds/tcp_recv.c
@@ -147,6 +147,15 @@ static void rds_tcp_cong_recv(struct rds_connection *conn,
rds_cong_map_updated(map, ~(u64) 0);
}
+/*
+ * A clone made by pskb_extract() keeps the truesize of the skb it is cut
+ * from, however few bytes it holds, and none of it is charged to a socket.
+ * Pieces smaller than a quarter of that are copied instead, and once a
+ * copy has started, data is appended to it until it is full. A message
+ * then holds at most about four times its size.
+ */
+#define RDS_TCP_MAX_CLONE_RATIO 4
+
struct rds_tcp_desc_arg {
struct rds_conn_path *conn_path;
gfp_t gfp;
@@ -189,6 +198,7 @@ static int rds_tcp_data_recv(read_descriptor_t *desc, struct sk_buff *skb,
* we've already serialized at a higher level.
*/
skb_queue_head_init(&tinc->ti_skb_list);
+ tinc->ti_tail_copy = false;
}
if (left && tc->t_tinc_hdr_rem) {
@@ -210,20 +220,64 @@ static int rds_tcp_data_recv(read_descriptor_t *desc, struct sk_buff *skb,
be32_to_cpu(tinc->ti_inc.i_hdr.h_len);
tinc->ti_inc.i_rx_lat_trace[RDS_MSG_RX_START] =
local_clock();
+ /*
+ * The payload is queued on tinc until the
+ * whole message has arrived, so a peer must
+ * not announce more than a sender is allowed
+ * to send.
+ */
+ if (tc->t_tinc_data_rem > RDS_MAX_MSG_SIZE)
+ rds_conn_path_drop(cp, false);
}
}
+ /*
+ * After an oversized header the connection is being dropped:
+ * consume and discard the rest of the stream until it is shut
+ * down, so that the receive queue drains and the shutdown is
+ * not held up.
+ */
+ if (!tc->t_tinc_hdr_rem &&
+ tc->t_tinc_data_rem > RDS_MAX_MSG_SIZE) {
+ left = 0;
+ break;
+ }
+
if (left && tc->t_tinc_data_rem) {
to_copy = min(tc->t_tinc_data_rem, left);
- clone = pskb_extract(skb, offset, to_copy, arg->gfp);
- if (!clone) {
- desc->error = -ENOMEM;
- goto out;
+ /* unreadable (devmem) frags can only be cloned */
+ clone = skb_peek_tail(&tinc->ti_skb_list);
+ if (skb_frags_readable(skb) &&
+ ((tinc->ti_tail_copy && skb_tailroom(clone)) ||
+ skb->truesize > RDS_TCP_MAX_CLONE_RATIO * to_copy)) {
+ if (!tinc->ti_tail_copy || !skb_tailroom(clone)) {
+ clone = alloc_skb(min_t(size_t,
+ tc->t_tinc_data_rem,
+ SKB_MAX_ORDER(0, 0)),
+ arg->gfp);
+ if (!clone) {
+ desc->error = -ENOMEM;
+ goto out;
+ }
+ skb_queue_tail(&tinc->ti_skb_list, clone);
+ tinc->ti_tail_copy = true;
+ }
+ to_copy = min_t(size_t, to_copy,
+ skb_tailroom(clone));
+ skb_copy_bits(skb, offset,
+ skb_put(clone, to_copy), to_copy);
+ } else {
+ clone = pskb_extract(skb, offset, to_copy,
+ arg->gfp);
+ if (!clone) {
+ desc->error = -ENOMEM;
+ goto out;
+ }
+ skb_queue_tail(&tinc->ti_skb_list, clone);
+ tinc->ti_tail_copy = false;
}
- skb_queue_tail(&tinc->ti_skb_list, clone);
-
rdsdebug("skb %p data %p len %d off %u to_copy %zu -> "
"clone %p data %p len %d\n",
skb, skb->data, skb->len, offset, to_copy,
---
base-commit: 05441d697f7f9a927264f4058cbbc6a03dfcac9d
change-id: 20261110-h047-send-52025d442823
Best regards,
--
Weidong Wang <weidongw@illinois.edu>
Technical Details
Message-ID:
<20261201-h047-send-v3-1-a70043d448b1@illinois.edu>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!feed-us-ny.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375572-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!feed-us-ny.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375572-linux-kernel-netdev=dewy.ru From: devnull+weidongw.illinois.edu@kernel.org (Weidong Wang via B4 Relay) Newsgroups: linux.kernel.netdev Subject: [PATCH net v3] net/rds: tcp: bound the memory held for an incoming message Date: Tue, 01 Dec 2026 23:23:35 -0600 Organization: Usenet Network Message-ID: <20261201-h047-send-v3-1-a70043d448b1@illinois.edu> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="1895813"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:sByz7GRu/6Qy0FM5RWepV+6c4pA= sha256:vuRQRuPsTMEojgvPBpg8pUVWt0eOh1OYr4zDpOHHzQE= sha1:A2LrVO9dZWKVOjDntYXzSEhljKs= sha256:vU9oCqGA0q9zhZs68sgKXK55IG5J8tBgrEDsFny01m8= 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 3233D1174E7; Wed, 2 Dec 2026 08:24:03 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.4 X-Spam-Status: No, score=-3.4 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, URIBL_BLOCKED=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 vX_pYsPeNTAb; Wed, 2 Dec 2026 08:23:59 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-375572-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 06EA1117543; Wed, 2 Dec 2026 08:23:49 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id C34F42A663; Wed, 2 Dec 2026 05:23:47 +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=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796189027; b=YELpntGhhniVKknuJ4sSS31IdxJ9rXfWc6zLfzDJA5YhbHoxYW3o4NJgq2qtn4qkKnau 1X9HHS/JsgqHGxtXPlTe2ByNq/rWZ+/tS9ZZcNoGLR+b1I5gZ3/Zgc02WVm7ukjXtupzO Ug40PsEqhg7u68fhzW/tSQMtFQPaJLGIBqs91Q9pgOGYw/qkWFNpaRJ6olDPYZGi2njMu V45J0axBvNxWO2wF8z1iawr++ORZACgNccUEwwrin3+ekMCyO9eWXxCSxhVIX3/F4eDON aaOxBVk8huh0plsoCwnyigNX2ygLXbWuYYjZgFKZ/8qtHnLv7z4jmHJANnsb2WK0v3g== X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796189027; h=X-Original-To:Received:Received:DKIM-Signature:Received:From:Date: Subject:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type: Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=XrqZ1Wu7syjQxxZ8cxOeOmCf9FR0HP0hJhVUYkY+Ank=; b=bVvMj1DaROQixf+MIhDoLVJhzued8XcoyIc4zihAwDaNEHM6rIkCp1h0H6OjzwjOr7o+ pAE5h/zFOfZjaRWLzdHhu1sVZJD/ugyPLsvDFzW9pVqeO7YUG3VymQiO4oXu1PItlMmSm 0YqLlG6vdMTBZHfTNsOp6BeyjdaKfMqDGgAPk1U1dGjzyFGg3j3bESva+bDTUUNb0IW3F W/FiJtgkYVpHCysweUedLm12PCBhJiNbOqurSS3TTQzfjjvZhmkNWnkpQObOuXEIY62jl Vc3YXdeagtAfSVTcNtpxRC8V/KMIiNqmrdmzm5uhmRV1mAv+kvJkQg7gux68U3Gq+vA== X-ARC-Authentication-Results: i=3; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SHKbzCqI; 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 995F7606A32E; Wed, 2 Dec 2026 05:23:47 +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=SHKbzCqI X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796189016; b=ffDqRggI6Y7ZcF0gGdxKQp481wFKBaLCerKQozv5hNe2ErOf2zds+6vkXFDyLhTfeFUj 2trCZ/P+gjHYuuB2IHe3qCq3AYAv+D2jFmuMMGfEAAZ9YeHZjVoIk354SpiI+e5SdVUAs C8KMWvabZPz4UJNLEii7TKbiZIM7Cr+k05ZodVj0juxLAUDS6tWwWsxm4O4MV8Lg7EcBA D5NqnwraGBk/5oqYtpuGlDkBMLV+xz81m60Td29I2OEmP6CjX5owGINsUVloLrMYQ3wQP uyKXvzDBiXI6Gz9E0pAQGpJDxxvfiYhooYhCrG+IKQL1FVxQTswC38L17pAK2qrbjpA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796189016; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=XrqZ1Wu7syjQxxZ8cxOeOmCf9FR0HP0hJhVUYkY+Ank=; b=dVYSzlijCrsqGn8N1J5+dgS0t1/NlfiiUT6LEqDiXkBuz3qChqi7xDauPI1inE1Ehp/9 XO9OtxMCCP3EPbyVXFlXd/dRuF9meUE+wE48iienXNRtmXnO80TTrkIbvPH0Kk5hjdk95 9+JXbdflR2H26bos/MQiNqkEZMrEC95PlIulne4FWBmCfV45XDM3p/rUpxZhOSTuJWqDd JO7fE5x4gxSm1W6WDDmwnx5EjQgarKipjCJIkj1kLFj8l4ZYqMEpJcIEFN0ICbhj7GFvD W3iLFYC5fyY8ECNMNtYTcK4CeqvbYipX9utXpTZGiXnJtvbmeR9WswkpC2bU6YYDu4w== 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=SHKbzCqI; arc=pass header.oldest-pass=0 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 B07C6606A31A; Wed, 2 Dec 2026 05:23:36 +0000 (UTC) X-Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 X-ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796189016; b=bu9twSuwBTcXvpOfU75lD4e0hkOdWR3TJb+dHHGscQvGL7us5fA3SQAZj7G9Ai71Cmzj 7Vx8LL7qR81nH3mbw3UkihSInwPlK5Y8MYpvjA4kQ/a9BLExZ9h+Erqfimj1PXPmoIA/z y4Nv3O9DAPuoItBoscd7vy+JbfUSPrcfazJreFOb+hUmjeD/5CYzvyKgLeZ9wfaOKu7l3 XCEY16ckKiRJaWiR9HL/44t3C5gzb4V5lFbZjjx76Q6v7oKqMlQPOTpoPKyyj7YFYAVxi R6QgRRLLW566f2HPsyh1GPzGLp/PrBcs4sX5R4ZN0QZ7F8xy6wUNHeB1Z/X7XO/pJVw== X-ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796189016; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=XrqZ1Wu7syjQxxZ8cxOeOmCf9FR0HP0hJhVUYkY+Ank=; b=xjh0hkeUXuIZNs018ybxRr/7mP83pR/NlAxH9jtJZlTUhe15Rlz5kc72W+VHRV8L1I7f LHsK+fn/n5UC1eDYq9oFvhV+b3v2v++gDGiBLPScyDLHl3vx3D7LgqJ5atpvGn2BXJk7G +YEfbDo7eud0SR2gQk2fm/oqzBRFKLwjZqiU7UT4wZY9CE0pZPJ/XEkyxUYizom+Bg7uu Ju7vO6EfQe+lbmPNZ4uK8h3Tjq3q/qIgAbVlRTTudW3Jr6dnxyZdyi9D44W3Nji+ssDNM PRN+ivRzfL/PCvv4kWz/WGL5vWAQCvvvZ/qfjlH4z71v8IDFKxdNHBA5RONjPeZlBOw== X-ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 X-Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id ADBDD1F00893; Wed, 2 Dec 2026 05:23:35 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796189016; bh=XrqZ1Wu7syjQxxZ8cxOeOmCf9FR0HP0hJhVUYkY+Ank=; h=From:Date:Subject:To:Cc:Reply-To; b=SHKbzCqIGpeaYHdcd6fp6acpCTOgk/uyzE1UEH9o3nXjs2HkgVokQttyHrGzQuN1q Bu09Z9mPOoMB9+B/UVYL5gB4juJgMtMCcNLyNBLvgXX5JlPi4YlyVH4ShDR6PDwEYB aUSCDycq89AttNiCkTEY7+6Bpt/A+sqozC9uJy6MVl+c3hgcleCaL6oUWcYtul0V2y qVMIC9ClNgFE673nnz3HCKyt4N6N1nVLj/GArIWLdDap1ZVm3Y1GnYM0pb7S3tz5Lh bsqzwH6b07j7oTUizCmNSgiRqGCf1PPeecbGuCaj6xsQvt60OS5mX145pLFusJdrMZ i4TkfSxm5HbQA== X-Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 120F94F270; Wed, 2 Dec 2026 05:23:35 +0000 (UTC) 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-B4-Tracking: v=1; b=H4sIAFarD2sC/12Nyw7CIBREf8WwFgOXPl35H8ZFC7f2moYaaImm6 b9L0UXjciZzzizMoyP07HxYmMNAnkYbgzoemO4be0dOJmYGAgoppeC9yEru0Rqexy43WQYVKBb 3T4cdvZLryixO7PYt/dw+UE+bZZv15KfRvdNjkGn8k8udPEguOZRQNqoybafNhYaB7Ej+hGZO6 gA7GPI9DBFuoRZK6q5oa/UHr+v6AfkGj7X5AAAA X-Change-ID: 20261110-h047-send-52025d442823 X-Cc: "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@kernel.org>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>, netdev@vger.kernel.org, linux-rdma@vger.kernel.org, rds-devel@oss.oracle.com, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Zijie Zhao <zijie4@illinois.edu>, Weidong Wang <weidongw@illinois.edu> X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796189014; l=5955; i=weidongw@illinois.edu; s=20261108; h=from:subject:message-id; bh=XZBdG4L7hFmyV/S6aOx1ggeNXijrQT3nGyOXh+G92Rs=; b=jpSiLAPsDiRX+JFSf2yexRAeCr5u0lpLXBu0ZPh4lf9wGje3z+toLcRoTSlMXL+gTmxWBI3yr xigaRTX4bDsCYe1gUyXwzuF+521aMbZNJ2899e/hrm4ohMDBcezhEFT X-Developer-Key: i=weidongw@illinois.edu; a=ed25519; pk=DR2S1xPEa5sELrWPfOpvUphJQ2VHC+MDc/wJavE/ifg= X-Endpoint-Received: by B4 Relay for weidongw@illinois.edu/20261108 with auth_id=1449 X-Original-From: Weidong Wang <weidongw@illinois.edu> X-Reply-To: weidongw@illinois.edu