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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6677cfffbc25a_33363c294d@willemb.c.googlers.com.notmuch>
Date: Sun, 23 Jun 2024 03:34:23 -0400
From: Willem de Bruijn <willemdebruijn.kernel@...il.com>
To: Jakub Kicinski <kuba@...nel.org>, 
 davem@...emloft.net
Cc: netdev@...r.kernel.org, 
 edumazet@...gle.com, 
 pabeni@...hat.com, 
 willemdebruijn.kernel@...il.com, 
 ecree.xilinx@...il.com, 
 Jakub Kicinski <kuba@...nel.org>
Subject: Re: [PATCH net-next 1/4] selftests: drv-net: try to check if port is
 in use

Jakub Kicinski wrote:
> We use random ports for communication. As Willem predicted
> this leads to occasional failures. Try to check if port is
> already in use by opening a socket and binding to that port.
> 
> Signed-off-by: Jakub Kicinski <kuba@...nel.org>
> ---
>  tools/testing/selftests/net/lib/py/utils.py | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/selftests/net/lib/py/utils.py
> index 0540ea24921d..9fa9ec720c89 100644
> --- a/tools/testing/selftests/net/lib/py/utils.py
> +++ b/tools/testing/selftests/net/lib/py/utils.py
> @@ -3,6 +3,7 @@
>  import json as _json
>  import random
>  import re
> +import socket
>  import subprocess
>  import time
>  
> @@ -81,7 +82,17 @@ import time
>      """
>      Get unprivileged port, for now just random, one day we may decide to check if used.
>      """
> -    return random.randint(10000, 65535)
> +    while True:
> +        port = random.randint(10000, 65535)
> +        try:
> +            with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
> +                s.bind(("", port))
> +            with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s:
> +                s.bind(("", port))

Is the separate AF_INET needed? As AF_INET6 is not IPV6_V6ONLY.

The following correctly fails in the second bind

    with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s6:
      s6.bind(("", 8000))
      with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s4:
          s4.bind(("", 8000))


> +            return port
> +        except OSError as e:
> +            if e.errno != 98:  # already in use
> +                raise
>  
>  
>  def wait_port_listen(port, proto="tcp", ns=None, host=None, sleep=0.005, deadline=5):
> -- 
> 2.45.2
> 



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ