[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <9aebb3e9-70c5-428c-bc31-7b38a04e4848@gmail.com>
Date: Mon, 23 Oct 2023 17:37:26 -0700
From: Kui-Feng Lee <sinquersw@...il.com>
To: Martin KaFai Lau <martin.lau@...ux.dev>,
Kuniyuki Iwashima <kuniyu@...zon.com>
Cc: andrii@...nel.org, ast@...nel.org, bpf@...r.kernel.org,
daniel@...earbox.net, davem@...emloft.net, dsahern@...nel.org,
edumazet@...gle.com, haoluo@...gle.com, john.fastabend@...il.com,
jolsa@...nel.org, kpsingh@...nel.org, kuba@...nel.org, kuni1840@...il.com,
mykolal@...com, netdev@...r.kernel.org, pabeni@...hat.com, sdf@...gle.com,
song@...nel.org, yonghong.song@...ux.dev
Subject: Re: [PATCH v1 bpf-next 00/11] bpf: tcp: Add SYN Cookie
generation/validation SOCK_OPS hooks.
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.
Powered by blists - more mailing lists