mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: bot+bpf-ci@kernel.org
To: jiayuan.chen@linux.dev,bpf@vger.kernel.org,ast@kernel.org
Cc: jiayuan.chen@linux.dev,john.fastabend@gmail.com,jakub@cloudflare.com,davem@davemloft.net,edumazet@kernel.org,kuba@kernel.org,pabeni@redhat.com,horms@kernel.org,kuniyu@google.com,willemb@google.com,ncardwell@google.com,daniel@iogearbox.net,andrii@kernel.org,eddyz87@gmail.com,memxor@gmail.com,martin.lau@linux.dev,song@kernel.org,yonghong.song@linux.dev,jolsa@kernel.org,emil@etsalapatis.com,ihor.solodrai@linux.dev,shuah@kernel.org,rhkrqnwk98@gmail.com,mhal@rbox.co,mattia.meleleo@coralogix.com,linux-kernel@vger.kernel.org,netdev@vger.kernel.org,linux-kselftest@vger.kernel.org,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf 03/11] bpf, sockmap: Fix strparser reinit after the parser link is removed
Date: Sat, 21 Nov 2026 11:26:44 +0000 (UTC)	[thread overview]
Message-ID: <ab092342eebeb1a7b9330adb3ee4643fcb025c330a45c80872dcc29ea6874cb6@mail.kernel.org> (raw)
In-Reply-To: <20261121103222.88209-4-jiayuan.chen@linux.dev>

[-- Attachment #1: Type: text/plain, Size: 3921 bytes --]

> 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

  reply	other threads:[~2026-11-21 11:26 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-21 10:30 [PATCH bpf 00/11] fix misc sockmap issues Jiayuan Chen
2026-11-21 10:30 ` [PATCH bpf 01/11] bpf, sockmap: Fix copied_seq updates with strparser Jiayuan Chen
2026-11-21 10:30 ` [PATCH bpf 02/11] selftests/bpf: Add test for unread SK_PASS data " Jiayuan Chen
2026-11-21 10:30 ` [PATCH bpf 03/11] bpf, sockmap: Fix strparser reinit after the parser link is removed Jiayuan Chen
2026-11-21 11:26   ` bot+bpf-ci [this message]
2026-11-21 10:30 ` [PATCH bpf 04/11] bpf, sockmap: Fix empty sk_msg queued by ingress redirect Jiayuan Chen
2026-11-21 10:30 ` [PATCH bpf 05/11] bpf, sockmap: Fix concurrent senders on one psock Jiayuan Chen
2026-11-21 10:30 ` [PATCH bpf 06/11] bpf, sockmap: Fix reconnect with a psock by rejecting disconnect Jiayuan Chen
2026-11-21 10:30 ` [PATCH bpf 07/11] bpf, sockmap: Fix psock refcnt taken in sk_psock_backlog() Jiayuan Chen
2026-11-21 10:30 ` [PATCH bpf 08/11] bpf, sockmap: Fix socket lock taken on a child before accept() Jiayuan Chen
2026-11-21 11:26   ` bot+bpf-ci
2026-11-21 10:30 ` [PATCH bpf 09/11] bpf, sockmap: Fix apply_bytes when a redirect sends only a part Jiayuan Chen
2026-11-21 11:11   ` bot+bpf-ci
2026-11-21 10:30 ` [PATCH bpf 10/11] selftests/bpf: Fix errno expected by the wait send mem test of test_sockmap Jiayuan Chen
2026-11-21 10:30 ` [PATCH bpf 11/11] selftests/bpf: Add test for apply_bytes when a redirect sends a part Jiayuan Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ab092342eebeb1a7b9330adb3ee4643fcb025c330a45c80872dcc29ea6874cb6@mail.kernel.org \
    --to=bot+bpf-ci@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=eddyz87@gmail.com \
    --cc=edumazet@kernel.org \
    --cc=emil@etsalapatis.com \
    --cc=horms@kernel.org \
    --cc=ihor.solodrai@linux.dev \
    --cc=jakub@cloudflare.com \
    --cc=jiayuan.chen@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mason@kernel.org \
    --cc=mattia.meleleo@coralogix.com \
    --cc=memxor@gmail.com \
    --cc=mhal@rbox.co \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rhkrqnwk98@gmail.com \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=willemb@google.com \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®