Skip to content

Qwen3-0.6B inference (12 KB), bare-metal bootable OS (22 KB), and from-scratch Mini-GPT trainer with live Braille TUI (32 KB) in 100% pure x86-64 NASM assembly. Zero C, zero libc, zero dependencies.

6.1 KB
Raw Blame

eBPF-Jev Shared Architecture & Binary Contract (v1)

Defensive Linux kernel security research project (05-ebpf-jev/). All tests use inert fixtures (disposable dummy files, local loopback sinks) — zero offensive payloads.

1. Scope & Hooks (Linux 6.12 KVM testbed, CONFIG_BPF_LSM=y, lsm=...,bpf)

Monitored processes live inside a dedicated launcher-managed cgroup. Four non-sleepable lsm/* hooks (zero tail_call dependencies, 100% bpf_loop-compatible):

  1. lsm/task_alloc: copies 32-byte int8_t h[32] + metadata from parent BPF_MAP_TYPE_TASK_STORAGE to child (with model_gen check and graceful NULL handling).
  2. lsm/bprm_check_security: extracts bounded event feature vector x[32] from executable identity (bprm->file inode/dev class + hashed byte 3-grams of bprm->filename, interpreter class, depth/uid flags) and updates h[32] in task_storage.
  3. lsm/file_open: extracts x[32] from resolved (dev, ino) against a registered protected-object map (protected_objects_map), open flags (O_RDONLY/O_WRONLY/O_RDWR), and file class. Registered config (40) and protected (85/127) objects advance recurrent state. Opens of unregistered inodes leave that state intact.
  4. lsm/socket_connect: extracts x[32] from sockaddr (sa_family, port bucket, loopback/private/allowlisted CIDR vs external), runs the recurrent forward pass on [x[32], h[32]], updates h[32], evaluates the calibrated multi-head decision scores y[4], emits a BPF_RINGBUF event (with exact ktime_ns delta, scores, action), and returns -EPERM if (deterministic_floor_deny || (y[0] >= thresh_deny && y[3] <= max_uncertainty)).

2. Exact Fixed-Point Recurrent Micro-Jev Math (Bit-Exact Python <-> eBPF C)

  • Input per event: int8_t in[64], where:
    • in[0..31] = current event feature vector x[32] (int8, [-128, 127])
    • in[32..63] = previous task hidden state h[32] (int8, [-128, 127], initialized to 0 at root task start)
  • Layer 1 (64 -> 64, INT8 weights, INT32 bias & accumulator):
    • W1[64][64] (int8_t, 4,096 B), b1[64] (int32_t, 256 B), shift1 (uint8_t, right-shift after acc)
    • For j in 0..63:
      • acc = b1[j] + sum_{i=0..63} ((int32_t)in[i] * (int32_t)W1[j][i])
      • val = (acc > 0) ? (acc >> shift1) : 0 // ReLU + arithmetic shift
      • h1[j] = clamp_i8(val, 0, 127)
  • State Update (Recurrent Carry in BPF_MAP_TYPE_TASK_STORAGE):
    • h_next[0..31] = h1[0..31] (stored back into task_storage!)
  • Layer 2 (64 -> 4 Multi-Head Jev Decision Output):
    • W2[4][64] (int8_t, 256 B), b2[4] (int32_t, 16 B), shift2 (uint8_t)
    • For k in 0..3:
      • acc = b2[k] + sum_{j=0..63} ((int32_t)h1[j] * (int32_t)W2[k][j])
      • logit = clamp_i32(acc >> shift2, -128, 127)
      • prob_u8[k] = sigmoid_lut[logit + 128] // 256-byte calibrated LUT (uint8_t in 0..255)
    • The 4 Jev heads:
      • k=0: exfil_risk (0..255, probability of unauthorized secret-to-network exfiltration)
      • k=1: evasion_chain (0..255, probability of suspicious child-fork / wrapper chain after protected access)
      • k=2: benign_dev_workflow (0..255, probability of legitimate developer/CI workflow)
      • k=3: uncertainty (0..255, calibrated abstention / low-confidence score)
  • Optional Content N-Gram Embedding Table (in flat BPF_MAP_TYPE_ARRAY, single element):
    • emb[1024][16] (int8_t, 16,384 B) indexed by fnv1a_3gram(filename_bytes) & 1023 for in[16..31], while in[0..15] carry structured kernel features (event_type one-hot, protected_obj_class, open_flags, exec_interpreter_class, fork_depth, uid_class, dst_cidr_class, dst_port_bucket, time_delta_bucket, prior_protected_count, prior_exec_count).
    • Total model weight footprint: ~21 KB (16 KB embedding + 4.6 KB recurrent MLP + 256 B sigmoid LUT + metadata) — fits completely inside L1/L2 cache and double-buffered BPF map (active_slot atomic flip for live hot-swap!).

3. Feature Layout in[0..31] (Shared Frozen Mapping)

  • in[0]: event_type (0=bprm, 64=file_open, 127=socket_connect)
  • in[1]: protected_object_class (0=none, 40=config_nonsecret, 85=dummy_env, 127=dummy_key)
  • in[2]: open_access_mode (0=none, 40=rdonly, 85=wronly, 127=rdwr)
  • in[3]: exec_binary_class (0=other, 30=coreutils_git, 65=build_pkg_mgr, 95=shell, 127=script_interp_net_tool)
  • in[4]: fork_depth_from_cgroup_root (min(depth * 25, 127))
  • in[5]: dst_class (0=none, 30=loopback_approved, 75=local_private, 127=unapproved_sink)
  • in[6]: dst_port_bucket (0=none, 30=http_https, 65=dns_ssh, 95=high_ephemeral, 127=nonstandard_sink)
  • in[7]: time_since_protected_open_bucket (0=never, 127=<1s, 90=1..5s, 50=5..30s, 20=>30s)
  • in[8]: protected_open_count (min(cnt * 32, 127))
  • in[9]: exec_count_since_protected (min(cnt * 32, 127))
  • in[10]: inherited_taint_flag (0 or 127 if parent had protected_open_count > 0)
  • in[11]: benign_allowlist_hint (0 or 127 if binary+dst match known approved dev registry/tooling)
  • in[12..15]: reserved / zero (0)
  • in[16..31]: pooled 16-dim INT8 FNV-1a 3-gram hash embedding over bounded path/filename bytes (<= 64 B, clamped [-128, 127]; 0 when hook has no string).

4. Shared Binary Pack Format (ebpf_jev_model.bin + ebpf_jev_weights.h)

Little-endian C struct struct jev_model_weights (fixed exact size, padded to 8B):

  • uint32_t magic (0x4A455631 = "JEV1")
  • uint32_t model_gen
  • uint8_t shift1, shift2, thresh_deny, max_uncertainty
  • uint8_t emb_shift, reserved[3]
  • int8_t emb[1024][16]
  • int8_t W1[64][64]
  • int32_t b1[64]
  • int8_t W2[4][64]
  • int32_t b2[4]
  • uint8_t sigmoid_lut[256]

5. Required Comparators (Identical Features & Splits)

  1. noop (empty LSM hooks, latency baseline)
  2. rule_fsm (deterministic: any protected open -> deny unapproved connect)
  3. oblivious_gbdt (16–32 depth-4 oblivious trees in BPF_MAP, INT16 leaves, same 32 features + counters)
  4. stateless_mlp (same 32 -> 64 -> 4 INT8 MLP with h[32] zeroed)
  5. recurrent_jev (full recurrent 64 -> 64 -> 4 INT8 multi-head Micro-Jev with task_storage h[32])