From: Allison Henderson <achender@kernel.org>
To: weidongw@illinois.edu, Andy Grover <andy.grover@oracle.com>
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>
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 [thread overview]
Message-ID: <5acbd3b6c34460f180cd793d0d27d64f330a55a4.camel@kernel.org> (raw)
In-Reply-To: <20261201-h047-send-v3-1-a70043d448b1@illinois.edu>
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>
>
>
prev parent reply other threads:[~2026-12-04 0:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 5:23 Weidong Wang via B4 Relay
2026-12-04 0:59 ` Allison Henderson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5acbd3b6c34460f180cd793d0d27d64f330a55a4.camel@kernel.org \
--to=achender@kernel.org \
--cc=andy.grover@oracle.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rds-devel@oss.oracle.com \
--cc=stable@vger.kernel.org \
--cc=weidongw@illinois.edu \
--cc=zijie4@illinois.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®