| From e9df8c6a5d35e83d8337e7f1670bd78274a7b423 Mon Sep 17 00:00:00 2001 | |
| From: Sasha Levin <sashal@kernel.org> | |
| Date: Tue, 6 Oct 2026 14:29:59 +0100 | |
| Subject: rxrpc: Fix sendmsg length | |
| From: David Howells <dhowells@redhat.com> | |
| [ Upstream commit ef369cacbd524931199078427ae152c63a826189 ] | |
| rxrpc_send_data() is given two data lengths (len and msg->msg_iter.count) | |
| and is inconsistent about how it uses them. Fix this by using len in | |
| preference to msg->msg_iter.count. Also limit the amount copied to either | |
| len or msg->msg_iter.count, whichever is smaller. | |
| Note that, currently, all the callers have len and msg->msg_iter.count the | |
| same and so the problem won't occur. This is a prerequisite for another | |
| patch that fixes the handling of encryption errors. | |
| Fixes: 382d7974de31 ("RxRPC: Use iov_iter_count() in rxrpc_send_data() instead of the len argument") | |
| Signed-off-by: David Howells <dhowells@redhat.com> | |
| cc: Marc Dionne <marc.dionne@auristor.com> | |
| cc: Jeffrey Altman <jaltman@auristor.com> | |
| cc: Eric Dumazet <edumazet@google.com> | |
| cc: "David S. Miller" <davem@davemloft.net> | |
| cc: Jakub Kicinski <kuba@kernel.org> | |
| cc: Paolo Abeni <pabeni@redhat.com> | |
| cc: Simon Horman <horms@kernel.org> | |
| cc: linux-afs@lists.infradead.org | |
| Link: https://patch.msgid.link/20261006133011.531806-8-dhowells@redhat.com | |
| Signed-off-by: Paolo Abeni <pabeni@redhat.com> | |
| [ sashal: Adapted the fix to the older skb-based send code, using len in the buffer sizing, copy clamp, full-packet test, last-packet flag and rxrpc_queue_packet() argument instead of txb-based helpers. ] | |
| Signed-off-by: Sasha Levin <sashal@kernel.org> | |
| --- | |
| net/rxrpc/sendmsg.c | 19 +++++++++++-------- | |
| 1 file changed, 11 insertions(+), 8 deletions(-) | |
| diff --git a/net/rxrpc/sendmsg.c b/net/rxrpc/sendmsg.c | |
| index 4b5ee70433039..a4ad0dc9f4367 100644 | |
| --- a/net/rxrpc/sendmsg.c | |
| +++ b/net/rxrpc/sendmsg.c | |
| @@ -318,9 +318,9 @@ static int rxrpc_send_data(struct rxrpc_sock *rx, | |
| ret = -EMSGSIZE; | |
| if (call->tx_total_len != -1) { | |
| - if (len - copied > call->tx_total_len) | |
| + if (len > call->tx_total_len) | |
| goto maybe_error; | |
| - if (!more && len - copied != call->tx_total_len) | |
| + if (!more && len != call->tx_total_len) | |
| goto maybe_error; | |
| } | |
| @@ -343,7 +343,7 @@ static int rxrpc_send_data(struct rxrpc_sock *rx, | |
| * the security header is going to be in the padded | |
| * region (enc blocksize), but the trailer is not. | |
| */ | |
| - remain = more ? INT_MAX : msg_data_left(msg); | |
| + remain = more ? INT_MAX : len; | |
| ret = call->conn->security->how_much_data(call, remain, | |
| &bufsize, &chunk, &offset); | |
| if (ret < 0) | |
| @@ -387,9 +387,11 @@ static int rxrpc_send_data(struct rxrpc_sock *rx, | |
| sp = rxrpc_skb(skb); | |
| /* append next segment of data to the current buffer */ | |
| - if (msg_data_left(msg) > 0) { | |
| + if (len > 0) { | |
| int copy = skb_tailroom(skb); | |
| ASSERTCMP(copy, >, 0); | |
| + if (copy > len) | |
| + copy = len; | |
| if (copy > msg_data_left(msg)) | |
| copy = msg_data_left(msg); | |
| if (copy > sp->remain) | |
| @@ -403,6 +405,7 @@ static int rxrpc_send_data(struct rxrpc_sock *rx, | |
| sp->remain -= copy; | |
| skb->mark += copy; | |
| copied += copy; | |
| + len -= copy; | |
| if (call->tx_total_len != -1) | |
| call->tx_total_len -= copy; | |
| } | |
| @@ -414,7 +417,7 @@ static int rxrpc_send_data(struct rxrpc_sock *rx, | |
| /* add the packet to the send queue if it's now full */ | |
| if (sp->remain <= 0 || | |
| - (msg_data_left(msg) == 0 && !more)) { | |
| + (len == 0 && !more)) { | |
| struct rxrpc_connection *conn = call->conn; | |
| uint32_t seq; | |
| @@ -424,7 +427,7 @@ static int rxrpc_send_data(struct rxrpc_sock *rx, | |
| sp->hdr._rsvd = 0; | |
| sp->hdr.flags = conn->out_clientflag; | |
| - if (msg_data_left(msg) == 0 && !more) | |
| + if (len == 0 && !more) | |
| sp->hdr.flags |= RXRPC_LAST_PACKET; | |
| else if (call->tx_top - call->tx_hard_ack < | |
| call->tx_winsize) | |
| @@ -435,12 +438,12 @@ static int rxrpc_send_data(struct rxrpc_sock *rx, | |
| goto out_unlock; | |
| ret = rxrpc_queue_packet(rx, call, skb, | |
| - !msg_data_left(msg) && !more, | |
| + len == 0 && !more, | |
| notify_end_tx); | |
| /* Should check for failure here */ | |
| call->tx_pending = NULL; | |
| } | |
| - } while (msg_data_left(msg) > 0); | |
| + } while (len > 0 && msg_data_left(msg) > 0); | |
| success: | |
| ret = copied; | |
| -- | |
| 2.53.0 | |