Re: [PATCH bpf 03/11] bpf, sockmap: Fix strparser reinit after the parser link is removed

From: bot+bpf-ci

Date: Sat Nov 21 2026 - 06:26:55 EST


> bpf, sockmap: Fix strparser reinit after the parser link is removed

TL;DR:
- Behaviour regression possible: re-adding a socket to a parser map after
removing its only parser link may now fail with -EBUSY (also kcm/TLS setup)
- Misleading comment in sk_psock_destroy() and commit message for single-link
case

> diff --git a/net/core/skmsg.c b/net/core/skmsg.c
> --- a/net/core/skmsg.c
> +++ b/net/core/skmsg.c

[ ... ]

> @@ -879,6 +879,18 @@ static void sk_psock_destroy(struct work_struct *work)
> {
> struct sk_psock *psock = container_of(to_rcu_work(work),
> struct sk_psock, rwork);
> +
> + if (sk_psock_test_state(psock, SK_PSOCK_STRP_DONE_PENDING)) {
> + /* Parser link gone, other links keep the psock alive */

This comment doesn't hold when the removed link was the psock's only
link. In that case only the reference taken in sk_psock_queue_strp_done()
keeps the psock alive.

> + sk_psock_done_strp(psock);

[ ... ]

> diff --git a/net/core/sock_map.c b/net/core/sock_map.c
> --- a/net/core/sock_map.c
> +++ b/net/core/sock_map.c

[ ... ]

> @@ -169,8 +196,10 @@ static void sock_map_del_link(struct sock *sk,
>
> write_lock_bh(&sk->sk_callback_lock);
> if (psock->saved_data_ready) {
> - if (strp_stop)
> + if (strp_stop) {
> sk_psock_stop_strp(sk, psock);
> + sk_psock_queue_strp_done(psock);
> + }
> if (verdict_stop)
> sk_psock_stop_verdict(sk, psock);

[ ... ]

> @@ -297,6 +326,13 @@ static int sock_map_link(struct bpf_map *map, struct sock *sk)
> }
>
> write_lock_bh(&sk->sk_callback_lock);
> + if (stream_parser &&
> + sk_psock_test_state(psock, SK_PSOCK_RX_STRP_ENABLED)) {
> + write_unlock_bh(&sk->sk_callback_lock);
> + sk_psock_put(sk, psock);
> + ret = -EBUSY;
> + goto out_progs;
> + }

Can this make a previously working sequence fail when the removed parser
link was the only link on the psock?

Before this patch, removing the last link ended in
sock_map_unref() -> sk_psock_put() -> refcnt 0 -> sk_psock_drop(), which
cleared sk_user_data and restored sk_prot synchronously. A following add
of the same socket to a parser map found no psock in
sock_map_psock_get_checked() and sk_psock_init() created a fresh psock.

With this patch, sock_map_del_link() calls sk_psock_queue_strp_done(),
which does:

refcount_inc(&psock->refcnt);
INIT_WORK(&psock->rwork.work, sk_psock_destroy);
schedule_work(&psock->rwork.work);

so the old psock stays attached until the work runs.
sock_map_psock_get_checked() then returns that psock, and the new check
above sees SK_PSOCK_RX_STRP_ENABLED and returns -EBUSY.

sock_map_update_elem_sys() waits via sock_map_strp_done_wait(), but
sock_map_update_elem() as the map op and bpf_sock_map_update() /
bpf_sock_hash_update() cannot wait. A sockops or iterator program that
deletes a socket from its only parser map and adds it to a parser map now
fails with -EBUSY whenever the update comes before the work completes. If
the program runs with the socket lock owned, the work cannot finish in
between at all, since strp_done() takes lock_sock().

The lingering psock also seems to make kcm_attach() fail:

if (csk->sk_user_data) ... err = -EALREADY

and TLS setup fail in that window, where both would have succeeded on the
psock-less socket before.

The commit message says "Before this change the same sequence
reinitialized a live strparser, so this is the better outcome." Does that
premise only hold when another link keeps the psock alive? In the
single-link case the old code returned success.

Could the deferred strp_done be limited to psocks that survive the unlink?
Or could the commit message at least describe the single-link behavior
change?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/44896626218