-
Notifications
You must be signed in to change notification settings - Fork 5
bpf: Fix FIONREAD and copied_seq issues #6416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: bpf-next_base
Are you sure you want to change the base?
bpf: Fix FIONREAD and copied_seq issues #6416
Conversation
|
Upstream branch: 590699d |
9b3817c to
90dfd48
Compare
|
Upstream branch: f2cb066 |
73f6092 to
a84d606
Compare
90dfd48 to
1559a3a
Compare
|
Upstream branch: 8c868a3 |
a84d606 to
7bf9758
Compare
1559a3a to
ae9b520
Compare
|
Upstream branch: 8f6ddc0 |
7bf9758 to
cb32b71
Compare
ae9b520 to
399fdcb
Compare
|
Upstream branch: 5262cb2 |
cb32b71 to
7e906ee
Compare
399fdcb to
8c83cb5
Compare
|
Upstream branch: 688b745 |
7e906ee to
df10136
Compare
8c83cb5 to
f015201
Compare
|
Upstream branch: 19f4091 |
df10136 to
f0cbe69
Compare
f015201 to
884c5bc
Compare
|
Upstream branch: bd5bdd2 |
f0cbe69 to
18d15e6
Compare
884c5bc to
4355736
Compare
|
Upstream branch: 34235a3 |
18d15e6 to
0aee2cf
Compare
4355736 to
5bece43
Compare
|
Upstream branch: 835a507 |
f1b0745 to
64a7d07
Compare
03e2ed2 to
3ea267d
Compare
|
Upstream branch: 835a507 |
64a7d07 to
4bc2215
Compare
3ea267d to
6d4eb64
Compare
|
Upstream branch: 835a507 |
4bc2215 to
b277238
Compare
6d4eb64 to
af4bac7
Compare
|
Upstream branch: 81f88f6 |
b277238 to
4488a44
Compare
af4bac7 to
6ba2fc1
Compare
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: 04919be ("tcp: Introduce tcp_read_skb()")
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
|
Upstream branch: 5d9fb42 |
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. Therefore, for sockmap, relying solely on copied_seq and rcv_nxt to calculate FIONREAD is not enough. This patch adds a new ingress_size field in the psock structure to record the data length in ingress_msg. Additionally, we implement new ioctl interfaces for TCP and UDP to intercept FIONREAD operations. While Unix and VSOCK also support sockmap and have similar FIONREAD calculation issues, fixing them would require more extensive changes (please let me know if modifications are needed). I believe it's not appropriate to include those changes under this fix patch. Previous work by John Fastabend made some efforts towards FIONREAD support: commit e5c6de5 ("bpf, sockmap: Incorrectly handling copied_seq") Although the current patch is based on the previous work by John Fastabend, it is acceptable for our Fixes tag to point to the same commit. 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 Fixes: 04919be ("tcp: Introduce tcp_read_skb()") Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
This commit adds two new test functions: one to reproduce the bug reported by syzkaller [1], and another to cover the calculation of copied_seq. The tests primarily involve installing and uninstalling sockmap on sockets, then reading data to verify proper functionality. Additionally, extend the do_test_sockmap_skb_verdict_fionread() function to support UDP FIONREAD testing. [1] https://syzkaller.appspot.com/bug?extid=06dbd397158ec0ea4983 Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
4488a44 to
fe70a12
Compare
b55822e to
d01de08
Compare
1d08ab8 to
c428576
Compare
Pull request for series with
subject: bpf: Fix FIONREAD and copied_seq issues
version: 4
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1027335