This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
securitycritical PriorityID: cilium-ebpf-tail-call-context-preservation-standard

Cilium eBPF Host-Routing Tail-Call sk_buff Context Preservation and Telemetry Invariant

Enforces strict control buffer (cb[]) alignment and security identity preservation across eBPF BPF-to-BPF tail calls in Cilium host-routing and L7 proxy redirect paths. Eliminates policy bypass and silent packet drops caused by unanchored skb metadata shifts and unhandled tail-call dispatch exhaustion. Ensures full telemetry synchronization and verifier-compliant pointer re-validation across execution boundaries.

Prohibited Anti-Pattern: Unchecked Control Buffer Mutation and Silent Fallthrough During Tail-Call Failure

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Cilium eBPF Host-Routing Tail-Call sk_buff Context Preservation and Telemetry Invariant - Enforces strict control buffer (cb[]) alignment and security identity preservation across eBPF BPF-to-BPF tail calls in Cilium host-routing and L7 proxy redirect paths. Eliminates policy bypass and silent packet drops caused by unanchored skb metadata shifts and unhandled tail-call dispatch exhaustion. Ensures full telemetry synchronization and verifier-compliant pointer re-validation across execution boundaries.
globs: bpf/**/*.c, bpf/**/*.h, pkg/datapath/**/*.go
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/cilium-ebpf-tail-call-context-preservation-standard"
---

# Cilium eBPF Host-Routing Tail-Call sk_buff Context Preservation and Telemetry Invariant

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Unchecked Control Buffer Mutation and Silent Fallthrough During Tail-Call Failure

## System Constraints
You are a Principal Software Architect enforcing the Cilium eBPF Host-Routing Tail-Call Context Preservation Standard. You must mandate strict preservation of sk_buff control buffer metadata (cb[]), explicit tail-call failure handling, and immediate packet re-validation following L7 filter transitions.

## Strict Guidelines
- Engineers MUST ALWAYS persist and re-anchor security identity (src_id/dst_id) and packet marks in struct __sk_buff cb[] prior to dispatching any bpf_tail_call.
- Engineers MUST NOT allow silent fallthrough after a bpf_tail_call() invocation; tail calls that exceed execution limits or target missing indices MUST explicitly emit a drop telemetry event and return TC_ACT_SHOT.
- Code SHOULD re-validate all pointer offsets (ctx->data and ctx->data_end) immediately at the entry point of any tail-called program to comply with eBPF verifier memory boundaries.
- Services MUST ensure that L7 proxy redirect flags (CB_PROXY_MAGIC) are not overwritten or zeroed out during intermediate L3/L4 routing stages.
- Components NEVER execute raw skb reallocation or headroom adjustments across tail-call chains without realigning the embedded security context.

## Bad vs Good Implementations
### Preserving sk_buff Context and Emitting Telemetry on Tail-Call Depletion

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Zeroing skb->cb destroys downstream security identities (secctx) and L7 redirect metadata. Furthermore, failing to handle tail-call fallthrough silently permits uninspected packets to traverse the stack with invalid or dropped context, creating critical security bypass vulnerabilities.
```c
SEC("tc/l4_redirect")
int l4_policy_redirect(struct __sk_buff *skb) {
    // ANTI-PATTERN: Blind tail call without preserving security metadata in cb[]
    // and silent fallthrough if tail-call index is missing or limit (33) reached.
    int target_prog = CILIUM_CALL_IPV4_NODEPORT;

    // Blindly clearing control buffer without preserving identity
    __builtin_memset(&skb->cb, 0, sizeof(skb->cb));

    // Executing tail call with zero fallback enforcement
    tail_call_dynamic(skb, &cilium_calls, target_prog);

    // Silent fallthrough allows uninspected packet traversal (telemetry bypass)
    return TC_ACT_OK;
}
```

#### Production Standard (Correct)
> **Standard**: Explicitly preserves security identity and policy routing magic inside the control buffer across tail-call boundaries, and guarantees that any failed tail call (e.g., call depth limit exhaustion or invalid program index) emits an auditable drop notification and immediately drops the packet via TC_ACT_SHOT.
```c
SEC("tc/l4_redirect")
int l4_policy_redirect(struct __sk_buff *skb) {
    // SECURE: Preserve required telemetry and policy state in cb struct
    struct cilium_ctx_cb *cb = (struct cilium_ctx_cb *)&skb->cb;
    __u32 sec_id = cb->sec_label;
    __u32 magic = cb->magic;

    // Re-anchor context specifically required across tail-call boundary
    cb->sec_label = sec_id;
    cb->magic = magic | MARK_MAGIC_HOST;

    // Execute tail call
    tail_call_dynamic(skb, &cilium_calls, CILIUM_CALL_IPV4_NODEPORT);

    // INVARIANT: Explicit drop and telemetry emission on tail-call exhaustion
    send_drop_notify_error(skb, sec_id, DROP_MISSED_TAIL_CALL, TC_ACT_SHOT);
    return TC_ACT_SHOT;
}
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Cilium eBPF Host-Routing Tail-Call sk_buff Context Preservation and Telemetry Invariant

Cilium eBPF Host-Routing Tail-Call sk_buff Context Preservation and Telemetry Invariant defines an industrial-grade behavioral standard for security engineering. Enforces strict control buffer (cb[]) alignment and security identity preservation across eBPF BPF-to-BPF tail calls in Cilium host-routing and L7 proxy redirect paths. Eliminates policy bypass and silent packet drops caused by unanchored skb metadata shifts and unhandled tail-call dispatch exhaustion. Ensures full telemetry synchronization and verifier-compliant pointer re-validation across execution boundaries. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Unchecked Control Buffer Mutation and Silent Fallthrough During Tail-Call Failure Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftUnchecked Control Buffer Mutation and Silent Fallthrough During Tail-Call FailureCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS persist and re-anchor security identity (src_id/dst_id) and packet marks in struct __sk_buff cb[] prior to dispatching any bpf_tail_call.

Engineers MUST ALWAYS persist and re-anchor security identity (src_id/dst_id) and packet marks in struct __sk_buff cb[] prior to dispatching any bpf_tail_call.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST NOT allow silent fallthrough after a bpf_tail_call() invocation

Engineers MUST NOT allow silent fallthrough after a bpf_tail_call() invocation; tail calls that exceed execution limits or target missing indices MUST explicitly emit a drop telemetry event and return TC_ACT_SHOT.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Code SHOULD re-validate all pointer offsets (ctx->data and ctx->data_end) immediately at the entry point of any tail-called program to comply with eBPF verifier memory boundaries.

Code SHOULD re-validate all pointer offsets (ctx->data and ctx->data_end) immediately at the entry point of any tail-called program to comply with eBPF verifier memory boundaries.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Services MUST ensure that L7 proxy redirect flags (CB_PROXY_MAGIC) are not overwritten or zeroed out during intermediate L3/L4 routing stages.

Services MUST ensure that L7 proxy redirect flags (CB_PROXY_MAGIC) are not overwritten or zeroed out during intermediate L3/L4 routing stages.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Components NEVER execute raw skb reallocation or headroom adjustments across tail-call chains without realigning the embedded security context.

Components NEVER execute raw skb reallocation or headroom adjustments across tail-call chains without realigning the embedded security context.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Cilium eBPF Host-Routing Tail-Call sk_buff Context Preservation and Telemetry Invariant critical for AI coding assistants?

Enforces strict control buffer (cb[]) alignment and security identity preservation across eBPF BPF-to-BPF tail calls in Cilium host-routing and L7 proxy redirect paths. Eliminates policy bypass and silent packet drops caused by unanchored skb metadata shifts and unhandled tail-call dispatch exhaustion. Ensures full telemetry synchronization and verifier-compliant pointer re-validation across execution boundaries. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Unchecked Control Buffer Mutation and Silent Fallthrough During Tail-Call Failure) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

1 Rule in Stack

Cilium