Skip to main content
skill CX Codex

kernel-security — Claude Code skill: Linux kernel hardening and LSM

kernel-security — a skill for SELinux and AppArmor policies, seccomp-bpf sandboxing, KASLR, Intel CET, ARM PAC and BTI. Write LSM rules, triage kernel CVEs, and configure kernel mitigations.

MIT 381 installs ★ 298 updated 2026-06-27

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add mohitmishra786/low-level-dev-skills --skill kernel-security -a claude-code
Open on GitHub

What kernel-security does

Activates on requests about Linux kernel security: LSM frameworks, syscall restriction with seccomp, KASLR configuration, Intel CET (Shadow Stack and Indirect Branch Tracking), ARM PAC and BTI, kernel vulnerability analysis.

Includes SELinux and AppArmor policy examples, C code with libseccomp for process sandboxing, commands to check security status, and a CVE triage workflow. Shows how to enable KASAN on a kernel build, verify CET support in the processor, and confirm PAC and BTI in binaries.

Requires basic Linux knowledge, understanding of DAC versus MAC, and experience with kernel or containers. The skill explains mechanisms and avoids common mistakes rather than providing ready-made policies for specific applications.

What it helps with

  • write a SELinux policy to confine a service
  • set up a seccomp filter for process sandboxing
  • enable CET or PAC during binary compilation
  • build a kernel with KASAN for vulnerability research
  • check whether a kernel CVE affects your version

Example prompts for the agent

  • Write a SELinux policy for nginx that allows logging only to /var/log/nginx and listening on port 80
  • Help me create a seccomp filter with libseccomp that allows read, write, exit_group, and mmap but blocks everything else
  • Explain how to enable Intel CET at compile time and verify Shadow Stack and IBT are active in a binary

How to install kernel-security

1Skills CLI (Vercel)

npx skills add mohitmishra786/low-level-dev-skills --skill kernel-security -a claude-code

2Manually: put the files in place

~/.claude/skills/kernel-security/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/kernel-security/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about kernel-security

How do I install kernel-security in Claude Code?

Run npx skills add mohitmishra786/low-level-dev-skills --skill kernel-security -a claude-code, then open ~/.claude/skills/kernel-security/SKILL.md for the skill documentation.

What does kernel-security do?

It guides you through writing LSM policies (SELinux, AppArmor), creating seccomp filters with libseccomp, enabling hardware protections (CET, PAC, BTI), building kernels with KASAN, and triaging kernel vulnerabilities.

Do I need assembly or low-level programming knowledge to use this skill?

No, but you should have basic Linux knowledge, understand syscalls, file permissions (DAC/MAC), and some experience with kernels or containers. CET, PAC, and BTI are hardware mechanisms—assembly details are not required.

Source text

SKILL.md · MIT
---
name: kernel-security
description: Linux kernel security skill for LSM, hardening, and exploit mitigations. Use when writing SELinux/AppArmor policies, seccomp-bpf filters, configuring KASLR/CET/PAC, or triaging kernel CVEs. Activates on queries about SELinux, AppArmor, seccomp, KASLR, CET, PAC, BTI, KASAN, or kernel CVE.
---

# Kernel Security

## Purpose

Guide agents through Linux kernel security: LSM frameworks (SELinux, AppArmor), seccomp-bpf with libseccomp, KASLR and bypass mitigations, Intel CET (Shadow Stack + IBT), ARM PAC and BTI, kernel sanitizers (KASAN, KMSAN), and CVE triage for kernel vulnerabilities.

## When to Use

- Writing SELinux or AppArmor policies for confined services
- Sandboxing processes with seccomp-bpf filters
- Hardening binaries with CET, PAC, or BTI
- Enabling KASAN on kernel builds for vulnerability research
- Triaging kernel CVE impact on your distro/kernel version
- Designing container or microservice security boundaries

## Workflow

### 1. LSM framework overview

```
Application syscall
    → DAC (uid/gid, file mode)
    → LSM hook (SELinux/AppArmor/Yama/...)
    → Capability check
    → seccomp filter
    → Kernel
```

```bash
# Active LSM
cat /sys/kernel/security/lsm
# common: lockdown,capability,yama,apparmor,safesetid
```

### 2. SELinux policy

```bash
# Check SELinux status
getenforce
sestatus

# Context of file/process
ls -Z /usr/sbin/nginx
ps -eZ | grep nginx

# Audit denials
ausearch -m avc -ts recent
sealert -a /var/log/audit/audit.log
```

Policy module example:

```te
# myapp.te
policy_module(myapp, 1.0.0)

type myapp_t;
type myapp_exec_t;
type myapp_log_t;

init_daemon_domain(myapp_t, myapp_exec_t)

allow myapp_t myapp_log_t:file { create write append open };
allow myapp_t self:tcp_socket { create bind listen accept };
```

```bash
checkmodule -M -m -o myapp.mod myapp.te
semodule_package -o myapp.pp -m myapp.mod
semodule -i myapp.pp
```

### 3. AppArmor profiles

```bash
# Generate complain-mode profile
aa-genprof /usr/bin/myapp

# Enforce
aa-enforce /etc/apparmor.d/usr.bin.myapp

# Check status
aa-status
```

```apparmor
# /etc/apparmor.d/usr.bin.myapp
#include <tunables/global>

/usr/bin/myapp {
  #include <abstractions/base>

  /usr/bin/myapp mr,
  /var/log/myapp.log w,
  /etc/myapp/config r,
  network bind tcp,
  deny /etc/shadow r,
}
```

### 4. seccomp-bpf with libseccomp

```c
#include <seccomp.h>

int sandbox(void) {
    scmp_filter_ctx ctx = seccomp_init(SCMP_ACT_KILL_PROCESS);

    // Allow read/write/exit/mmap
    seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(read), 0);
    seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(write), 0);
    seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(exit_group), 0);
    seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(mmap), 0);
    seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(brk), 0);

    // Return EPERM instead of kill for open
    seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EPERM), SCMP_SYS(open), 0);
    seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EPERM), SCMP_SYS(openat), 0);

    return seccomp_load(ctx);
}
```

```bash
# Export BPF filter for audit
scmp_filter_ctx ctx = ...;
seccomp_export_bpf(ctx, fd);

# strace to find needed syscalls before tightening
strace -c ./myapp
```

### 5. KASLR

```bash
# Check KASLR enabled
cat /proc/sys/kernel/randomize_va_space   # 2 = full
dmesg | grep KASLR

# Kernel cmdline
grep kaslr /proc/cmdline
```

Mitigations against KASLR leaks:
- No `/proc/<pid>/maps` to untrusted
- Pointer hashing in `%pK` printk
- eBPF restricted on unprivileged

### 6. Intel CET

```bash
# Compile with CET
gcc -fcf-protection=full -o app app.c

# Verify shadow stack and IBT
readelf -n app | grep -E 'SHSTK|IBT'
readelf --notes app | grep -A2 GNU_PROPERTY
```

| Feature | Protects against |
|---------|------------------|
| SHSTK (Shadow Stack) | ROP return address overwrites |
| IBT (Indirect Branch Tracking) | CALL/JMP to non-ENDBR targets |

Requires CPU with CET (Intel Tiger Lake+; AMD Zen 3+ on CPUs with shadow-stack support) and kernel CET support.

### 7. ARM PAC and BTI

```bash
# GCC/Clang branch protection
gcc -mbranch-protection=standard -o app app.c
# PAC (pointer authentication) + BTI (branch target identification)

# Verify
readelf -n app | grep -E 'GNU_PROPERTY_AARCH64_FEATURE_1'
llvm-objdump -d app | grep bti
```

PAC signs return addresses and pointers with cryptographic keys (ARMv8.3+).
BTI marks valid branch targets — invalid jumps fault.

### 8. Kernel memory tagging

```bash
# KASAN kernel build
# CONFIG_KASAN=y in kernel .config
make menuconfig  # Kernel hacking → KASAN

# Boot with KASAN kernel
# Reports use-after-free, OOB with stack trace

# KMSAN (uninitialized memory)
# CONFIG_KMSAN=y — kernel equivalent of MSan
```

```bash
# KASAN report example fields
# BUG: KASAN: slab-out-of-bounds in ...
# Call trace: ...
```

### 9. CVE triage workflow

```bash
# Check kernel version
uname -r

# Distro security tracker
# Ubuntu: ubuntu-security-notices
# RHEL: errata

# NVD lookup
# https://nvd.nist.gov/vuln/detail/CVE-XXXX-XXXXX

# Is patch backported?
zgrep -l CVE-2024-XXXX /usr/share/doc/linux-*/changelog.Debian.gz
```

Triage checklist:
1. Affected subsystem (net, fs, drivers)?
2. Local or remote exploit?
3. Fixed in your kernel version?
4. Mitigation without patch (disable module, sysctl)?

## Common Problems

| Symptom | Cause | Fix |
|---------|-------|-----|
| SELinux denials | Missing allow rule | `audit2allow`; refine policy |
| AppArmor profile break | Path mismatch | Update profile paths; use globs |
| seccomp kills app | Missing syscall | `strace`; add allow rule |
| CET not active | Old CPU/kernel | Check `/proc/cpuinfo` flags |
| KASAN kernel slow | 2-5x overhead | Use only in test VMs |
| False sense of security | LSM bypass via kernel bug | Defense in depth; keep kernel updated |

## Related Skills

- `skills/virtualization/containers-internals` — container seccomp and caps
- `skills/runtimes/binary-hardening` — userspace CET, RELRO, PIE
- `skills/runtimes/sanitizers` — ASan/HWASan userspace counterparts
- `skills/observability/ebpf` — LSM BPF programs
- `skills/kernel/kernel-debugging` — analyze KASAN reports
- `skills/security/reverse-engineering` — exploit analysis

© mohitmishra786 · MIT · mohitmishra786/low-level-dev-skills

Similar skills

All skills for Security →

From the same set140

The whole set →
jit-compilation jit-compilation teaches the agent to build a JIT: LLVM ORC and LLJIT, Cranelift, inline caches, trampolines, Rust dynasm. Useful for interpreter hot paths and REPLs. CX Codex +1 382installs kernel-testing Skill for Linux kernel testing: KUnit for unit tests, kselftest for regression checks, syzkaller for fuzzing, and LTP for syscall compatibility. Activates on kunit.py queries, syzkaller config, or KernelCI setup. CX Codex +1 382installs branch-prediction-and-speculation branch-prediction-and-speculation is a Claude Code skill that explains CPU branch prediction and speculative execution to help optimize hot loops and protect code from cache timing leaks. CX Codex +1 382installs os-dev-scratch os-dev-scratch is a Claude Code skill for building a minimal x86-64 OS, from boot stages to drivers and context switching. It activates on questions about kernel boot, interrupts, page tables, or QEMU. CX Codex +1 381installs peripherals-from-datasheet peripherals-from-datasheet guides driver development directly from MCU reference manuals. Helpful when writing bare-metal register code without a vendor HAL or migrating peripherals across chips. CX Codex +1 380installs platform-device-model The platform-device-model skill explains Linux platform-driver binding, probe and remove, sysfs, device properties, and deferred probing for kernel work. CX Codex +1 378installs writing-char-drivers writing-char-drivers — a skill for writing Linux character drivers: cdev registration, file_operations implementation, safe userspace copies, ioctl and mmap. CX Codex +1 378installs adc-dac-baremetal adc-dac-baremetal — a skill for bare-metal ADC and DAC setup on MCUs: channel selection, sampling time, calibration, DMA buffers, and voltage output. Essential when working with analog sensors, audio signals, or control voltages. CX Codex +1 378installs

Project sponsors

Companies that keep this analytics open