-
Notifications
You must be signed in to change notification settings - Fork 5
bpf, sockmap: Fix psock incorrectly pointing to sk #5369
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, sockmap: Fix psock incorrectly pointing to sk #5369
Conversation
Upstream branch: 8259eb0 |
bd529bf
to
11fe6ec
Compare
Upstream branch: bfccacd |
55a0c2e
to
e876912
Compare
11fe6ec
to
40a30fa
Compare
Upstream branch: 079e5c5 |
e876912
to
54b8e76
Compare
40a30fa
to
87ab7f8
Compare
Upstream branch: db22b13 |
54b8e76
to
7da39a0
Compare
87ab7f8
to
3f5c63a
Compare
Upstream branch: 1ae7a84 |
7da39a0
to
8893d15
Compare
3f5c63a
to
74bd0ee
Compare
Upstream branch: 86bc9c7 |
8893d15
to
014a330
Compare
74bd0ee
to
7ccca9e
Compare
Upstream branch: d496557 |
014a330
to
5796b03
Compare
7ccca9e
to
a352c18
Compare
Upstream branch: ca56fbd |
5796b03
to
c1b3c0b
Compare
a352c18
to
cff43b2
Compare
Upstream branch: 5ffb537 |
c1b3c0b
to
c202682
Compare
cff43b2
to
a597de4
Compare
Upstream branch: c5cebb2 |
c202682
to
00ae49a
Compare
18af9fe
to
653831c
Compare
Upstream branch: bb1556e |
00ae49a
to
80af544
Compare
653831c
to
04594e1
Compare
Upstream branch: bb1556e |
80af544
to
a278b64
Compare
04594e1
to
4224827
Compare
Upstream branch: cd2e103 |
a278b64
to
d9de908
Compare
4224827
to
e7b3cab
Compare
We observed an issue from the latest selftest: sockmap_redir where sk_psock(psock->sk) != psock in the backlog. The root cause is the special behavior in sockmap_redir - it frequently performs map_update() and map_delete() on the same socket. During map_update(), we create a new psock and during map_delete(), we eventually free the psock via rcu_work in sk_psock_drop(). However, pending workqueues might still exist and not be processed yet. If users immediately perform another map_update(), a new psock will be allocated for the same sk, resulting in two psocks pointing to the same sk. When the pending workqueue is later triggered, it uses the old psock to access sk for I/O operations, which is incorrect. Timing Diagram: cpu0 cpu1 map_update(sk): sk->psock = psock1 psock1->sk = sk map_delete(sk): rcu_work_free(psock1) map_update(sk): sk->psock = psock2 psock2->sk = sk workqueue: wakeup with psock1, but the sk of psock1 doesn't belong to psock1 rcu_handler: clean psock1 free(psock1) Previously, we used reference counting to address the concurrency issue between backlog and sock_map_close(). This logic remains necessary as it prevents the sk from being freed while processing the backlog. But this patch prevents pending backlogs from using a psock after it has been freed. Note: We cannot call cancel_delayed_work_sync() in map_delete() since this might be invoked in BPF context by BPF helper, and the function may sleep. Fixes: 604326b ("bpf, sockmap: convert to generic sk_msg interface") Signed-off-by: Jiayuan Chen <[email protected]>
Upstream branch: cd2e103 |
d9de908
to
9d5b34e
Compare
Pull request for series with
subject: bpf, sockmap: Fix psock incorrectly pointing to sk
version: 1
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=965935