[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <b403d53317c0bd8125cecbc0651e54338ca11bfd@linux.dev>
Date: Thu, 20 Mar 2025 12:36:53 +0000
From: "Jiayuan Chen" <jiayuan.chen@...ux.dev>
To: "Cong Wang" <xiyou.wangcong@...il.com>
Cc: john.fastabend@...il.com, jakub@...udflare.com, davem@...emloft.net,
edumazet@...gle.com, kuba@...nel.org, pabeni@...hat.com,
horms@...nel.org, andrii@...nel.org, eddyz87@...il.com, mykolal@...com,
ast@...nel.org, daniel@...earbox.net, martin.lau@...ux.dev,
song@...nel.org, yonghong.song@...ux.dev, kpsingh@...nel.org,
sdf@...ichev.me, haoluo@...gle.com, jolsa@...nel.org, shuah@...nel.org,
mhal@...x.co, sgarzare@...hat.com, netdev@...r.kernel.org,
bpf@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-kselftest@...r.kernel.org,
syzbot+dd90a702f518e0eac072@...kaller.appspotmail.com
Subject: Re: [PATCH bpf-next v3 2/3] bpf, sockmap: avoid using sk_socket
after free when reading
March 20, 2025 at 08:34, "Cong Wang" <xiyou.wangcong@...il.com> wrote:
>
> On Mon, Mar 17, 2025 at 05:22:55PM +0800, Jiayuan Chen wrote:
>
> >
> > There are potential concurrency issues, as shown below.
> >
> > '''
> >
> > CPU0 CPU1
> >
> > sk_psock_verdict_data_ready:
> >
> > socket *sock = sk->sk_socket
> >
> > if (!sock) return
> >
> > close(fd):
> >
> > ...
> >
> > ops->release()
> >
> > if (!sock->ops) return
> >
> > sock->ops = NULL
> >
> > rcu_call(sock)
> >
> > free(sock)
> >
> > READ_ONCE(sock->ops)
> >
> > ^
> >
> > use 'sock' after free
> >
> > '''
> >
> >
> >
> > RCU is not applicable to Unix sockets read path, because the Unix socket
> >
> > implementation itself assumes it's always in process context and heavily
> >
> > uses mutex_lock, so, we can't call read_skb within rcu lock.
> >
>
> Hm, I guess the RCU work in sk_psock_drop() does not work for Unix
>
> domain sockets either?
>
> Thanks.
>
Although the Unix domain socket framework does not use RCU locks, the
entire sockmap process protects access to psock via RCU:
'''
rcu_read_lock();
psock = sk_psock(sk_other);
if (psock) {
...
}
rcu_read_unlock(); // `sk_psock_drop` will not execute until the unlock
'''
Therefore, I believe there are no issues with the psock operations here.
Thanks~
Powered by blists - more mailing lists