Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2568063lkm; Mon, 20 Sep 2021 18:56:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzg0+ben+RSSe2kv996BXMNfVr7Jhdy+dfRoIAnEwtimoveSDTxGR82jwwqL6mEFPJ3Xac1 X-Received: by 2002:a5d:8715:: with SMTP id u21mr21581417iom.1.1632188965125; Mon, 20 Sep 2021 18:49:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632188965; cv=none; d=google.com; s=arc-20160816; b=l80FvOuU2emtsZDucztotY1OE3Kqr6ZdaZscFSDvqT1L7It3r0vPmKISCGZeso84PM haCTT1D5VyN4+q5t5ZHPEnRxJndS0rK1Hkcn29uvPDXl2NVMkL/TCrPk8lL7VS3y4VAB 3V9lNJ45rXwjn8BuwETLbZSXyOcsCHlfAO+8AoeE+EZLnb8vwl61uEJ5uKQwGNbKP44p zXo3BDASvXnmo6dEvLwnUfhZZoWmHGUE/VQ56/jdwgtROfsDxNVMfEkhkCjeNJ7J5r6A 5WlpODM04zy5K+MKjIQlv6Aswml3Yg3O5OaYzhelygjTLXpWW+8DVekGJ3oD1NUxECzL OZVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LNK+cOa2G10DF2foUTO7pcdVcrfPS0dwlzcv3CP9npM=; b=golhXBbQQztYR53bnCq2tjR/134XP8uEqRuVJOvbtXb2lzvItQBDGFovML2IjwX7lO QjXL2AvGzjYAl2ne5aRAND1dhNL0550RBq992SF4pmyBz/VNE2GRZ4a9HJQKSCqqgNgX /9MNkxxci2CRP3sWHkwPzvZrDnq2B5ZGpgxITrpbEflhk7xEM6qB9irSM5IhVVSxX/CK +2UsipnyeHG/uTxgYNc0bEz2bf7Sv1ZiE8ojX0F3ywVFlxxqxLMDkGZlwvEmtB1FWO61 HscsPVkK9MvrRo6Xa6xyWeO5aRDSF9qrK7A8WQJheFwOX9x7nnoxF3aWziEj4EDCB+0r 5OLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IkMRXRtH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f184si2198791jac.98.2021.09.20.18.49.14; Mon, 20 Sep 2021 18:49:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IkMRXRtH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355484AbhITRyy (ORCPT + 99 others); Mon, 20 Sep 2021 13:54:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:52812 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354098AbhITRsx (ORCPT ); Mon, 20 Sep 2021 13:48:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A640861BB6; Mon, 20 Sep 2021 17:11:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632157877; bh=yIPfydS2oP2rEmzgNeetOSsUrPJdErXC2oPguSDHeYM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IkMRXRtHA7tBItE2042zsoVGBGOE1nY72KvtvjNWKbDK08q05vWUNKF3+4u33n+1L kjrlNTKMQhTNJTf9SpybyW9hBR6Q11wtJGg3pZR+e0fTJ/leptSB2I2Mhn3Ojt50qo 6OL7xRUweMQE7DHBfEE3ajFDaHphekFRLvyrwd5E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xin Long , Jon Maloy , "David S. Miller" , Sasha Levin Subject: [PATCH 4.19 175/293] tipc: keep the skb in rcv queue until the whole data is read Date: Mon, 20 Sep 2021 18:42:17 +0200 Message-Id: <20210920163939.271337512@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163933.258815435@linuxfoundation.org> References: <20210920163933.258815435@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xin Long [ Upstream commit f4919ff59c2828064b4156e3c3600a169909bcf4 ] Currently, when userspace reads a datagram with a buffer that is smaller than this datagram, the data will be truncated and only part of it can be received by users. It doesn't seem right that users don't know the datagram size and have to use a huge buffer to read it to avoid the truncation. This patch to fix it by keeping the skb in rcv queue until the whole data is read by users. Only the last msg of the datagram will be marked with MSG_EOR, just as TCP/SCTP does. Note that this will work as above only when MSG_EOR is set in the flags parameter of recvmsg(), so that it won't break any old user applications. Signed-off-by: Xin Long Acked-by: Jon Maloy Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/tipc/socket.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/net/tipc/socket.c b/net/tipc/socket.c index 6aead6deaa6c..e9acbb290d71 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c @@ -1716,6 +1716,7 @@ static int tipc_recvmsg(struct socket *sock, struct msghdr *m, bool connected = !tipc_sk_type_connectionless(sk); struct tipc_sock *tsk = tipc_sk(sk); int rc, err, hlen, dlen, copy; + struct tipc_skb_cb *skb_cb; struct sk_buff_head xmitq; struct tipc_msg *hdr; struct sk_buff *skb; @@ -1739,6 +1740,7 @@ static int tipc_recvmsg(struct socket *sock, struct msghdr *m, if (unlikely(rc)) goto exit; skb = skb_peek(&sk->sk_receive_queue); + skb_cb = TIPC_SKB_CB(skb); hdr = buf_msg(skb); dlen = msg_data_sz(hdr); hlen = msg_hdr_sz(hdr); @@ -1758,18 +1760,33 @@ static int tipc_recvmsg(struct socket *sock, struct msghdr *m, /* Capture data if non-error msg, otherwise just set return value */ if (likely(!err)) { - copy = min_t(int, dlen, buflen); - if (unlikely(copy != dlen)) - m->msg_flags |= MSG_TRUNC; - rc = skb_copy_datagram_msg(skb, hlen, m, copy); + int offset = skb_cb->bytes_read; + + copy = min_t(int, dlen - offset, buflen); + rc = skb_copy_datagram_msg(skb, hlen + offset, m, copy); + if (unlikely(rc)) + goto exit; + if (unlikely(offset + copy < dlen)) { + if (flags & MSG_EOR) { + if (!(flags & MSG_PEEK)) + skb_cb->bytes_read = offset + copy; + } else { + m->msg_flags |= MSG_TRUNC; + skb_cb->bytes_read = 0; + } + } else { + if (flags & MSG_EOR) + m->msg_flags |= MSG_EOR; + skb_cb->bytes_read = 0; + } } else { copy = 0; rc = 0; - if (err != TIPC_CONN_SHUTDOWN && connected && !m->msg_control) + if (err != TIPC_CONN_SHUTDOWN && connected && !m->msg_control) { rc = -ECONNRESET; + goto exit; + } } - if (unlikely(rc)) - goto exit; /* Mark message as group event if applicable */ if (unlikely(grp_evt)) { @@ -1792,9 +1809,10 @@ static int tipc_recvmsg(struct socket *sock, struct msghdr *m, tipc_node_distr_xmit(sock_net(sk), &xmitq); } - tsk_advance_rx_queue(sk); + if (!skb_cb->bytes_read) + tsk_advance_rx_queue(sk); - if (likely(!connected)) + if (likely(!connected) || skb_cb->bytes_read) goto exit; /* Send connection flow control advertisement when applicable */ -- 2.30.2