From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: Zhang Cen <rollkingzzc@gmail.com>,
John Fastabend <john.fastabend@gmail.com>,
Jakub Sitnicki <jakub@cloudflare.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>
Cc: netdev@vger.kernel.org, bpf@vger.kernel.org,
linux-kernel@vger.kernel.org, zerocling0077@gmail.com,
2045gemini@gmail.com
Subject: Re: [PATCH] net: skmsg: pin the delayed-work psock in sk_psock_backlog
Date: Fri, 15 May 2026 14:09:53 +0800 [thread overview]
Message-ID: <e0a24b78-9800-4927-b611-ccbad1e906fe@linux.dev> (raw)
In-Reply-To: <20260515050437.104716-1-rollkingzzc@gmail.com>
On 5/15/26 1:04 PM, Zhang Cen wrote:
> sk_psock_backlog() recovers the psock it operates on from the delayed
> work item, but it takes its lifetime reference with
> sk_psock_get(psock->sk).
> That reloads sk->sk_user_data and can therefore return a replacement
> psock after the old psock was detached and a new one was attached to
> the same socket.
>
> In that case the worker locks and drains the old psock, but the
> reference it acquired belongs to the replacement psock. The exit path
> then puts the detached old psock, which can underflow its refcount
> after the last unlink while the replacement psock keeps the leaked
> reference.
>
> Take the reference on the delayed-work psock directly with
> refcount_inc_not_zero(). If that fails, the old psock is already being
> dropped, so skip the detached backlog instead of processing or putting
> it. This keeps the worker's get/put pair on the same psock whose
> work_state, ingress queue and state bits it manipulates.
>
> The buggy scenario involves two paths, with each column showing the
> order within that path:
>
> path A label: detach and reattach path path B label: old backlog worker
> 1. The last unlink drops the old 1. Delayed work resumes from the
> psock into sk_psock_drop(). old psock embedded in work.
> 2. sk_psock_drop() clears 2. The worker still sees
> sk->sk_user_data before the old SK_PSOCK_TX_ENABLED on that
> TX state is cleared. old psock.
> 3. A new attach publishes a 3. sk_psock_get(psock->sk)
> replacement psock on the same reloads sk->sk_user_data and
> socket. refs the replacement psock.
> 4. The old psock is still queued for 4. The worker locks, drains and
> delayed backlog work. finally puts the detached old
> psock.
>
> Sanitizer validation reported:
> Non-fatal target warning: refcount_t underflow/use-after-free warning from refcount_warn_saturate triggered by sk_psock_backlog putting the detached old psock after last_old_ref_before_put reached 0.
Where is the 'last_old_ref_before_put' symbol from? I can't find it
anywhere in the tree.
If you are using LLMs to dig into races like this, please also have them
produce a reproducer, e.g. patch mdelay() into
the relevant windows to widen them, then trigger it from userspace.
next prev parent reply other threads:[~2026-05-15 6:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-15 5:04 [PATCH] net: skmsg: pin the delayed-work psock in sk_psock_backlog Zhang Cen
2026-05-15 6:09 ` Jiayuan Chen [this message]
2026-05-15 8:12 ` Cen Zhang
2026-05-15 8:26 ` Jiayuan Chen
2026-05-15 8:54 ` Jiayuan Chen
2026-05-15 9:10 ` Cen Zhang
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=e0a24b78-9800-4927-b611-ccbad1e906fe@linux.dev \
--to=jiayuan.chen@linux.dev \
--cc=2045gemini@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jakub@cloudflare.com \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rollkingzzc@gmail.com \
--cc=zerocling0077@gmail.com \
/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