]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
bpf, sockmap: Fix incorrect copied_seq calculation
authorJiayuan Chen <jiayuan.chen@linux.dev>
Sat, 24 Jan 2026 11:32:43 +0000 (19:32 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 27 Jan 2026 17:11:30 +0000 (09:11 -0800)
commitb40cc5adaa80e1471095a62d78233b611d7a558c
treec37bf9c643becb942e776e31320b8fa618ebd86b
parent1456ebb291ddee67c9144c8f7f38a6dddcd32ed7
bpf, sockmap: Fix incorrect copied_seq calculation

A socket using sockmap has its own independent receive queue: ingress_msg.
This queue may contain data from its own protocol stack or from other
sockets.

The issue is that when reading from ingress_msg, we update tp->copied_seq
by default. However, if the data is not from its own protocol stack,
tcp->rcv_nxt is not increased. Later, if we convert this socket to a
native socket, reading from this socket may fail because copied_seq might
be significantly larger than rcv_nxt.

This fix also addresses the syzkaller-reported bug referenced in the
Closes tag.

This patch marks the skmsg objects in ingress_msg. When reading, we update
copied_seq only if the data is from its own protocol stack.

                                                     FD1:read()
                                                     --  FD1->copied_seq++
                                                         |  [read data]
                                                         |
                                [enqueue data]           v
                  [sockmap]     -> ingress to self ->  ingress_msg queue
FD1 native stack  ------>                                 ^
-- FD1->rcv_nxt++               -> redirect to other      | [enqueue data]
                                       |                  |
                                       |             ingress to FD1
                                       v                  ^
                                      ...                 |  [sockmap]
                                                     FD2 native stack

Closes: https://syzkaller.appspot.com/bug?extid=06dbd397158ec0ea4983
Fixes: 04919bed948dc ("tcp: Introduce tcp_read_skb()")
Reviewed-by: Jakub Sitnicki <jakub@cloudflare.com>
Reviewed-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
Link: https://lore.kernel.org/r/20260124113314.113584-2-jiayuan.chen@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/linux/skmsg.h
net/core/skmsg.c
net/ipv4/tcp_bpf.c