Article View: linux.kernel.netdev
Article #26634Re: [PATCH net v3] net/rds: tcp: bound the memory held for an incoming message
From: Allison Henderson
Date: Fri, 04 Dec 2026 00:59
Date: Fri, 04 Dec 2026 00:59
180 lines
14486 bytes
14486 bytes
On Tue, 2026-12-01 at 23:23 -0600, Weidong Wang via B4 Relay wrote:
> 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>
I think this version looks good. Thanks Weidong!
Reviewed-by: Allison Henderson <achender@kernel.org>
> ---
> 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:
<5acbd3b6c34460f180cd793d0d27d64f330a55a4.camel@kernel.org>Path:
mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376940-linux-kernel-netdev=dewy.ruReferences:
<20261201-h047-send-v3-1-a70043d448b1@illinois.edu>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376940-linux-kernel-netdev=dewy.ru From: achender@kernel.org (Allison Henderson) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v3] net/rds: tcp: bound the memory held for an incoming message Date: Thu, 03 Dec 2026 17:59:31 -0700 Organization: Usenet Network Message-ID: <5acbd3b6c34460f180cd793d0d27d64f330a55a4.camel@kernel.org> References: <20261201-h047-send-v3-1-a70043d448b1@illinois.edu> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: usenet.network; logging-data="2642418"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:siZF4FoCpl0+lfd88k8PKfxrDEo= sha256:eqkgztSdKe1GmHiBCqtVBiJhKXpTPAMuEyiaIg5VGb4= sha1:1Nhh/NZopi9RQmXej2kaIfg9+Uo= sha256:NgRle6azt23ltZMT2XDVSvv/xvrGMfPGtSIlBQ+NhR4= 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 CA7D0117A8C; Fri, 4 Dec 2026 03:59:59 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.739 X-Spam-Status: No, score=-3.739 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.24, 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 c2E_t1zjMRfW; Fri, 4 Dec 2026 03:59:52 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-376940-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 10490117A7E; Fri, 4 Dec 2026 03:59:42 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 001D62450E; Fri, 4 Dec 2026 00:59:35 +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=1796345974; b=2t9kM48bmn88FnSGeOt1F9dR6Gd0WS6w44L0gy+gRU7xAmW6pPL16EJnYooPkaNRg0k+ HAvGwnDAgAchE8r1O6lJXNhAeWA/IK406GYSiupHhxRDO/KiZCacDMallO3pNg+2UsHUa U3bVrpgFYTqEVoxLoArsQPhOdd9yYdkabP3mDyW72iAwcs+ECogi+TKL3hIKL9V0erpw9 CD9p58p3FzjLaGw8WI5wXtWTcP5rbn4hOBqxMwr+i8nhFyTHW+LRbW1EP37MznWaQZJte 47qLdUrIIgYTc94Ru5vpM3AHjtAdQYEAG+EIttCx2hLpYC0jdNH2opaWtsnEmVANl/g== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796345974; h=X-Original-To:Received:Received:DKIM-Signature:Message-ID:Subject: From:To:Cc:Date:In-Reply-To:References:Content-Type: Content-Transfer-Encoding:User-Agent:X-Mailing-List:List-Id:List-Post: List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence: MIME-Version; bh=QeaULdi+XUP3AI7NzpJpd5n6FMCkNtYe8vKpsMsMhQs=; b=Wv6S9lr1r+6vHcRhAJZrXsN0iEImy6UZmF7NPdKCFlbp3rbKzKMRJynuWNknyc3W2Q3n hwe20/g77lzuclJQjeXbaMaKrTWgHmv6J2F7iNBJuHN9ryRnxJmwP9HEsUsKkSVqK8nTH b92Ek4NqSI5qjQXCGjAJDqlwbHReBvSh7uHpJ2Sp6/u67fSjFxHnpwvR8M29h0dXgWxxS 2iCOmzunVILv1JqVt+DfXaDnBLOzx3qiIKfLxosFswFK8W5WiT4FAA9WTKkByDFz9aGfd h/wpydQyVFfiqnydGdRcm2fh3fxtWzIbVmZnWhogkceRJhqN8CRP1iD2pxrakvjxi2A== 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=TBpGXQh0; 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 35A7B606A333; Fri, 4 Dec 2026 00:59:34 +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=TBpGXQh0 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=1796345973; b=f9PKKIczklw1ctd+86dAa3OEJjPEH044nh10WoQdpoZ4a49rcvi+4o8NQLUrgbRwCGtu JK7T2sYDnPPBP+VQu/uIT1iW73sQ5TKR0t2KaT0kHlOrGG73yL8FAgPEvoIjPGMYcD0BD 2o4vYjx1NxJAVvNYfIBw/mFq5+WlkHTXd+t5XfmJG09on454iVHBdiBNXo/8DXeg9CC+B i4ALQWlhjOMsO+KB1NOPTLULw/mG3Ms7OkbXUGN5ARt0YFQzG5KmUTHdS3lEYMsUbNszh gMn7nTGju/obXv5tHs4ssdT2JC/DPW7GeCA1JrFIrRLQSCl0pp+3lL91R3S5zTLaUzQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796345973; h=Received:DKIM-Signature:Message-ID:Subject:From:To:Cc:Date: In-Reply-To:References:Content-Type:Content-Transfer-Encoding: User-Agent:MIME-Version; bh=QeaULdi+XUP3AI7NzpJpd5n6FMCkNtYe8vKpsMsMhQs=; b=eKoSC0Anx+/BwZ8Yn8lajx9s56HqyrBL6GjLT0mjqx5WUABJrW1IDDolzszow/SRNUhM mHwG9G9pxgpTu8/vbnlY4IfbLKR6wM8z1Hh5PSzE9x9Gas5w+27ulPHGS7FTFxIbe95BV wPvAQMAYf5KQt5d13VT8RZriPvv+lvL2uMpmS8tSJkK114x1HQPKlSrPZiVhtsgwx8ijM RLo3uNbqEnxvL73SP3w+0AWQJMz6l/E8I1lXD1cjEZy7amcxhC2dFgrqDKjA5TpwfH26i dh1sjgXZn9c5ZCWDUL2maB/62AmvVQJ9IARsyjFIzn+IPKs3UrRJGR8SzX7fdUngM7w== 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=TBpGXQh0; 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 55521606A322; Fri, 4 Dec 2026 00:59:33 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 519DB1F000CE; Fri, 4 Dec 2026 00:59:32 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796345972; bh=QeaULdi+XUP3AI7NzpJpd5n6FMCkNtYe8vKpsMsMhQs=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=TBpGXQh0CZ+wocqPHC2qBrMZiDn5XZzws22eJZwlKf188zivOmnSI1eKzpt8P+7zc y9kaKtG3rofRGi+Z+jVTwoIQEMwiGzfU2keCqDE9kiq0hv+dPFPFfivJ3mvEKmfbBE yMwSnRCSSYf+3BDZaTCyBqSKkzFJCW79aJRJTtVZCanJyC5Wz+wuTR3NflbFq5KRIs tUJMoV4b1Pek1sq3qJhCYVi090CauR0pecnrCMXxjtroJCA77WBCzWXLCXkNnOjWaW NDTfZScEz7PDwjrmdL8x2bcom7TPwS0yMN1FBvh1i9I+M3EZKEUzyovoC5EVhlxKor 956mzt2SCAiqg== 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> X-In-Reply-To: <20261201-h047-send-v3-1-a70043d448b1@illinois.edu> X-User-Agent: Evolution 3.52.3-0ubuntu1.1 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