Re: [PATCH] udp6: Fix race condition in udp6_sendmsg & connect

From: Vlad Efanov
Date: Fri May 26 2023 - 12:41:15 EST

sk_dst_set() is called by sk_setup_caps().

sk_dst_set() replaces dst in socket using xchg() call and we still have two tasks use one socket but expect different dst in sk_dst_cache.

__sk_dst_set() is rcu protected, but it checks for socket lock.

static inline void
__sk_dst_set(struct sock *sk, struct dst_entry *dst)
    struct dst_entry *old_dst;

    sk->sk_dst_pending_confirm = 0;
    old_dst = rcu_dereference_protected(sk->sk_dst_cache,
    rcu_assign_pointer(sk->sk_dst_cache, dst);

Best regards.


On 26.05.2023 19:00, Eric Dumazet wrote:
On Fri, May 26, 2023 at 5:58 PM Ефанов Владислав Александрович
<vefanov@xxxxxxxxx> wrote:

I don't think that we can just move sk_dst_set() call.

I think we can destroy dst of sendmsg task in this case.

dst are RCU protected, it should be easy to make sure we respect all the rules.