From: "Jiayuan Chen" <jiayuan.chen@linux.dev>
To: "Cong Wang" <xiyou.wangcong@gmail.com>
Cc: john.fastabend@gmail.com, jakub@cloudflare.com,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, andrii@kernel.org,
eddyz87@gmail.com, mykolal@fb.com, ast@kernel.org,
daniel@iogearbox.net, martin.lau@linux.dev, song@kernel.org,
yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me,
haoluo@google.com, jolsa@kernel.org, shuah@kernel.org,
mhal@rbox.co, sgarzare@redhat.com, netdev@vger.kernel.org,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH bpf-next v3 1/3] bpf, sockmap: avoid using sk_socket after free when sending
Date: Wed, 19 Mar 2025 23:36:13 +0000 [thread overview]
Message-ID: <48068a86ea99dffe1e7849fb544eac1746364afb@linux.dev> (raw)
In-Reply-To: <Z9tNAhMV1Y5znONo@pop-os.localdomain>
2025/3/20 07:02, "Cong Wang" <xiyou.wangcong@gmail.com> wrote:
>
> On Mon, Mar 17, 2025 at 05:22:54PM +0800, Jiayuan Chen wrote:
>
> >
> > The sk->sk_socket is not locked or referenced, and during the call to
> >
>
> Hm? We should have a reference in socket map, whether directly or
>
> indirectly, right? When we add a socket to a socket map, we do call
>
> sock_map_psock_get_checked() to obtain a reference.
>
Yes, but we remove psock from sockmap when sock_map_close() was called
'''
sock_map_close
lock_sock(sk);
rcu_read_lock();
psock = sk_psock(sk);
// here we remove psock and the reference of psock become 0
sock_map_remove_links(sk, psock)
psock = sk_psock_get(sk);
if (unlikely(!psock))
goto no_psock; <=== jmp to no_psock
rcu_read_unlock();
release_sock(sk);
cancel_delayed_work_sync(&psock->work); <== no chance to run cancel
'''
So I think we should hold the psock when backlog running
Thanks,
next prev parent reply other threads:[~2025-03-19 23:36 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-17 9:22 [PATCH bpf-next v3 0/3] bpf: Fix use-after-free of sockmap Jiayuan Chen
2025-03-17 9:22 ` [PATCH bpf-next v3 1/3] bpf, sockmap: avoid using sk_socket after free when sending Jiayuan Chen
2025-03-19 23:02 ` Cong Wang
2025-03-19 23:36 ` Jiayuan Chen [this message]
2025-03-20 0:06 ` Cong Wang
2025-03-20 0:27 ` Jiayuan Chen
2025-03-20 12:32 ` Michal Luczaj
2025-03-20 14:48 ` Jiayuan Chen
2025-03-17 9:22 ` [PATCH bpf-next v3 2/3] bpf, sockmap: avoid using sk_socket after free when reading Jiayuan Chen
2025-03-20 0:34 ` Cong Wang
2025-03-20 12:36 ` Jiayuan Chen
2025-03-17 9:22 ` [PATCH bpf-next v3 3/3] selftests/bpf: Add edge case tests for sockmap 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=48068a86ea99dffe1e7849fb544eac1746364afb@linux.dev \
--to=jiayuan.chen@linux.dev \
--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@google.com \
--cc=haoluo@google.com \
--cc=horms@kernel.org \
--cc=jakub@cloudflare.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mhal@rbox.co \
--cc=mykolal@fb.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--cc=sgarzare@redhat.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=xiyou.wangcong@gmail.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;
as well as URLs for NNTP newsgroup(s).