From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 519DB1F000CE; Fri, 4 Dec 2026 00:59:32 +0000 (UTC) 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== Message-ID: <5acbd3b6c34460f180cd793d0d27d64f330a55a4.camel@kernel.org> Subject: Re: [PATCH net v3] net/rds: tcp: bound the memory held for an incoming message From: Allison Henderson To: weidongw@illinois.edu, Andy Grover Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , 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 Date: Thu, 03 Dec 2026 17:59:31 -0700 In-Reply-To: <20261201-h047-send-v3-1-a70043d448b1@illinois.edu> References: <20261201-h047-send-v3-1-a70043d448b1@illinois.edu> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.52.3-0ubuntu1.1 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 On Tue, 2026-12-01 at 23:23 -0600, Weidong Wang via B4 Relay wrote: > From: Weidong Wang >=20 > 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. >=20 > 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. >=20 > 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. >=20 > Fixes: 70041088e3b9 ("RDS: Add TCP transport to RDS") > Cc: stable@vger.kernel.org > Cc: Zijie Zhao > Signed-off-by: Weidong Wang I think this version looks good. Thanks Weidong! Reviewed-by: Allison Henderson > --- > 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). >=20 > 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-b29031cf6b= 93@illinois.edu >=20 > 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-2727a38dbf= cd@illinois.edu > --- > net/rds/tcp.h | 1 + > net/rds/tcp_recv.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++= +----- > 2 files changed, 61 insertions(+), 6 deletions(-) >=20 > 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 */ > }; > =20 > 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); > } > =20 > +/* > + * A clone made by pskb_extract() keeps the truesize of the skb it is cu= t > + * from, however few bytes it holds, and none of it is charged to a sock= et. > + * 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 =3D false; > } > =20 > if (left && tc->t_tinc_hdr_rem) { > @@ -210,20 +220,64 @@ static int rds_tcp_data_recv(read_descriptor_t *des= c, 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] =3D > 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); > } > } > =20 > + /* > + * 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 =3D 0; > + break; > + } > + > if (left && tc->t_tinc_data_rem) { > to_copy =3D min(tc->t_tinc_data_rem, left); > =20 > - clone =3D pskb_extract(skb, offset, to_copy, arg->gfp); > - if (!clone) { > - desc->error =3D -ENOMEM; > - goto out; > + /* unreadable (devmem) frags can only be cloned */ > + clone =3D 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 =3D alloc_skb(min_t(size_t, > + tc->t_tinc_data_rem, > + SKB_MAX_ORDER(0, 0)), > + arg->gfp); > + if (!clone) { > + desc->error =3D -ENOMEM; > + goto out; > + } > + skb_queue_tail(&tinc->ti_skb_list, clone); > + tinc->ti_tail_copy =3D true; > + } > + to_copy =3D min_t(size_t, to_copy, > + skb_tailroom(clone)); > + skb_copy_bits(skb, offset, > + skb_put(clone, to_copy), to_copy); > + } else { > + clone =3D pskb_extract(skb, offset, to_copy, > + arg->gfp); > + if (!clone) { > + desc->error =3D -ENOMEM; > + goto out; > + } > + skb_queue_tail(&tinc->ti_skb_list, clone); > + tinc->ti_tail_copy =3D false; > } > =20 > - 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, >=20 > --- > base-commit: 05441d697f7f9a927264f4058cbbc6a03dfcac9d > change-id: 20261110-h047-send-52025d442823 >=20 > Best regards, > -- =20 > Weidong Wang >=20 >=20