nasa / nasa/CryptoLib

🐛 [BUG] - Implementation Standard - Unrecognized SA-Management PID Silently Returns Success

Open Beginner friendly
#535 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C
Stars
169
Forks
67
PR merge metrics
No merged PRs in 30d

Description

Description

Bug Report: Unrecognized SA-Management PID Silently Returns Success

Summary

Field Value
Product NASA CryptoLib (SDLS Protocol Implementation)
Version 1.4.2
Component src/core/crypto.cCrypto_SG_SA_MGMT
Issue The SA-management command dispatcher's default: case for an unrecognized Procedure Identification Field (PID) never sets an error status, so the function returns CRYPTO_LIB_SUCCESS from its initialized value
Bug Type Conformance
Severity Low-Medium
Impact A malformed or unsupported SA-management command is silently accepted rather than rejected — a ground segment sending a PID CryptoLib doesn't implement gets no indication the command was not processed

Description

Crypto_SG_SA_MGMT dispatches an incoming SA-management command by its pid field to one of
the PID_CREATE_SA/PID_SA_STATUS/etc. handlers. status is initialized to
CRYPTO_LIB_SUCCESS at function entry. The switch's default: case, reached for any pid
value outside the defined set, prints a debug diagnostic and breaks — it never assigns
status anything else — so the function returns success for a PDU it explicitly could not
interpret.

Affected Code

Crypto_SG_SA_MGMT (src/core/crypto.c:629-700)
int32_t Crypto_SG_SA_MGMT(uint8_t *ingest, TC_t *tc_frame)
{
    int status = CRYPTO_LIB_SUCCESS;
    switch (sdls_frame.tlv_pdu.hdr.pid)
    {
        case PID_CREATE_SA:
            status = sa_if->sa_create(tc_frame);
            break;
        // ... PID_DELETE_SA, PID_SETARSNW, PID_REKEY_SA, PID_EXPIRE_SA,
        //     PID_SETARSN, PID_START_SA, PID_STOP_SA, PID_READ_ARSN, PID_SA_STATUS ...
        default:
#ifdef PDU_DEBUG
            printf(KRED "Error: Crypto_PDU failed interpreting SA Procedure Identification Field! \n" RESET);
#endif
            break;   // status never set — still CRYPTO_LIB_SUCCESS from initialization
    }
    return status;
}

Reproduction Sequence (from the fuzzing logs)

Replaying the full multi-packet mismatch pcap (crypto_triage, -DDEBUG=ON); only the final
frame is needed to trigger the bug (the dispatch is stateless with respect to pid — earlier
frames just exercise other unrelated SA-management commands in the same fuzzer-generated
sequence):

# Direction Hex Meaning
8 ground → flight 002c100c0000000098cf70e150 TC frame, sg=0x1, pid=0x8 — not one of the defined PID_* values for the SA-management service group

Debug replay of that frame:

TLV PDU
	 sg         = 0x1
	 pid        = 0x8
	 pdu_len    = 0xcf70
	 data[0]    = 0x00

Error: Crypto_PDU failed interpreting SA Procedure Identification Field!
Status code: 0

CryptoLib prints its own diagnostic confirming it could not interpret the PID, then returns
Status code: 0 (success) anyway.

Suggested Fix

Assign a real error code in the default: branch instead of leaving status at its initialized
success value:

default:
#ifdef PDU_DEBUG
    printf(KRED "Error: Crypto_PDU failed interpreting SA Procedure Identification Field! \n" RESET);
#endif
    status = CRYPTO_LIB_ERROR;  // or a more specific "unrecognized PID" code
    break;

Worth checking whether the sibling dispatch functions for the other service groups (Key
Management, Monitoring & Control) have the same default:-falls-through-to-success shape, since
this looks like a copy-pasted dispatch pattern rather than something unique to SA management.


Discovered using the StratoFuzz protocol fuzzing framework.

Branch Name

dev

Reproduction steps
## Reproduction Sequence (from the fuzzing logs)

Replaying the full multi-packet mismatch pcap (`crypto_triage`, `-DDEBUG=ON`); only the final
frame is needed to trigger the bug (the dispatch is stateless with respect to `pid` — earlier
frames just exercise other unrelated SA-management commands in the same fuzzer-generated
sequence):

| # | Direction | Hex | Meaning |
|---|-----------|-----|---------|
| 8 | ground → flight | `002c100c0000000098cf70e150` | TC frame, `sg=0x1, pid=0x8` — not one of the defined `PID_*` values for the SA-management service group |

Debug replay of that frame:


TLV PDU
	 sg         = 0x1
	 pid        = 0x8
	 pdu_len    = 0xcf70
	 data[0]    = 0x00

Error: Crypto_PDU failed interpreting SA Procedure Identification Field!
Status code: 0


CryptoLib prints its own diagnostic confirming it could not interpret the PID, then returns
`Status code: 0` (success) anyway.
Screenshots

Logs

OS

Linux

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/core/crypto.c at Crypto_SG_SA_MGMT around lines 629-700 and trace the PID switch, then replay the provided pid=0x8 frame to confirm the current success status. Update the unrecognized-PID path so it returns an error, and verify that the diagnostic remains correct and the replay no longer reports status 0. Check sibling service-group dispatchers only if time permits.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
security
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
84/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.