From nobody Sun Dec 14 08:06:54 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87C481F1315 for ; Sat, 7 Jun 2025 08:55:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749286510; cv=none; b=nGr2wkPLES8DIvwgucA/GdNCHLVUBWUiw4VEptEg9zGL07H7WpmEuLUnrLQEDeOJ1jRrr2VvD/4Hnxoohh7npdrep84T8pZQ88zQXfupWWefP7+sd90M9outCIw4HGzSCwpWHkCc7yNjrJn3aj0Pc3UVxr2wAjHd3jFJO41cMHM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749286510; c=relaxed/simple; bh=iXP+eXD0Iko8Ej1JcFgDkE0uBeEgKk3crTkDqsVbG1o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZT7VM84ijtCT66QqwhaqjYFH8Mwh0UZw8vusk3v34phq+A0uj1ZIJnQS3fAe9qzj3eTwvje6AKyO9fDy5JcceB6parmEtFmrAa1zVmjIGOefwqpxBUnLz/YcPYlSzocqpFjUT5TqSETBaQtXUCnQkPxOCC6SQB8NQzk7Ui5t/3E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=d3NinwLy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="d3NinwLy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8BD8C4CEE4; Sat, 7 Jun 2025 08:55:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749286510; bh=iXP+eXD0Iko8Ej1JcFgDkE0uBeEgKk3crTkDqsVbG1o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d3NinwLyuMsj6ECbVSjs41AvBYVBYIwV0K+/rZd1wZWpv588/QicEewOqftdHV1hu NyTiegRQ+rNMUTrFXBmLjnOt/HRv95fMx65su32C4/O1/V8ROuND/9nS7Q27GEg/3V goxtNxDgrAnTw3iGjbaCnT8zIeGeBBE8NUReNNiDk44Cw+Y/+eJSdjT3dDr1lCBi8e a65qqNQuOUFMqfGwpmrNLOw6T6ub9BB4wZ7a3QDb35xWBX+VxVFrqj0nin9auaWGb1 9iFMwSNR+y9h09qPtAk6vXfOC8nUmxlwo9kz6Dbc/t+Ww5fBQH8u3UyHd9Do3lnzPs UodoEFjN4V0wg== From: Geliang Tang To: mptcp@lists.linux.dev, hare@kernel.org Cc: Geliang Tang Subject: [PATCH mptcp-next v2 2/4] mptcp: implement .read_sock Date: Sat, 7 Jun 2025 08:54:17 +0000 Message-ID: <32cc946892d634a14cdf4373c1b9d47126162e5a.1749286212.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang nvme_tcp_try_recv() needs to call .read_sock interface of struct proto_ops, but it is not implemented in MPTCP. This patch implements it with reference to __mptcp_recvmsg_mskq(). v2: - first check the sk_state (Matt), but not look for the end of the end of a connection like TCP in __tcp_read_sock(): if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) break; This will cause a use-after-free error: BUG: KASAN: slab-use-after-free in mptcp_read_sock. Reviewed-by: Hannes Reinecke Signed-off-by: Geliang Tang --- net/mptcp/protocol.c | 61 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 7fc940a60b3d..da4242e48246 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3956,6 +3956,65 @@ static __poll_t mptcp_poll(struct file *file, struct= socket *sock, return mask; } =20 +/* + * Note: + * - It is assumed that the socket was locked by the caller. + */ +static int mptcp_read_sock(struct sock *sk, read_descriptor_t *desc, + sk_read_actor_t recv_actor) +{ + struct mptcp_sock *msk =3D mptcp_sk(sk); + struct scm_timestamping_internal tss; + struct sk_buff *skb, *tmp; + size_t len =3D INT_MAX; + int copied =3D 0; + + if (sk->sk_state =3D=3D TCP_LISTEN) + return -ENOTCONN; + skb_queue_walk_safe(&sk->sk_receive_queue, skb, tmp) { + u32 offset =3D MPTCP_SKB_CB(skb)->offset; + u32 data_len =3D skb->len - offset; + u32 size =3D min_t(size_t, len - copied, data_len); + int count; + + count =3D recv_actor(desc, skb, offset, size); + if (count <=3D 0) { + if (!copied) + copied =3D count; + break; + } + + if (MPTCP_SKB_CB(skb)->has_rxtstamp) + tcp_update_recv_tstamps(skb, &tss); + + copied +=3D count; + + if (count < data_len) { + MPTCP_SKB_CB(skb)->offset +=3D count; + MPTCP_SKB_CB(skb)->map_seq +=3D count; + msk->bytes_consumed +=3D count; + break; + } + + /* avoid the indirect call, we know the destructor is sock_wfree */ + skb->destructor =3D NULL; + atomic_sub(skb->truesize, &sk->sk_rmem_alloc); + sk_mem_uncharge(sk, skb->truesize); + sk_eat_skb(sk, skb); + msk->bytes_consumed +=3D count; + + if (copied >=3D len) + break; + } + + mptcp_rcv_space_adjust(msk, copied); + + if (copied > 0) + mptcp_cleanup_rbuf(msk, copied); + + return copied; +} + static const struct proto_ops mptcp_stream_ops =3D { .family =3D PF_INET, .owner =3D THIS_MODULE, @@ -3976,6 +4035,7 @@ static const struct proto_ops mptcp_stream_ops =3D { .recvmsg =3D inet_recvmsg, .mmap =3D sock_no_mmap, .set_rcvlowat =3D mptcp_set_rcvlowat, + .read_sock =3D mptcp_read_sock, }; =20 static struct inet_protosw mptcp_protosw =3D { @@ -4080,6 +4140,7 @@ static const struct proto_ops mptcp_v6_stream_ops =3D= { .compat_ioctl =3D inet6_compat_ioctl, #endif .set_rcvlowat =3D mptcp_set_rcvlowat, + .read_sock =3D mptcp_read_sock, }; =20 static struct proto mptcp_v6_prot; --=20 2.43.0