Back to skill

Security audit

misra-automotive-c

Security checks for vulnerabilities and agentic risk

Overview

The skill has no executable payload, but its broad activation and unsafe or overstated safety-critical C guidance warrant human review before use.

Review this skill before installing if you use it for real automotive or embedded work. It should not be treated as a certified MISRA checker or a source of production-ready safety code; verify generated fixes with qualified static analysis, platform documentation, and human safety review, and consider narrowing its trigger phrases.

Vulnerability Patterns
  • Insecure Skill Coding PracticesFinds exploitable flaws such as hardcoded secrets or command injection
  • Skill Instruction HijackingAlters the agent's session goals or safety constraints when the skill loads
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
  • Embedded Malicious CodeShips malicious scripts inside the skill and executes them locally
Findings (2)

T09 · Insecure Skill Coding Practices

Error
Location
memory-embedded.md:193
Finding

Unsafe CAN DLC Handling Can Cause Out-of-Bounds Writes and Undefined Shifts

Content
View full analysis

Vulnerability Details

File Location: memory-embedded.md, lines 193–201
Vulnerability Type: Unsafe bounds handling in a safety-critical code-generation template
Risk Level: High

Vulnerable Code:

c
uint32_t raw_dlc = CAN1_sFIFOMailBox[0].RDTR & 0x0Fu;

/* 2. Copy data to shared volatile buffer */
uint8_t i;
for (i = 0u; i < (uint8_t)raw_dlc; i++) {
    g_can_rx_buf[i] = (uint8_t)(CAN1_sFIFOMailBox[0].RDLR >> (i * 8u));
}
g_can_rx_id      = raw_id >> 21u;    /* extract CAN ID */
g_can_rx_dlc     = (uint8_t)raw_dlc;

Technical Analysis

The code masks the received data-length code to four bits but does not validate it against the CAN payload limit, the size of g_can_rx_buf, or the number of bytes available in the RDLR register.

Consequently, a DLC greater than the destination capacity can make the loop write beyond g_can_rx_buf. In addition, RDLR is a 32-bit value. When i reaches 4, the expression i * 8u produces a shift count of 32. Shifting a 32-bit value by 32 or more is undefined behavior in C. The example also reads only RDLR, so it cannot correctly retrieve bytes beyond the first four.

Because this appears under the prescriptive “Do in ISRs” section, an Agent may reproduce it in generated automotive code and incorrectly present it as a safe embedded pattern.

Attack Path

  1. The template is adopted in a CAN receive interrupt handler.
  2. A malformed frame, corrupted peripheral state, or unsupported DLC value produces a value above the valid payload or buffer limit.
  3. The loop processes the unvalidated DLC.
  4. For sufficiently large values, it writes past g_can_rx_buf.
  5. At i >= 4, it also performs an invalid shift of at least 32 bits.
  6. The resulting memory corruption or undefined behavior may alter adjacent state, trigger a fault, or disrupt ECU control flow.

Impact Assessment

The issue does not grant operating-system privileges by itself. I ...[truncated 473 chars]

Remediation
View remediation

Remediation Suggestions

  • Validate the DLC before entering the copy loop.
  • Bound the effective length by the protocol maximum and sizeof(g_can_rx_buf).
  • Reject invalid DLC values and record a communication fault rather than silently truncating safety-relevant input.
  • Read bytes 0–3 from RDLR and bytes 4–7 from the corresponding high-data register.
  • Ensure every shift count is strictly less than the width of the shifted operand.
  • Prefer a documented hardware-abstraction-layer receive API where available.
  • Add static-analysis checks and tests for DLC values 0, 4, 8, and every invalid value.

A safe pattern should first validate the length:

c
uint32_t raw_dlc = CAN1_sFIFOMailBox[0].RDTR & 0x0Fu;
uint8_t dlc = 0u;

if (raw_dlc <= 8u) {
    dlc = (uint8_t)raw_dlc;
} else {
    report_error(ERR_CAN_INVALID_DLC);
}

if (dlc <= (uint8_t)sizeof(g_can_rx_buf)) {
    /* Copy from both low and high data registers with shifts below 32. */
} else {
    report_error(ERR_CAN_RX_BUFFER_TOO_SMALL);
}

T09 · Insecure Skill Coding Practices

Error
Location
memory-embedded.md:226
Finding

Critical-Section Template Unconditionally Re-Enables Interrupts

Content
View full analysis

Vulnerability Details

File Location: memory-embedded.md, lines 226–231
Vulnerability Type: Incorrect restoration of processor interrupt state
Risk Level: High

Vulnerable Code:

c
uint32_t safe_read_tick(void) {
    uint32_t tick;
    __disable_irq();          /* enter critical section */
    tick = g_system_tick_ms;  /* atomic read */
    __enable_irq();           /* exit critical section */
    return tick;
}

Technical Analysis

The function disables interrupts and then unconditionally enables them. It does not save and restore the processor’s prior interrupt-mask state.

If the function is called while interrupts are already disabled, including from a larger critical section or interrupt-sensitive initialization path, it enables interrupts earlier than the caller intended. This breaks nesting semantics and can expose data that the caller still considers protected.

The problem is particularly significant because the snippet is presented as a “Critical Section Pattern,” making it likely to be reused by an Agent when generating safety-critical firmware.

Attack Path

  1. A caller disables interrupts before updating a group of related shared objects.
  2. During that protected operation, the caller invokes safe_read_tick.
  3. safe_read_tick executes __disable_irq(), although interrupts are already disabled.
  4. It then executes __enable_irq() instead of restoring the previous mask.
  5. An interrupt occurs before the outer critical operation is complete.
  6. The interrupt observes partially updated state or modifies shared data concurrently, violating synchronization assumptions.

Impact Assessment

No additional operating-system privilege is acquired; the impact occurs within the firmware’s existing execution privilege. The affected scope includes any caller that relies on nested critical sections or invokes the helper while interrupts are already masked.

Potential c ...[truncated 258 chars]

Remediation
View remediation

Remediation Suggestions

  • Save the architecture-specific interrupt-mask state before disabling interrupts.
  • Restore the exact saved state rather than unconditionally enabling interrupts.
  • Prefer the target platform or RTOS’s nesting-aware critical-section API.
  • Document whether the helper is legal in thread mode, handler mode, and already-masked contexts.
  • Where aligned 32-bit reads are naturally atomic on the target architecture, avoid unnecessary interrupt masking, subject to the memory model and device requirements.
  • Add tests that invoke the helper both with interrupts enabled and already disabled.

An architecture-specific pattern should resemble:

c
uint32_t safe_read_tick(void) {
    uint32_t tick;
    uint32_t saved_mask = __get_PRIMASK();

    __disable_irq();
    tick = g_system_tick_ms;
    __set_PRIMASK(saved_mask);

    return tick;
}

The exact register and intrinsic must be selected for the target architecture and verified against the compiler and RTOS documentation.

Vulnerability Patterns
  • Excessive AgencyUnrestricted Tool Access, Autonomous Decision Making, Scope Creep
  • Trigger AbuseOverly Broad Trigger, Shadow Command Trigger, Keyword Baiting Trigger
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
Findings (14)

Vague Triggers

High
Category
Not specified by scanner
Confidence
97% confidence
Finding

The trigger list includes broad terms such as 'asil' and 'iso 26262', and the README also says the agent will offer a review when C code is merely pasted. This can cause accidental activation during ordinary safety or standards discussions, leading the skill to intercept unrelated prompts and produce unsolicited code-review behavior in contexts where the user did not intend to invoke it.

Content

No source excerpt is available for this finding.

Ae1

High
Category
analysis-evasion
Confidence
100% confidence
Finding

Referenced artifact was not completely inspected

Content

Scanner excerpt · SKILL.md (reported line 33)May include surrounding context.

md
| `misra-mandatory.md` | Mandatory rules — never violate, no deviation allowed |

Ae1

High
Category
analysis-evasion
Confidence
100% confidence
Finding

Referenced artifact was not completely inspected

Content

Scanner excerpt · SKILL.md (reported line 59)May include surrounding context.

md
| `misra-mandatory.md` | Mandatory rules — never violate, no deviation allowed |

Description-Behavior Mismatch

High
Category
Not specified by scanner
Confidence
97% confidence
Finding

The skill metadata claims capabilities such as flagging violations with ASIL classification and providing replacements for every non-compliant line, but the file only contains generic static guidance. This mismatch can mislead users into overtrusting the skill's coverage and precision, causing unsafe compliance decisions in an automotive context where incomplete analysis may leave real defects unreviewed.

Content

No source excerpt is available for this finding.

Vague Triggers

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

Several triggers such as 'review my c code', 'embedded c review', and 'asil' are broad enough to activate on requests that are not specifically about MISRA analysis. Unintended activation can route unrelated coding tasks into this skill, increasing the chance of overreach, unexpected code generation, or inappropriate safety-labeled guidance.

Content

No source excerpt is available for this finding.

Description-Behavior Mismatch

Medium
Category
Not specified by scanner
Confidence
96% confidence
Finding

The manifest presents the skill as a code review tool, but the body also authorizes generation of new embedded C code. This scope expansion can cause the agent to perform higher-risk actions than users or orchestrators expect, weakening policy controls that may permit review but not code authoring.

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Medium
Category
Not specified by scanner
Confidence
82% confidence
Finding

At L008-L010, the text states 'goto is absolutely forbidden. No exceptions, no deviations.' However, the same document later discusses raising deviations for intentional fall-through, showing that the skill documentation is willing to frame MISRA findings in terms of deviation handling rather than absolute impossibility. This creates an intent-level contradiction in the documentation about how MISRA compliance is to be interpreted.

Content

No source excerpt is available for this finding.

Unbounded Resource Access

Medium
Category
Excessive Agency
Confidence
75% confidence
Finding

Skill allows unbounded resource consumption (API calls, storage, compute). Without rate limits or quotas, a compromised or misbehaving agent can cause denial-of-service or cost overruns.

Content

Scanner excerpt · memory-embedded.md (reported line 122)May include surrounding context.

/* In main: / while (!done) { } / compiler may hoist done into register and loop forever even after ISR fires */

text
Compliant:
```c

Description-Behavior Mismatch

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The manifest describes a skill that reviews Embedded C code against MISRA C:2012, flags violations with rule numbers and ASIL classifications, and provides replacements for every non-compliant line. This file is only a static markdown reference of selected MISRA rules and examples, with no executable analysis logic, no ASIL mapping mechanism, and no per-line remediation generation for user-supplied code.

Content

No source excerpt is available for this finding.

Description-Behavior Mismatch

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The document states absolute rules like never using core C integer types for numeric data and always using fixed-width typedefs, which overstates MISRA C:2012 and can cause the agent to generate incorrect review results and non-authoritative remediation. In a safety-critical automotive coding skill, inaccurate normative claims are dangerous because users may trust them as compliance requirements and apply bad transformations broadly.

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Medium
Category
Not specified by scanner
Confidence
97% confidence
Finding

The Rule 10.6 example asserts multiplication is performed in uint16_t and may overflow there, which contradicts standard integer promotion semantics in the shown code. A skill that teaches incorrect language semantics can misdiagnose defects and suggest unnecessary or wrong fixes, especially harmful in embedded automotive review workflows where developers rely on precise type reasoning.

Content

No source excerpt is available for this finding.

Description-Behavior Mismatch

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

The section claims explicit casts are universally required and presents silent conversions as categorically non-compliant, which misrepresents MISRA's intent and can encourage cast insertion as a blanket fix. In practice, unnecessary casts can hide type issues, suppress diagnostics, and produce replacements that are less compliant or less safe than the original code.

Content

No source excerpt is available for this finding.

Description-Behavior Mismatch

Low
Category
Not specified by scanner
Confidence
86% confidence
Finding

The skill promises line-level compliant replacements during review, but the documentation broadens into general code authoring behavior. Even if framed as MISRA-compliant output, this can be used to elicit substantial code synthesis beyond the narrowly declared review/remediation role.

Content

No source excerpt is available for this finding.

Description-Behavior Mismatch

Low
Category
Not specified by scanner
Confidence
88% confidence
Finding

The enum example references an undeclared enumerator and promotes cast-based integer-to-enum conversion as a general pattern, which can lead the agent to emit incorrect or weakly justified fixes. In a compliance-review skill, even low-level inaccuracies reduce trust and may normalize unsafe conversion practices when handling externally supplied values.

Content

No source excerpt is available for this finding.

Static analysis

No suspicious patterns detected.