[PATCH] bpf, sockmap: fix cork data loss after redirect

From: Ömer Mete Kaya

Date: Sat Nov 14 2026 - 06:52:55 EST


In tcp_bpf_send_verdict(), when a corked message is redirected via
__SK_REDIRECT, the cork cleanup path unconditionally frees the entire
message and sets msg to NULL, even when only a partial send was
performed (tosend < total msg size due to apply_bytes).

This prevents the more_data loop at the end of the function from
processing the remaining bytes, silently dropping them. The check:

if (msg &&
msg->sg.data[msg->sg.start].page_link &&
msg->sg.data[msg->sg.start].length)
goto more_data;

can never trigger because msg is always NULL after the cork path.

Fix this by only freeing the cork message when it is fully consumed
or when the redirect failed. When unsent data remains, keep the
message alive so the more_data loop picks up the rest.

Discovered by Sashiko, not triggered, not runtime tested.

Fixes: 604326b41a6f ("bpf, sockmap: convert to generic sk_msg interface")
Signed-off-by: Ömer Mete Kaya <omermetekaya0@xxxxxxxxx>
---
net/ipv4/tcp_bpf.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c
index 8cf63a9e7fed..e6a8184aad6a 100644
--- a/net/ipv4/tcp_bpf.c
+++ b/net/ipv4/tcp_bpf.c
@@ -499,9 +499,13 @@ static int tcp_bpf_send_verdict(struct sock *sk, struct sk_psock *psock,
*copied -= free;
}
if (cork) {
- sk_msg_free(sk, msg);
- kfree(msg);
- msg = NULL;
+ if (ret < 0 ||
+ !msg->sg.data[msg->sg.start].page_link ||
+ !msg->sg.data[msg->sg.start].length) {
+ sk_msg_free(sk, msg);
+ kfree(msg);
+ msg = NULL;
+ }
ret = 0;
}
break;
--
2.56.0