Skip to content

Commit 3a8e680

Browse files
mrpregregkh
authored andcommitted
bpf, sockmap: fix duplicated data transmission
[ Upstream commit 3b4f14b ] 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: 405df89 ("bpf, sockmap: Improved check for empty queue") Signed-off-by: Jiayuan Chen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 57fbbe2 commit 3a8e680

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

net/core/skmsg.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -655,11 +655,6 @@ static void sk_psock_backlog(struct work_struct *work)
655655
int ret;
656656

657657
mutex_lock(&psock->work_mutex);
658-
if (unlikely(state->len)) {
659-
len = state->len;
660-
off = state->off;
661-
}
662-
663658
while ((skb = skb_peek(&psock->ingress_skb))) {
664659
len = skb->len;
665660
off = 0;
@@ -669,6 +664,13 @@ static void sk_psock_backlog(struct work_struct *work)
669664
off = stm->offset;
670665
len = stm->full_len;
671666
}
667+
668+
/* Resume processing from previous partial state */
669+
if (unlikely(state->len)) {
670+
len = state->len;
671+
off = state->off;
672+
}
673+
672674
ingress = skb_bpf_ingress(skb);
673675
skb_bpf_redirect_clear(skb);
674676
do {
@@ -696,6 +698,8 @@ static void sk_psock_backlog(struct work_struct *work)
696698
len -= ret;
697699
} while (len);
698700

701+
/* The entire skb sent, clear state */
702+
sk_psock_skb_state(psock, state, 0, 0);
699703
skb = skb_dequeue(&psock->ingress_skb);
700704
kfree_skb(skb);
701705
}

0 commit comments

Comments
 (0)