Commit 9072931f authored by Pengcheng Yang's avatar Pengcheng Yang Committed by Daniel Borkmann
Browse files

bpf, sockmap: Fix data loss caused by using apply_bytes on ingress redirect



Use apply_bytes on ingress redirect, when apply_bytes is less than
the length of msg data, some data may be skipped and lost in
bpf_tcp_ingress().

If there is still data in the scatterlist that has not been consumed,
we cannot move the msg iter.

Fixes: 604326b4 ("bpf, sockmap: convert to generic sk_msg interface")
Signed-off-by: default avatarPengcheng Yang <yangpc@wangsu.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarJakub Sitnicki <jakub@cloudflare.com>
Link: https://lore.kernel.org/bpf/1669718441-2654-4-git-send-email-yangpc@wangsu.com
parent a351d608
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -45,9 +45,12 @@ static int bpf_tcp_ingress(struct sock *sk, struct sk_psock *psock,
		tmp->sg.end = i;
		if (apply) {
			apply_bytes -= size;
			if (!apply_bytes)
			if (!apply_bytes) {
				if (sge->length)
					sk_msg_iter_var_prev(i);
				break;
			}
		}
	} while (i != msg->sg.end);

	if (!ret) {