On Thu, Jun 25, 2020 at 04:12:59PM -0700, John Fastabend wrote: > There are two paths to generate the below RCU splat the first and > most obvious is the result of the BPF verdict program issuing a > redirect on a TLS socket (This is the splat shown below). Unlike > the non-TLS case the caller of the *strp_read() hooks does not > wrap the call in a rcu_read_lock/unlock. Then if the BPF program > issues a redirect action we hit the RCU splat. > > However, in the non-TLS socket case the splat appears to be > relatively rare, because the skmsg caller into the strp_data_ready() > is wrapped in a rcu_read_lock/unlock. Shown here, > > static void sk_psock_strp_data_ready(struct sock *sk) > { > struct sk_psock *psock; > > rcu_read_lock(); > psock = sk_psock(sk); > if (likely(psock)) { > if (tls_sw_has_ctx_rx(sk)) { > psock->parser.saved_data_ready(sk); > } else { > write_lock_bh(&sk->sk_callback_lock); > strp_data_ready(&psock->parser.strp); > write_unlock_bh(&sk->sk_callback_lock); > } > } > rcu_read_unlock(); > } > > If the above was the only way to run the verdict program we > would be safe. But, there is a case where the strparser may throw an > ENOMEM error while parsing the skb. This is a result of a failed > skb_clone, or alloc_skb_for_msg while building a new merged skb when > the msg length needed spans multiple skbs. This will in turn put the > skb on the strp_wrk workqueue in the strparser code. The skb will > later be dequeued and verdict programs run, but now from a > different context without the rcu_read_lock()/unlock() critical > section in sk_psock_strp_data_ready() shown above. In practice > I have not seen this yet, because as far as I know most users of the > verdict programs are also only working on single skbs. In this case no > merge happens which could trigger the above ENOMEM errors. In addition > the system would need to be under memory pressure. For example, we > can't hit the above case in selftests because we missed having tests > to merge skbs. (Added in later patch) > > To fix the below splat extend the rcu_read_lock/unnlock block to > include the call to sk_psock_tls_verdict_apply(). This will fix both > TLS redirect case and non-TLS redirect+error case. Also remove > psock from the sk_psock_tls_verdict_apply() function signature its > not used there. Acked-by: Martin KaFai Lau <kafai@xxxxxx>