Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1532571pxb; Thu, 16 Sep 2021 09:21:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwEL0Rl/0PpGnqr4eQXv7o8mJgYAszgi1/MsO68xxOy0u36u0Gh4t3zv79tLXmL3vUI1Q1t X-Received: by 2002:a50:bb09:: with SMTP id y9mr7264932ede.89.1631809317736; Thu, 16 Sep 2021 09:21:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631809317; cv=none; d=google.com; s=arc-20160816; b=ErF9OIBHLeabQz6UgnCON2Nt2fLx1bGmb6qmeVip1rZ3KbugH1+gVYpbmXtHVzqwep AJrFo+IDmmTdkywH9ee1INiz9/czT8SoaHhHbU9iQC0S8iYYnrg4aTahixNC5YGfiE6h tLVWKf6Uso5PueDmmxwGqDgfZy6ZzAQheg5bLKFWqUYPDtHnbd7x5bDgRROZdmGLxTEG LxSAnnSCXvznmOSI89L9+sYqkvCIH1VaNick5I35Mo6wOQ0WBnNiSfc6hxDlBnf8IGKs +BLYwRD0eNSiTG+ldN+3nmpzu8iv2dUqGWsAJ5hQNuXKg1DROPtFY5Rl5n4jiiRbUC1o x66Q== 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=ikfJAUW+CoB6XpZ8FZLCmvemcPTgnDJ2Xx7Zmqb4Xi8=; b=Xzk9sybYj90JmOBiayTtFSMog/MQS3QFlpwrHVrc+6OnZr45R4acIVVYjCTDKIKNZl 1NG5lRlnoL7oF/jTjA06QDHV4TNOXplBc/eV0fDvIPWCo80BXVYivHqzbSl/Y7TVPO4x sk5s34J/Zsw5xgSB0dQGQ4d6c9jo7g/cOq111xBmjjCqQb69zxRlxtqno1pGlgSKbT6s c2CyaWAlR8FbMnTMc7OjvMzMwV0iB9e24fqZEnR7YR4rbubF6NS79DRjj199pbFmhEr/ Si8xSIl/0WjyFRLvTUSmWyrxMmTjSDgKlW4t2IUuBPkEkuReskqd9jfw6lLMVCRN1jtb Ws0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uzBxdbTw; 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 c6si3890394ejc.71.2021.09.16.09.21.32; Thu, 16 Sep 2021 09:21:57 -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=uzBxdbTw; 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 S236175AbhIPQS2 (ORCPT + 99 others); Thu, 16 Sep 2021 12:18:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:47416 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237066AbhIPQKc (ORCPT ); Thu, 16 Sep 2021 12:10:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6CE146126A; Thu, 16 Sep 2021 16:08:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808508; bh=oXQrmImgzspKLQctNWZ27J0bJXr2dNfubqFfMuqlvks=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uzBxdbTw3eNqk1/HuL3E1uuxn7aoa6cVBAB8plY51O2yQPyAECTc4zMeAQ/sunhEE zueTedvESlW3UKJ7pW1QHr4WQ1TwO8snqZhzudVZFzge1E9ivLuwJuYoydjp6rw+UQ pAk44hfNGi0WCm1h39XDraAIGTvClhyhygTiydi0= 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 5.10 118/306] tipc: keep the skb in rcv queue until the whole data is read Date: Thu, 16 Sep 2021 17:57:43 +0200 Message-Id: <20210916155758.089107332@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@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 9bd72468bc68..963047c57c27 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c @@ -1887,6 +1887,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; @@ -1910,6 +1911,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); @@ -1929,18 +1931,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)) { @@ -1963,9 +1980,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