Am I affected?

This record states its affected versions in a form that can't be compared automatically.

≥ 1.0.0 < 2.5.4 affected
every other version: unaffected

Description

Loop with Unreachable Exit Condition ('Infinite Loop') vulnerability in device certificate verification in nerves-hub nerves_hub_web allows an unauthenticated remote attacker to cause a denial of service via a TLS client certificate whose CA is not registered. When a client certificate chains to a root in the device endpoint's trust store but no CA in the chain is registered in NervesHub, NervesHub.SSL.decide/2 refuses it with the reason :unknown_ca. Erlang/OTP ssl reads that reason as a missing trust anchor, looks for an alternative root, finds the same root and validates again without end. The handshake process queries the database on each pass and keeps running after the client disconnects, until the node restarts.

The device endpoint trusts the public roots from CAStore unless DEVICE_SSL_CACERTFILE is set, so a client certificate from a public CA whose chain allows client authentication is sufficient. A chain that ends at a root outside the trust store is refused once.

This issue affects nerves_hub: from 1.0.0 before 2.5.4.

Technical analysis

1. Refusal reason. The device endpoint gives ssl the verify function NervesHub.DeviceLink.PeerVerification.verify_fun/3, which asks NervesHub.SSL.decide/2. For a :valid_peer event on a certificate that is not on file, decide/2 tries to register the certificate. check_known_ca/1 in lib/nerves_hub/ssl.ex looks for the signer among the registered CAs and returns :unknown_ca when it finds none. do_verify/2 passes that to ssl as {:fail, :unknown_ca}.

2. Retry in ssl. unknown_ca is also the reason Erlang/OTP uses for a path with no trust anchor. In ssl_handshake:path_validate/11, a {bad_cert, unknown_ca} result makes ssl look for a cross-signed alternative root and validate again. Unlike the root_cert_expired branch, this branch does not add the root it tried to the list of roots to skip.

3. Loop. When the chain ends at a self-signed root in the trust store, ssl finds the same root, calls the verify function again, and receives unknown_ca again. The recursion is a tail call, so the process does not grow or crash. It does not return to its mailbox, so it sees neither the handshake timeout nor the closed socket. Each pass runs the database queries of the registration checks.

Proof of concept

  1. Make a self-signed root and a client certificate signed by it, directly or through an intermediate that the client sends. Do not register either CA in NervesHub.
  2. Run a device endpoint whose trust store holds that root, by adding it to the DEVICE_SSL_CACERTFILE bundle. Against the default trust store, a client certificate from a public CA replaces steps 1 and 2.
  3. Open one TLS connection to the device endpoint with that certificate, then disconnect.
  4. The handshake process on the server keeps running. The nerves_hub.ssl.fail telemetry event with reason unknown_ca and the database queries repeat until the node restarts.

Weaknesses & attack patterns

Weakness

CWE-835 · Loop with Unreachable Exit Condition in catalog → MITRE ↗

Attack patterns

CAPEC-227 · Sustained Client Engagement MITRE ↗

An unauthenticated client can leave a handshake process on a device node running and querying the database after it disconnects. Each further connection adds another such process, and they stop only when the node restarts. Devices and users of the instance lose service while the nodes and the database are saturated.

Affected — ghcr.io / nerves-hub

≥ 1.0.0 < 2.5.4 affected
every other version: unaffected
cpe cpe:2.3:a:nerves-hub:nerves_hub_web:*:*:*:*:*:*:*:*
version type other
modules · source files · routines
modules 'Elixir.NervesHub.SSL' · 'Elixir.NervesHub.DeviceLink.PeerVerification'
source files lib/nerves_hub/ssl.ex · lib/nerves_hub/device_link/peer_verification.ex
routines 'Elixir.NervesHub.SSL':decide/2 · 'Elixir.NervesHub.SSL':verify_fun/3 · 'Elixir.NervesHub.DeviceLink.PeerVerification':verify_fun/3

Affected — Nerves Hub Repository ↗

≥ 1.0.0 < 2.5.4 affected
every other version: unaffected
cpe cpe:2.3:a:nerves-hub:nerves_hub_web:*:*:*:*:*:*:*:*
version type semver
modules · source files · routines
modules 'Elixir.NervesHub.SSL' · 'Elixir.NervesHub.DeviceLink.PeerVerification'
source files lib/nerves_hub/ssl.ex · lib/nerves_hub/device_link/peer_verification.ex
routines 'Elixir.NervesHub.SSL':decide/2 · 'Elixir.NervesHub.SSL':verify_fun/3 · 'Elixir.NervesHub.DeviceLink.PeerVerification':verify_fun/3

Affected — GitHub / nerves-hub/nerves_hub_web Repository ↗

≥ a49fb88 < 064e78c affected
every other version: unaffected
cpe cpe:2.3:a:nerves-hub:nerves_hub_web:*:*:*:*:*:*:*:*
version type git
modules · source files · routines
modules 'Elixir.NervesHub.SSL' · 'Elixir.NervesHub.DeviceLink.PeerVerification'
source files lib/nerves_hub/ssl.ex · lib/nerves_hub/device_link/peer_verification.ex
routines 'Elixir.NervesHub.SSL':decide/2 · 'Elixir.NervesHub.SSL':verify_fun/3 · 'Elixir.NervesHub.DeviceLink.PeerVerification':verify_fun/3

Workarounds

Set DEVICE_SSL_CACERTFILE to a bundle that holds no public root and no root that signs device certificates, for example a file with one self-signed certificate made for this purpose. A certificate from an unregistered CA is then refused once and the handshake ends. Devices whose certificate or CA is registered in NervesHub continue to connect.

Restarting a node ends the handshakes that are already stuck on it.

Configurations

The certificate chain must end at a root in the device endpoint's trust store. With DEVICE_SSL_CACERTFILE unset, which is the default from 2.0.0, the trust store holds the public roots from CAStore. With DEVICE_SSL_CACERTFILE set to a bundle that holds a root which signs device certificates, any certificate from that root whose CA is not registered is sufficient, including the certificate of a deleted device.

The retry in Erlang/OTP ssl was confirmed on Erlang/OTP 28.3, 29.0 and 29.1. Earlier releases were not checked.

References

Credits

deasthamgp Finder Reporter
Josh Kalderimis Remediation developer
Jonatan Männchen / EEF Coordinator

CVSS breakdown

CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N
« All CVEs