Skip to content

Commit 8333545

Browse files
author
Xin Long
committed
tipc: keep the skb in rcv queue until the whole data is read
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2160540 Tested: compile only commit f4919ff Author: Xin Long <lucien.xin@gmail.com> Date: Fri Jul 16 17:44:07 2021 -0400 tipc: keep the skb in rcv queue until the whole data is read 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 <lucien.xin@gmail.com> Acked-by: Jon Maloy <jmaloy@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Xin Long <lxin@redhat.com>
1 parent e66c18c commit 8333545

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

net/tipc/socket.c

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,6 +1889,7 @@ static int tipc_recvmsg(struct socket *sock, struct msghdr *m,
18891889
bool connected = !tipc_sk_type_connectionless(sk);
18901890
struct tipc_sock *tsk = tipc_sk(sk);
18911891
int rc, err, hlen, dlen, copy;
1892+
struct tipc_skb_cb *skb_cb;
18921893
struct sk_buff_head xmitq;
18931894
struct tipc_msg *hdr;
18941895
struct sk_buff *skb;
@@ -1912,6 +1913,7 @@ static int tipc_recvmsg(struct socket *sock, struct msghdr *m,
19121913
if (unlikely(rc))
19131914
goto exit;
19141915
skb = skb_peek(&sk->sk_receive_queue);
1916+
skb_cb = TIPC_SKB_CB(skb);
19151917
hdr = buf_msg(skb);
19161918
dlen = msg_data_sz(hdr);
19171919
hlen = msg_hdr_sz(hdr);
@@ -1931,18 +1933,33 @@ static int tipc_recvmsg(struct socket *sock, struct msghdr *m,
19311933

19321934
/* Capture data if non-error msg, otherwise just set return value */
19331935
if (likely(!err)) {
1934-
copy = min_t(int, dlen, buflen);
1935-
if (unlikely(copy != dlen))
1936-
m->msg_flags |= MSG_TRUNC;
1937-
rc = skb_copy_datagram_msg(skb, hlen, m, copy);
1936+
int offset = skb_cb->bytes_read;
1937+
1938+
copy = min_t(int, dlen - offset, buflen);
1939+
rc = skb_copy_datagram_msg(skb, hlen + offset, m, copy);
1940+
if (unlikely(rc))
1941+
goto exit;
1942+
if (unlikely(offset + copy < dlen)) {
1943+
if (flags & MSG_EOR) {
1944+
if (!(flags & MSG_PEEK))
1945+
skb_cb->bytes_read = offset + copy;
1946+
} else {
1947+
m->msg_flags |= MSG_TRUNC;
1948+
skb_cb->bytes_read = 0;
1949+
}
1950+
} else {
1951+
if (flags & MSG_EOR)
1952+
m->msg_flags |= MSG_EOR;
1953+
skb_cb->bytes_read = 0;
1954+
}
19381955
} else {
19391956
copy = 0;
19401957
rc = 0;
1941-
if (err != TIPC_CONN_SHUTDOWN && connected && !m->msg_control)
1958+
if (err != TIPC_CONN_SHUTDOWN && connected && !m->msg_control) {
19421959
rc = -ECONNRESET;
1960+
goto exit;
1961+
}
19431962
}
1944-
if (unlikely(rc))
1945-
goto exit;
19461963

19471964
/* Mark message as group event if applicable */
19481965
if (unlikely(grp_evt)) {
@@ -1965,9 +1982,10 @@ static int tipc_recvmsg(struct socket *sock, struct msghdr *m,
19651982
tipc_node_distr_xmit(sock_net(sk), &xmitq);
19661983
}
19671984

1968-
tsk_advance_rx_queue(sk);
1985+
if (!skb_cb->bytes_read)
1986+
tsk_advance_rx_queue(sk);
19691987

1970-
if (likely(!connected))
1988+
if (likely(!connected) || skb_cb->bytes_read)
19711989
goto exit;
19721990

19731991
/* Send connection flow control advertisement when applicable */

0 commit comments

Comments
 (0)