Skip to content
Memory corruption Write-up Advanced

CVE-2024-5535: SSL_select_next_proto buffer overread

A function in OpenSSL that selects a next protocol could be called with an empty client buffer, causing it to read past the buffer and return a pointer and length pointing at unrelated heap memory. When used in a client's NPN callback, this caused up to 255 bytes of the client's heap to be sent to the server inside the protocol negotiation extension.

jbp.io

Published on jbp.io

ctx = ssl.createdefaultcontext() ctx.setnpnprotocols([]) ctx.loadverifylocations('root.crt') sock = socket.createconnection(('127.0.0.1', 443)) sock = ctx.wrapsocket(sock, serverhostname='localhost') sock.write('hello')

Joe Birr-Pixton, on jbp.io

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the function did not check for a zero-length client buffer and unconditionally read the first byte and returned a pointer one past the start with an undefined length.

Impact

A client using NPN could leak up to 255 bytes of its heap to a server, though the data is encrypted in transit and NPN is rare on modern servers; server-side ALPN use is not affected because OpenSSL validates the extension as non-empty.

What the attacker needed

Server supports NPN; client uses NPN with an empty protocol list; affected OpenSSL, BoringSSL or LibreSSL build

The fix

The text says BoringSSL has already landed a fix and an OpenSSL advisory was released, but does not describe the code change itself.

How it was found

  1. Call the protocol selection function with an empty client buffer.
  2. Observe that it returns a pointer past the buffer and an undefined length.
  3. Use it in a client's NPN callback so the returned memory is copied into the negotiation extension.
  4. Connect to a server that supports NPN and observe heap bytes sent to the peer.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

OpenSSL is a widely used library that handles encrypted connections. A function meant to pick a protocol from a list was given an empty list, and instead of refusing it read memory beyond the list and reported a made-up length. The program then copied that much memory into a message sent to the other side, leaking whatever happened to be in memory.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.