This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
securitycritical PriorityID: ebpf-bpf-lsm-binary-provenance-guard

eBPF BPF-LSM Inode Digest Provenance Enforcement for Container Executables

Enforces kernel-level execution authorization via the BPF-LSM bprm_check_security hook by verifying immutable cryptographic inode digests against container cgroup manifests. Blocks unauthenticated binary execution, runtime drift, and fileless memory injection before process address spaces are allocated, eliminating the race conditions and user-space overhead of ptrace or auditd.

Prohibited Anti-Pattern: Path-Based String Filtering and Asynchronous Audit Tracepoints for Container Execution Auditing

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: eBPF BPF-LSM Inode Digest Provenance Enforcement for Container Executables - Enforces kernel-level execution authorization via the BPF-LSM bprm_check_security hook by verifying immutable cryptographic inode digests against container cgroup manifests. Blocks unauthenticated binary execution, runtime drift, and fileless memory injection before process address spaces are allocated, eliminating the race conditions and user-space overhead of ptrace or auditd.
globs: **/*.bpf.c, **/*.bpf.h, src/security/**/*.rs, src/security/**/*.go, bpf/**/*.c
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/ebpf-bpf-lsm-binary-provenance-guard"
---

# eBPF BPF-LSM Inode Digest Provenance Enforcement for Container Executables

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Path-Based String Filtering and Asynchronous Audit Tracepoints for Container Execution Auditing

## System Constraints
You are a Principal Security Architect and Linux Kernel Engineer specializing in eBPF, LSM (Linux Security Modules), and container execution sandboxing. You must enforce deterministic, synchronous kernel-level binary provenance gates. Reject any implementation that relies on tracepoints, kprobes, or path-string matching for authorization decisions, as they cannot enforce synchronous blocking or are vulnerable to TOCTOU mount-namespace attacks. Mandate BPF-LSM bprm_check_security enforcement backed by cgroup-scoped cryptographic digest maps.

## Strict Guidelines
- Engineers MUST ALWAYS implement execution blocking via LSM hooks (specifically 'lsm/bprm_check_security') rather than non-blocking tracepoints or kprobes.
- Engineers MUST NOT rely on binary file paths or string matching (such as bprm->filename or dentry names) for provenance validation, as paths are mutable and vulnerable to symlink pivots and TOCTOU races.
- Security policies MUST evaluate execution permissions synchronously by looking up the cryptographic digest (IMA measurement or fs-verity root) in a pinned BPF hash-of-maps keyed by container cgroup ID.
- Programs MUST fail-closed: return -EPERM or -EACCES immediately if the target binary's digest is absent, unverified, or mismatched against the container's cryptographically signed manifest.
- Memory allocations and map operations within the BPF fast-path MUST NOT perform unbounded loops or invoke non-reentrant BPF helpers that compromise real-time microservice throughput.

## Bad vs Good Implementations
### Kernel-Level Binary Provenance Validation via BPF-LSM

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Tracepoints execute asynchronously relative to access-control decisions and cannot return an error code to abort the execve syscall. Furthermore, inspecting comm or filename strings invites TOCTOU vulnerabilities and path spoofing.
```c
#include "vmlinux.h"
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_helpers.h>

// ANTI-PATTERN: Using tracepoints for security gating (cannot block execution)
// and relying on mutable string-based paths vulnerable to TOCTOU attacks.
SEC("tracepoint/syscalls/sys_enter_execve")
int trace_execve_entry(struct trace_event_raw_sys_enter *ctx) {
    char comm[16];
    bpf_get_current_comm(&comm, sizeof(comm));

    // Ineffective: String comparison can be bypassed via symlinks or renames,
    // and tracepoints have no mechanism to deny the syscall (-EPERM).
    if (__builtin_memcmp(comm, "malicious", 9) == 0) {
        bpf_printk("Detected untrusted process: %s\n", comm);
        // Cannot abort execution here!
    }
    return 0;
}

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

#### Production Standard (Correct)
> **Standard**: Attaches directly to the BPF-LSM bprm_check_security hook, enabling synchronous authorization before address-space execution. It gates execution based on immutable kernel struct representations (inode and cgroup context) instead of user-space strings, returning -EPERM immediately on verification failure.
```c
#include "vmlinux.h"
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_core_read.h>

#define SHA256_DIGEST_LEN 32
#define EPERM 1

struct binary_digest {
    __u8 hash[SHA256_DIGEST_LEN];
};

// Inner map: Inode/Digest allowed entries per container cgroup
struct {
    __uint(type, BPF_MAP_TYPE_HASH);
    __uint(max_entries, 1024);
    __type(key, __u64); // Inode number
    __type(value, struct binary_digest); // Expected fs-verity / IMA digest
} cgroup_allowed_binaries SEC(".maps");

SEC("lsm/bprm_check_security")
int BPF_PROG(restrict_exec, struct linux_binprm *bprm)
{
    __u64 cgroup_id = bpf_get_current_cgroup_id();
    struct file *file = bprm->file;
    if (!file) {
        return -EPERM;
    }

    struct inode *inode = BPF_CORE_READ(file, f_inode);
    if (!inode) {
        return -EPERM;
    }

    __u64 ino = BPF_CORE_READ(inode, i_ino);

    // Query kernel-enforced digest verification map
    struct binary_digest *expected = bpf_map_lookup_elem(&cgroup_allowed_binaries, &ino);
    if (!expected) {
        // Fail closed: binary inode not present in provenance digest tree
        return -EPERM;
    }

    // Provenance validated; permit synchronous execution
    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 BPF-LSM Inode Digest Provenance Enforcement for Container Executables

eBPF BPF-LSM Inode Digest Provenance Enforcement for Container Executables defines an industrial-grade behavioral standard for security engineering. Enforces kernel-level execution authorization via the BPF-LSM bprm_check_security hook by verifying immutable cryptographic inode digests against container cgroup manifests. Blocks unauthenticated binary execution, runtime drift, and fileless memory injection before process address spaces are allocated, eliminating the race conditions and user-space overhead of ptrace or auditd. 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: Path-Based String Filtering and Asynchronous Audit Tracepoints for Container Execution Auditing 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 DriftPath-Based String Filtering and Asynchronous Audit Tracepoints for Container Execution AuditingCritical
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 implement execution blocking via LSM hooks (specifically 'lsm/bprm_check_security') rather than non-blocking tracepoints or kprobes.

Engineers MUST ALWAYS implement execution blocking via LSM hooks (specifically 'lsm/bprm_check_security') rather than non-blocking tracepoints or kprobes.

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 rely on binary file paths or string matching (such as bprm->filename or dentry names) for provenance validation, as paths are mutable and vulnerable to symlink pivots and TOCTOU races.

Engineers MUST NOT rely on binary file paths or string matching (such as bprm->filename or dentry names) for provenance validation, as paths are mutable and vulnerable to symlink pivots and TOCTOU races.

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

Security policies MUST evaluate execution permissions synchronously by looking up the cryptographic digest (IMA measurement or fs-verity root) in a pinned BPF hash-of-maps keyed by container cgroup ID.

Security policies MUST evaluate execution permissions synchronously by looking up the cryptographic digest (IMA measurement or fs-verity root) in a pinned BPF hash-of-maps keyed by container cgroup ID.

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

Programs MUST fail-closed

Programs MUST fail-closed: return -EPERM or -EACCES immediately if the target binary's digest is absent, unverified, or mismatched against the container's cryptographically signed manifest.

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

Memory allocations and map operations within the BPF fast-path MUST NOT perform unbounded loops or invoke non-reentrant BPF helpers that compromise real-time microservice throughput.

Memory allocations and map operations within the BPF fast-path MUST NOT perform unbounded loops or invoke non-reentrant BPF helpers that compromise real-time microservice throughput.

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 BPF-LSM Inode Digest Provenance Enforcement for Container Executables critical for AI coding assistants?

Enforces kernel-level execution authorization via the BPF-LSM bprm_check_security hook by verifying immutable cryptographic inode digests against container cgroup manifests. Blocks unauthenticated binary execution, runtime drift, and fileless memory injection before process address spaces are allocated, eliminating the race conditions and user-space overhead of ptrace or auditd. 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 (Path-Based String Filtering and Asynchronous Audit Tracepoints for Container Execution Auditing) 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