Skip to content

Commit b6b701c

Browse files
mrpreKernel Patches Daemon
authored and
Kernel Patches Daemon
committed
ktls, sockmap: Fix missing uncharge operation
When we specify apply_bytes, we divide the msg into multiple segments, each with a length of 'send', and every time we send this part of the data using tcp_bpf_sendmsg_redir(), we use sk_msg_return_zero() to uncharge the memory of the specified 'send' size. However, if the first segment of data fails to send, for example, the peer's buffer is full, we need to release all of the msg. When releasing the msg, we haven't uncharged the memory of the subsequent segments. This modification does not make significant logical changes, but only fills in the missing uncharge places. This issue has existed all along, until it was exposed after we added the apply test in test_sockmap: commit 3448ad2 ("selftests/bpf: Add apply_bytes test to test_txmsg_redir_wait_sndmem in test_sockmap") Reported-by: Cong Wang <[email protected]> Closes: https://lore.kernel.org/bpf/[email protected]/T/#t Fixes: d3b18ad ("tls: add bpf support to sk_msg handling") Signed-off-by: Jiayuan Chen <[email protected]>
1 parent bebc5be commit b6b701c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

net/tls/tls_sw.c

+7
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,13 @@ static int bpf_exec_tx_verdict(struct sk_msg *msg, struct sock *sk,
908908
&msg_redir, send, flags);
909909
lock_sock(sk);
910910
if (err < 0) {
911+
/* Regardless of whether the data represented by
912+
* msg_redir is sent successfully, we have already
913+
* uncharged it via sk_msg_return_zero(). The
914+
* msg->sg.size represents the remaining unprocessed
915+
* data, which needs to be uncharged here.
916+
*/
917+
sk_mem_uncharge(sk, msg->sg.size);
911918
*copied -= sk_msg_free_nocharge(sk, &msg_redir);
912919
msg->sg.size = 0;
913920
}

0 commit comments

Comments
 (0)