summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorAlexei Starovoitov <ast@kernel.org>2026-11-02 07:21:01 +0000
committerAlexei Starovoitov <ast@kernel.org>2026-11-04 18:47:24 +0000
commitfa84be67b5bc2999c6962e18c5deee2e90483bfb (patch)
tree13a57ff3dbe231336c7473ccf3a9b0239319f097 /net
parentf4c044966d6c896c46ea0fd929df3b7c06529ef8 (diff)
bpf, sockmap: Subtract all dropped bytes from the return value
When an sk_msg prog returns SK_DROP, tcp_bpf_send_verdict() frees the full message. It then subtracts tosend bytes from *copied, the return value of sendmsg(). But tosend is the number of bytes that the verdict applies to. After bpf_msg_apply_bytes() tosend can be less than the message size. Then sendmsg() reports dropped bytes as sent. Subtract the number of bytes that sk_msg_free() frees. After an error the SK_PASS branch already does this. The SK_REDIRECT branch does the same if the message is not the cork. Nothing changes when tosend is equal to the message size. Otherwise sendmsg() now returns -EACCES if it sends nothing. Fixes: ca70b8baf2bd ("tcp_bpf: Fix the sk_mem_uncharge logic in tcp_bpf_sendmsg") Signed-off-by: Alexei Starovoitov <ast@kernel.org> Reviewed-by: Jiayuan Chen <jiayuan.chen@linux.dev> Reviewed-by: John Fastabend <john.fastabend@gmail.com> Link: https://patch.msgid.link/20261102072112.4160195-5-alexei.starovoitov@gmail.com
Diffstat (limited to 'net')
-rw-r--r--net/ipv4/tcp_bpf.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c
index b016aa419fb2..36d1bf46353a 100644
--- a/net/ipv4/tcp_bpf.c
+++ b/net/ipv4/tcp_bpf.c
@@ -521,12 +521,12 @@ more_data:
break;
case __SK_DROP:
default:
- sk_msg_free(sk, msg);
+ /* All of it is thrown away, not only tosend bytes */
+ *copied -= sk_msg_free(sk, msg) + delta;
sk_msg_apply_bytes(psock, tosend);
/* The verdict holds for apply_bytes, not for ever */
if (!psock->apply_bytes)
psock->eval = __SK_NONE;
- *copied -= (tosend + delta);
return -EACCES;
}