lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <a1f091fc-727d-470a-835a-863501f28364@linux.alibaba.com>
Date: Wed, 8 Jan 2025 20:25:10 +0800
From: Philo Lu <lulie@...ux.alibaba.com>
To: Paolo Abeni <pabeni@...hat.com>, Eric Dumazet <edumazet@...gle.com>
Cc: netdev@...r.kernel.org, "David S. Miller" <davem@...emloft.net>,
 David Ahern <dsahern@...nel.org>, Jakub Kicinski <kuba@...nel.org>,
 Simon Horman <horms@...nel.org>, Fred Chen <fred.cc@...baba-inc.com>,
 Cambda Zhu <cambda@...ux.alibaba.com>, Willem de Bruijn
 <willemb@...gle.com>, Stefano Brivio <sbrivio@...hat.com>
Subject: Re: [PATCH net] udp: fix l4 hash after reconnect

Hi,

On 2025/1/7 15:56, Paolo Abeni wrote:
> Hi,
> 
> I'm sorry for the latency, I was off in the past days.
> 
> On 12/31/24 8:55 AM, Philo Lu wrote:
>> On 2024/12/10 16:32, Paolo Abeni wrote:
>>> On 12/7/24 03:34, Philo Lu wrote:
>>>> On 2024/12/7 00:23, Paolo Abeni wrote:
>>>>> On 12/6/24 17:01, Eric Dumazet wrote:
>>>>>> BTW, it seems that udp_lib_rehash() does the udp_rehash4()
>>>>>> only if the hash2 has changed.
>>>>>
>>>>> Oh, you are right, that requires a separate fix.
>>>>>
>>>>> @Philo: could you please have a look at that? basically you need to
>>>>> check separately for hash2 and hash4 changes.
>>>>
>>>> This is a good question. IIUC, the only affected case is when trying to
>>>> re-connect another remote address with the same local address
>>>
>>> AFAICS, there is also another case: when re-connection using a different
>>> local addresses with the same l2 hash...
>>>
>>>> (i.e.,
>>>> hash2 unchanged). And this will be handled by udp_lib_hash4(). So in
>>>> udp_lib_rehash() I put rehash4() inside hash2 checking, which means a
>>>> passive rehash4 following rehash2.
>>>
>>> ... but even the latter case should be covered from the above.
>>>
>>>> So I think it's more about the convention for rehash. We can choose the
>>>> better one.
>>>
>>> IIRC a related question raised during code review for the udp L4 hash
>>> patches. Perhaps refactoring the code slightly to let udp_rehash()
>>> really doing the re-hashing and udp_hash really doing only the hashing
>>> could be worth.
>>>
>>
>> I'm trying to unify rehash() for both hash2 and hash4 in
>> __ip4_datagram_connect, when I noticed the inet_rcv_saddr checking
>> before calling rehash():
>>
>> ```
>> if (!inet->inet_rcv_saddr) {
>> 	inet->inet_rcv_saddr = fl4->saddr;
>> 	if (sk->sk_prot->rehash)
>> 		sk->sk_prot->rehash(sk);
>> }
>> ```
>> This means inet_rcv_saddr is reset at most once no matter how many times
>> connect() is called.
> 
> ... if you make consecutive connect(<dst address>) calls.
> 
>   __udp_disconnect() clears saddr, so:
> 
> connect(<AF_UNSPEC>); connect(<dst address>);
> 
> will yield the expected result
> 
>> I'm not sure if this is by-design for some reason?
>> Or can I remove this checking? like:
>>
>> --- a/net/ipv4/datagram.c
>> +++ b/net/ipv4/datagram.c
>> @@ -67,11 +67,9 @@ int __ip4_datagram_connect(struct sock *sk, struct
>> sockaddr *uaddr, int addr_len
>>           inet->inet_dport = usin->sin_port;
>>           if (!inet->inet_saddr)
>>                   inet->inet_saddr = fl4->saddr;
>> -       if (!inet->inet_rcv_saddr) {
>> -               inet->inet_rcv_saddr = fl4->saddr;
>> -               if (sk->sk_prot->rehash)
>> -                       sk->sk_prot->rehash(sk);
>> -       }
>> +       inet->inet_rcv_saddr = fl4->saddr;
>> +       if (sk->sk_prot->rehash)
>> +               sk->sk_prot->rehash(sk);
>>           reuseport_has_conns_set(sk);
>>           sk->sk_state = TCP_ESTABLISHED;
>>           sk_set_txhash(sk);
> 
> This sounds like an unexpected behaviour change which may broke existing
> applications.
> 
> I suggest retaining the current beheviour.
> 

Thank you for your suggestion. I've sent a fix patch for rehash4 (with 
few build errors I'll solve soon), leaving __ip4_datagram_connect() 
unchanged.

-- 
Philo


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ