This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
securitycritical PriorityID: ebpf-lsm-bprm-exec-lockdown-guardrail

eBPF LSM bprm_creds_for_exec Ephemeral Binary Lockdown

Intercepts kernel bprm_creds_for_exec hooks via eBPF Linux Security Modules (LSM) to enforce immutable execution boundaries within zero-trust distroless containers. Prevents post-exploitation arbitrary binary execution, fileless payload spawning via memfd_create, and runtime process drift by enforcing cryptographic hash verification or strict cgroup-pinned execution allowlists in ring 0. Enforces immediate kernel-level denial with -EPERM and zero-allocation ringbuffer telemetry before process credential transitions finalize.

Prohibited Anti-Pattern: Relying on Userspace Namespaces or Read-Only Rootfs Without Kernel-Enforced Execution Verification

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: eBPF LSM bprm_creds_for_exec Ephemeral Binary Lockdown - Intercepts kernel bprm_creds_for_exec hooks via eBPF Linux Security Modules (LSM) to enforce immutable execution boundaries within zero-trust distroless containers. Prevents post-exploitation arbitrary binary execution, fileless payload spawning via memfd_create, and runtime process drift by enforcing cryptographic hash verification or strict cgroup-pinned execution allowlists in ring 0. Enforces immediate kernel-level denial with -EPERM and zero-allocation ringbuffer telemetry before process credential transitions finalize.
globs: **/*.c, **/*.bpf.c, **/*.bpf.h, **/*.go, **/*.rs
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/ebpf-lsm-bprm-exec-lockdown-guardrail"
---

# eBPF LSM bprm_creds_for_exec Ephemeral Binary Lockdown

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Relying on Userspace Namespaces or Read-Only Rootfs Without Kernel-Enforced Execution Verification

## System Constraints
You are a Principal Security Engineer and Kernel Systems Architect enforcing eBPF LSM Ephemeral Process Execution Lockdown Guardrails. Mandate that all containerized execution events pass through `lsm/bprm_creds_for_exec` hooks. Verify that memory-backed executions (`memfd_create`), unexpected binary paths, and unauthorized cgroup task spawning are dropped synchronously in the kernel before capability assignment. Reject any solution relying exclusively on userspace admission controllers or vulnerable seccomp blacklists.

## Strict Guidelines
- LSM programs MUST attach to `lsm/bprm_creds_for_exec` or `lsm/bprm_check_security` rather than non-blocking tracepoints like `sys_enter_execve` to ensure pre-execution denial capability.
- Programs MUST read file paths and inode properties safely using `bpf_d_path` or direct struct walk macros (`BPF_CORE_READ`) ensuring zero TOCTOU attack surface.
- Hooks MUST evaluate container identity using `bpf_get_current_cgroup_id()` against an eBPF BPF_MAP_TYPE_HASH allowlist populated strictly by orchestrator admission control.
- Executions sourced from anonymous memory, pipefs, or memory descriptors (e.g., anonymous inodes originating from `memfd_create`) MUST return `-EPERM` instantly for locked cgroups.
- Security audit logs MUST be dispatched asynchronously via `BPF_MAP_TYPE_RINGBUF` to prevent kernel blocking and memory exhaustion during high-frequency execution-denial attacks.
- Engineers MUST NOT depend on standard file extension or string-suffix checking; checks MUST validate device major/minor IDs and inode numbers from trusted immutable layers.

## Bad vs Good Implementations
### Kernel-Level LSM Execution Lockdown via eBPF CO-RE

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Using a tracepoint only provides post-facto observation. The payload executes with full process credentials before userspace can act, and tracepoints cannot alter control flow or return -EPERM to abort binary execution.
```c
#include <vmlinux.h>
#include <bpf/bpf_helpers.h>

SEC("tracepoint/syscalls/sys_enter_execve")
int tracepoint_exec(struct trace_event_raw_sys_enter *ctx) {
    // ANTI-PATTERN: Tracepoints execute asynchronously and CANNOT block execution.
    // Attacker can execute dynamic payloads before alert is handled in userspace.
    char comm[16];
    bpf_get_current_comm(&comm, sizeof(comm));
    bpf_printk("Exec detected: %s\n", comm);
    return 0;
}
```

#### Production Standard (Correct)
> **Standard**: Attaches directly to the Linux Security Module hook bprm_creds_for_exec. It evaluates the binary's struct inode directly from bprm->file using BPF CO-RE, cross-referencing against an orchestration-managed cgroup map, synchronously dropping unauthorized processes with -EPERM before cred initialization.
```c
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_core_read.h>

#define EPERM 1

struct {
    __uint(type, BPF_MAP_TYPE_HASH);
    __uint(max_entries, 10240);
    __type(key, __u64);   /* cgroup_id */
    __type(value, __u64); /* allowed binary inode */
} locked_containers SEC(".maps");

SEC("lsm/bprm_creds_for_exec")
int BPF_PROG(restrict_exec, struct linux_binprm *bprm)
{
    __u64 cgroup_id = bpf_get_current_cgroup_id();
    __u64 *allowed_inode = bpf_map_lookup_elem(&locked_containers, &cgroup_id);
    
    if (!allowed_inode)
        return 0; /* Unlocked cgroup, pass through */

    struct file *file = BPF_CORE_READ(bprm, file);
    if (!file)
        return -EPERM;

    struct inode *inode = BPF_CORE_READ(file, f_inode);
    __u64 current_inode = BPF_CORE_READ(inode, i_ino);

    /* Reject dynamic binaries, memfd execution, or unexpected inodes */
    if (current_inode != *allowed_inode) {
        return -EPERM;
    }

    return 0;
}

char _license[] SEC("license") = "GPL";
```

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: eBPF LSM bprm_creds_for_exec Ephemeral Binary Lockdown

eBPF LSM bprm_creds_for_exec Ephemeral Binary Lockdown defines an industrial-grade behavioral standard for security engineering. Intercepts kernel bprm_creds_for_exec hooks via eBPF Linux Security Modules (LSM) to enforce immutable execution boundaries within zero-trust distroless containers. Prevents post-exploitation arbitrary binary execution, fileless payload spawning via memfd_create, and runtime process drift by enforcing cryptographic hash verification or strict cgroup-pinned execution allowlists in ring 0. Enforces immediate kernel-level denial with -EPERM and zero-allocation ringbuffer telemetry before process credential transitions finalize. 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: Relying on Userspace Namespaces or Read-Only Rootfs Without Kernel-Enforced Execution Verification 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 DriftRelying on Userspace Namespaces or Read-Only Rootfs Without Kernel-Enforced Execution VerificationCritical
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

LSM programs MUST attach to `lsm/bprm_creds_for_exec` or `lsm/bprm_check_security` rather than non-blocking tracepoints like `sys_enter_execve` to ensure pre-execution denial capability.

LSM programs MUST attach to `lsm/bprm_creds_for_exec` or `lsm/bprm_check_security` rather than non-blocking tracepoints like `sys_enter_execve` to ensure pre-execution denial capability.

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

Programs MUST read file paths and inode properties safely using `bpf_d_path` or direct struct walk macros (`BPF_CORE_READ`) ensuring zero TOCTOU attack surface.

Programs MUST read file paths and inode properties safely using `bpf_d_path` or direct struct walk macros (`BPF_CORE_READ`) ensuring zero TOCTOU attack surface.

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

Hooks MUST evaluate container identity using `bpf_get_current_cgroup_id()` against an eBPF BPF_MAP_TYPE_HASH allowlist populated strictly by orchestrator admission control.

Hooks MUST evaluate container identity using `bpf_get_current_cgroup_id()` against an eBPF BPF_MAP_TYPE_HASH allowlist populated strictly by orchestrator admission control.

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

Executions sourced from anonymous memory, pipefs, or memory descriptors (e.g., anonymous inodes originating from `memfd_create`) MUST return `-EPERM` instantly for locked cgroups.

Executions sourced from anonymous memory, pipefs, or memory descriptors (e.g., anonymous inodes originating from `memfd_create`) MUST return `-EPERM` instantly for locked cgroups.

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

Security audit logs MUST be dispatched asynchronously via `BPF_MAP_TYPE_RINGBUF` to prevent kernel blocking and memory exhaustion during high-frequency execution-denial attacks.

Security audit logs MUST be dispatched asynchronously via `BPF_MAP_TYPE_RINGBUF` to prevent kernel blocking and memory exhaustion during high-frequency execution-denial attacks.

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.
6

Engineers MUST NOT depend on standard file extension or string-suffix checking

Engineers MUST NOT depend on standard file extension or string-suffix checking; checks MUST validate device major/minor IDs and inode numbers from trusted immutable layers.

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 eBPF LSM bprm_creds_for_exec Ephemeral Binary Lockdown critical for AI coding assistants?

Intercepts kernel bprm_creds_for_exec hooks via eBPF Linux Security Modules (LSM) to enforce immutable execution boundaries within zero-trust distroless containers. Prevents post-exploitation arbitrary binary execution, fileless payload spawning via memfd_create, and runtime process drift by enforcing cryptographic hash verification or strict cgroup-pinned execution allowlists in ring 0. Enforces immediate kernel-level denial with -EPERM and zero-allocation ringbuffer telemetry before process credential transitions finalize. 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 (Relying on Userspace Namespaces or Read-Only Rootfs Without Kernel-Enforced Execution Verification) 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

eBPF