Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subsequent ssl:transport_accept() for the same IP stuck in dtls_packet_demux.erl call with infinity #6160

Closed
kuffel opened this issue Jul 20, 2022 · 6 comments · Fixed by #6649
Assignees
Labels
bug Issue is reported as a bug stalled waiting for input by the Erlang/OTP team team:PS Assigned to OTP team PS

Comments

@kuffel
Copy link

kuffel commented Jul 20, 2022

Starting with Erlang 24.3.3 we observe issues with DTLS ssl transport_accept for clients that have been connected before.

To Reproduce

We are using the following options to create a new listen socket and wait for clients:

ssl_opts = [
  active: false,
  reuseaddr: true,
  protocol: :dtls,
  versions: [:"dtlsv1.2"],
  ciphers: [
    %{key_exchange: :psk, cipher: :aes_256_cbc, mac: :sha, prf: :default_prf},
    %{key_exchange: :psk, cipher: :aes_128_cbc, mac: :sha256, prf: :default_prf},
    %{key_exchange: :psk, cipher: :aes_128_cbc, mac: :sha, prf: :default_prf}
  ],
  user_lookup_fun: {fn(:psk, psk_identity, _user_state) -> {:ok, Base.decode16!(psk_identity)} end, '3014F7B6E400090000001234'},
  log_level: :debug,
  # log_alert: true,
  ip: {0, 0, 0, 0, 0, 0, 0, 1}
]
:ssl.start()
{:ok, listen_socket} = :ssl.listen(20_127, ssl_opts)
{:ok, session_socket_1} = :ssl.transport_accept(listen_socket)
{:ok, session_socket_1} = :ssl.handshake(session_socket_1, [], 5_000)

Using OpenSSL s_client we can now connect to the socket and see a successful handshake:

openssl s_client -bind [::1]:10127 -connect [::1]:20127 -dtls1_2 -psk_identity 3014F7B6E400090000001234 -psk 3014F7B6E400090000001234 -6 -cipher PSK-AES256-CBC-SHA

After closing the client we want to accept the next client by doing:

{:ok, session_socket_2} = :ssl.transport_accept(listen_socket)
{:ok, session_socket_2} = :ssl.handshake(session_socket_2, [], 5_000)

If we repeat the openssl command we can see the client requesting another handshake but the application is stuck in transport_accept.

Expected behavior
Subsequent ssl:transport_accept() calls do not block and return a new session socket.

Affected versions
Erlang 24.3.3 and higher

@kuffel kuffel added the bug Issue is reported as a bug label Jul 20, 2022
@IngelaAndin IngelaAndin added the team:PS Assigned to OTP team PS label Jul 25, 2022
@IngelaAndin
Copy link
Contributor

Hmm ... Did you upgrade from OTP 24.3.1 or was the jump to 24.3.3 larger? Just to make sure as the only change between those versions seems unlikely to affect this.

@IngelaAndin IngelaAndin added the waiting waiting for changes/input from author label Aug 9, 2022
@kuffel
Copy link
Author

kuffel commented Aug 10, 2022

The jump was from 24.1.2. to 24.3.3

@IngelaAndin
Copy link
Contributor

Then I would say the bug was most likely introduced in OTP.24.2. We will look into it further.

@dgud
Copy link
Contributor

dgud commented Aug 22, 2022

Hmm this works for me in OTP-25.0, when closing the socket with ^D in openssl,
how do you close it?

Also for dlts you should probably set {recbuf, 32768} or more to ensure the packets is not discarded by the OS.

@kuffel
Copy link
Author

kuffel commented Aug 22, 2022

I closed openssl (Version 1.1.1k 25 Mar 2021) using ^C.
Thanks for the hint with the recbuf.

@dgud
Copy link
Contributor

dgud commented Aug 23, 2022

Yes it seems I broke this when I tried to fix it and misunderstood how this should work :-/
It will take some time until I have time to prioritize this and get it correct.

See #4393 so it didn't seem to work for everybody previously either, and it could be attacked
by a forged "clienthello" as in Also see RFC

@IngelaAndin IngelaAndin added stalled waiting for input by the Erlang/OTP team and removed waiting waiting for changes/input from author labels Aug 24, 2022
dgud added a commit that referenced this issue Jan 17, 2023
…nto maint

* dgud/ssl/dtls-multiple-connections/GH-6160/OTP-18371:
  ssl: dtls let new accept process handle new connections
  Refactor, remove client set
  Fix version test
@dgud dgud closed this as completed Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug stalled waiting for input by the Erlang/OTP team team:PS Assigned to OTP team PS
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants