On 10/23/23 14:35, Martin KaFai Lau wrote:
On 10/20/23 11:48 PM, Kuniyuki Iwashima wrote:
I think this was doable. With the diff below, I was able to skip
validation in cookie_v[46]_check() when if skb->sk is not NULL.
The kfunc allocates req and set req->syncookie to 1, which is usually
set in TX path, so if it's 1 in RX (inet_steal_sock()), we can see
that req is allocated by kfunc (at least, req->syncookie &&
req->rsk_listener never be true in the current TCP stack).
The difference here is that req allocated by kfunc holds refcnt of
rsk_listener (passing true to inet_reqsk_alloc()) to prevent freeing
the listener until req reaches cookie_v[46]_check().
The cookie_v[46]_check() holds the listener sk refcnt now?
The caller of cookie_v[46]_check() should hold a refcnt of the listener.
If the listener is destroyed, the callers of cookie_v[46]_check() should
fail to lookup a sock for the skb. However, in this case, the kfunc sets
a sock to skb->sk, and the lookup function
(__inet_lookup_skb()) steals sock from skb. So, there is no guarantee
ensuring the listener is still alive.
One solution is let the stealing function to lookup the listener if
inet_reqsk(skb->sk)->syncookie is true.