Skip to content

Commit 330442d

Browse files
author
Sabrina Dubroca
committed
bpf, ktls: Fix data corruption when using bpf_msg_pop_data() in ktls
JIRA: https://issues.redhat.com/browse/RHEL-115640 commit 178f6a5 Author: Jiayuan Chen <jiayuan.chen@linux.dev> Date: Mon Jun 9 10:08:52 2025 +0800 bpf, ktls: Fix data corruption when using bpf_msg_pop_data() in ktls When sending plaintext data, we initially calculated the corresponding ciphertext length. However, if we later reduced the plaintext data length via socket policy, we failed to recalculate the ciphertext length. This results in transmitting buffers containing uninitialized data during ciphertext transmission. This causes uninitialized bytes to be appended after a complete "Application Data" packet, leading to errors on the receiving end when parsing TLS record. Fixes: d3b18ad ("tls: add bpf support to sk_msg handling") Reported-by: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Reviewed-by: John Fastabend <john.fastabend@gmail.com> Acked-by: Jakub Kicinski <kuba@kernel.org> Link: https://lore.kernel.org/bpf/20250609020910.397930-2-jiayuan.chen@linux.dev Signed-off-by: Sabrina Dubroca <sdubroca@redhat.com>
1 parent 8428d1d commit 330442d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

net/tls/tls_sw.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,19 @@ static int bpf_exec_tx_verdict(struct sk_msg *msg, struct sock *sk,
865865
delta = msg->sg.size;
866866
psock->eval = sk_psock_msg_verdict(sk, psock, msg);
867867
delta -= msg->sg.size;
868+
869+
if ((s32)delta > 0) {
870+
/* It indicates that we executed bpf_msg_pop_data(),
871+
* causing the plaintext data size to decrease.
872+
* Therefore the encrypted data size also needs to
873+
* correspondingly decrease. We only need to subtract
874+
* delta to calculate the new ciphertext length since
875+
* ktls does not support block encryption.
876+
*/
877+
struct sk_msg *enc = &ctx->open_rec->msg_encrypted;
878+
879+
sk_msg_trim(sk, enc, enc->sg.size - delta);
880+
}
868881
}
869882
if (msg->cork_bytes && msg->cork_bytes > msg->sg.size &&
870883
!enospc && !full_record) {

0 commit comments

Comments
 (0)