Re: [PATCH] bpf, sockmap: defer sk_psock_free_link() using RCU

From: Jakub Sitnicki
Date: Wed May 22 2024 - 05:51:02 EST


On Wed, May 22, 2024 at 06:59 AM +08, Hillf Danton wrote:
> On Tue, 21 May 2024 08:38:52 -0700 Alexei Starovoitov <alexei.starovoitov@xxxxxxxxx>
>> On Sun, May 12, 2024 at 12:22=E2=80=AFAM Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx> wrote:
>> > --- a/net/core/sock_map.c
>> > +++ b/net/core/sock_map.c
>> > @@ -142,6 +142,7 @@ static void sock_map_del_link(struct sock *sk,
>> > bool strp_stop =3D false, verdict_stop =3D false;
>> > struct sk_psock_link *link, *tmp;
>> >
>> > + rcu_read_lock();
>> > spin_lock_bh(&psock->link_lock);
>>
>> I think this is incorrect.
>> spin_lock_bh may sleep in RT and it won't be safe to do in rcu cs.
>
> Could you specify why it won't be safe in rcu cs if you are right?
> What does rcu look like in RT if not nothing?

RCU readers can't block, while spinlock RT doesn't disable preemption.

https://docs.kernel.org/RCU/rcu.html
https://docs.kernel.org/locking/locktypes.html#spinlock-t-and-preempt-rt

I've finally gotten around to testing proposed fix that just disallows
map_delete_elem on sockmap/sockhash from BPF tracing progs
completely. This should put an end to this saga of syzkaller reports.

https://lore.kernel.org/all/87jzjnxaqf.fsf@xxxxxxxxxxxxxx/