]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
bpf, sockmap: fix duplicated data transmission
authorJiayuan Chen <jiayuan.chen@linux.dev>
Mon, 7 Apr 2025 14:21:21 +0000 (22:21 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 27 Jun 2025 10:07:09 +0000 (11:07 +0100)
[ Upstream commit 3b4f14b794287be137ea2c6158765d1ea1e018a4 ]

In the !ingress path under sk_psock_handle_skb(), when sending data to the
remote under snd_buf limitations, partial skb data might be transmitted.

Although we preserved the partial transmission state (offset/length), the
state wasn't properly consumed during retries. This caused the retry path
to resend the entire skb data instead of continuing from the previous
offset, resulting in data overlap at the receiver side.

Fixes: 405df89dd52c ("bpf, sockmap: Improved check for empty queue")
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
Link: https://lore.kernel.org/r/20250407142234.47591-3-jiayuan.chen@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/core/skmsg.c

index 5a790cd1121b10681a7fd8b4e98b0a6407ddaf9a..72f4949cbb70f5e30585b2ad890d9accd72fc662 100644 (file)
@@ -654,11 +654,6 @@ static void sk_psock_backlog(struct work_struct *work)
        int ret;
 
        mutex_lock(&psock->work_mutex);
-       if (unlikely(state->len)) {
-               len = state->len;
-               off = state->off;
-       }
-
        while ((skb = skb_peek(&psock->ingress_skb))) {
                len = skb->len;
                off = 0;
@@ -668,6 +663,13 @@ static void sk_psock_backlog(struct work_struct *work)
                        off = stm->offset;
                        len = stm->full_len;
                }
+
+               /* Resume processing from previous partial state */
+               if (unlikely(state->len)) {
+                       len = state->len;
+                       off = state->off;
+               }
+
                ingress = skb_bpf_ingress(skb);
                skb_bpf_redirect_clear(skb);
                do {
@@ -695,6 +697,8 @@ static void sk_psock_backlog(struct work_struct *work)
                        len -= ret;
                } while (len);
 
+               /* The entire skb sent, clear state */
+               sk_psock_skb_state(psock, state, 0, 0);
                skb = skb_dequeue(&psock->ingress_skb);
                kfree_skb(skb);
        }