Sitemap
80h3m14n

80h3m14n

Tech enthusiast and cyber security hobbyist

Linux Security Framework

11 min readAug 7, 2025

--

Linux has a layered and modular security model, using various kernel features and security modules to protect against a wide range of threats and vulnerabilities.

Security best practices

- Always apply updates regularly `sudo apt update && sudo apt upgrade`

- Use SSH keys instead of passwords for remote logins

- Limit sudo access, and enforce strong password policies.

- Audit your system regularly

- Enable and configure firewalls to block unwanted traffic

Kernel-level / system hardening

Kernel access control tools
1. Mandatory Access Control (MAC)
- SELinux
- AppArmor
- TOMOYO
- Simplified MAC Kernel (Smack)

2. System call filter
- Berkeley Packet Filter (BPF)
- Extended Berkeley Packet Filter (eBPF)
- Seccomp-BPF
- BPF-LSM

3. Process control
- kexec Restriction
- Grsecurity
- Yama
- Landlock

3. Kernel lockdown
- Lockdown

4. Kernal module control
- LodPin

5. UID/GID
- SafeSetID

6. File integrity check
- IMA/EVM

7. Isolation
- Namesapaces
- Cgroups

8. Privilege boundary enforcement technique

- Supervisor Mode Execution Protection (SMEP)
- Supervisor Mode Access Prevention (SMAP)
- Kernel Page Table Isolation (KPTI)

9. Memory Safety / Exploit Mitigations

These are compile-time and runtime protections against memory corruption exploits (ROP, JOP, use-after-free, info leaks):

- KASLR (`RANDOMIZE_BASE`, `RANDOMIZE_MEMORY`): Randomizes kernel and module load addresses at boot
- Stack canaries (`STACKPROTECTOR_STRONG`, per-task): Detects stack buffer overflows before return
- CFI (`CFI_CLANG` / kCFI): Compiler-enforced Control Flow Integrity; validates indirect call targets
- Intel CET — IBT (`X86_KERNEL_IBT`): Hardware Indirect Branch Tracking; requires ENDBR landing pads
- Intel CET — Shadow Stack (`X86_USER_SHADOW_STACK`): Hardware shadow stack protecting return addresses (userspace since 6.6; kernel-mode is an active RFC as of Oct 2026)
- ARM PAC / BTI (`ARM64_PTR_AUTH`, `ARM64_BTI`): Pointer Authentication + Branch Target Identification on ARMv8.3+
- Shadow Call Stack (`SHADOW_CALL_STACK`, arm64): Software shadow stack for return addresses when PAC unavailable
- FORTIFY_SOURCE / FORTIFY_KERNEL: Compile-time bounds checking on `memcpy`, `strcpy`, etc.
- HARDENED_USERCOPY: Whitelist-based validation of `copy_to_user`/`copy_from_user` ranges
- Slab hardening (`SLAB_FREELIST_HARDENED`, `SLAB_FREELIST_RANDOM`): Obfuscates and randomizes slab freelist metadata
- STRICT_KERNEL_RWX / STRICT_MODULE_RWX: Makes kernel/module text read-only, data non-executable
- INIT_STACK_ALL_ZERO: Zeroes the entire kernel stack frame (kills uninitialized info leaks)
- MTE (`ARM64_MTE`): ARM Memory Tagging Extension — hardware use-after-free detection
- KASAN / KMSAN / KFENCE: Kernel Address/Memory Sanitizer / KFENCE — runtime bug detection (debug/hardened builds)

10. Speculation Control (beyond KPTI)

KPTI is one piece; the full Spectre/Meltdown mitigation stack includes:

- IBRS / IBPB — Indirect Branch Restricted/Prediction
- STIBP — Single-Thread Indirect Branch Predictors
- Retpolines (`RETPOLINE`) — Software retpolines for Spectre v2
- SLS (`MITIGATION_SLS`) — Straight-Line Speculation mitigation
- SSBD — Speculative Store Bypass Disable
- L1D flush — L1 Data cache flush on VM exit

11. Boot & Firmware Integrity

- Secure Boot — signed bootloader chain
- Measured Boot / TPM — hashes each boot stage into TPM PCRs
- Kernel module signing (`MODULE_SIG`, `MODULE_SIG_FORCE`) — rejects unsigned modules at load

12. Attack Surface Reduction (sysctl / runtime)

These are the runtime knobs that complement the compile-time features:

- `kernel.kptr_restrict=2` — hide kernel pointers from `/proc`
- `kernel.dmesg_restrict=1` — restrict `dmesg` to root
- `kernel.unprivileged_bpf_disabled=1` — block unprivileged eBPF
- `kernel.unprivileged_userns_clone=0` — disable unprivileged user namespaces
- `io_uring` restrictions (disable or limit for unprivileged)
- Trusted Path Execution — only execute setuid binaries from trusted paths
- `/proc` and `/sys` hardening — restrict access to sensitive nodes

Seccomp-BPF

Seccomp (Secure Computing Mode) is a kernel feature that filters system calls a process can make.

The BPF (Berkeley Packet Filter) extension allows fine-grained, programmable syscall filtering.

- eBPF
- eBPF party

eBPF (extended Berkeley Packet Filter) allows for the efficient and safe execution of custom programs in response to various events, such as network packets, system calls, or tracepoints.

sudo apt-get install bpftrace clang
sudo bpftool version
clang -O2 -target bpf -c mpf.c -o mpf.o
sudo mount -t bpf bpf /sys/fs/bpf

Used to reduce the attack surface.

Ideal for sandboxing apps like browsers, containers, and runtimes.

// Enable seccomp filter
prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog);

Use tools like `seccomp-tools` or `libseccomp` to build and inspect filters.

Security-Enhanced Linux (SELinux)

A powerful MAC (Mandatory Access Control) system developed by the NSA used in Red Hat-based distributions.

SELinux controls how processes interact with each other and with system resources beyond normal Unix permissions.

- SELinux project

Functionalty:
- Multi-Level Security (MLS)/Multi-Category Security (MCS)
- Mandatory Access Control (MAC)
- Role-Based Access Control (RBAC)
- Type Enforcement (TE): applications whitelisting

# Enable/disable SELinux
sestatus [-b -v 0 1]
getenforce
# SELinux Booleans
semanage -o
getsebool -a | grep virt
# Set to permissive (0) or enforcing (1)
sudo setenforce 0 # or 1
# View SELinux context
ls -Z
ps auxZww
# Temporarily change context
chcon
# Restore default context
restorecon

Objects are anything on the OS: Files, devices, sockets, processes

ps -eZ | grep httpd
ls -dZ /var/www/html
id -Z

The `z` flag displays the SELinux context information.

SELinux basically isolates and protect system components from one another.

AppArmor

AppArmor is a Mandatory Access Control (MAC) system that’s easier to use than SELinux and focuses on per-application profiles i.e profile-based access control to restrict what applications can access.

# Show loaded profiles
sudo aa-status
# Put profile into complain mode
aa-complain /path
# Enforce a profile
aa-enforce /path
# AppArmor profiles
cat /etc/apparmor.d/

TOMOYO Linux

An early MAC framework, using path-based access control with a simple policy language. Less common today.

# Initialize TOMOYO
tomoyo-init

✅ Simple for embedded systems or legacy deployments.

Simplified MAC Kernel (SMACK)

SMACK uses labels to manage access control, aiming for simplicity.

# Check SMACK status
cat /sys/fs/smackfs/loaded

✅ Used in embedded systems like Tizen OS. Not as widely supported as SELinux/AppArmor.

LoadPin

Prevents the kernel from loading modules or files unless they come from a specific, trusted filesystem (e.g., `/boot` or an initramfs).

  • Once a module is loaded from a “pinned” mount, the kernel blocks loading from anywhere else.
  • Helps harden container and embedded setups.

Yama

Enhances ptrace and other user namespace isolation features.

# Restrict ptrace to only parent/child processes
sysctl -w kernel.yama.ptrace_scope=1

Levels:

1. `0` = classic behavior
2. `1` = restricted to parent processes (default in many distros)
3. `2` = admin-only ptrace
4. `3` = no ptrace at all

✅ Lightweight protection against snooping/debugging attacks.

SafeSetID

Restricts which UIDs/GIDs a process can switch to, reducing risks from `setuid` binaries.

  • Used for container isolation and sandboxed environments.
  • Requires configuration of allowed transitions.

✅ Helps lock down service users and container runtimes.

Lockdown Mode

Introduced in Linux 5.4+, the Lockdown LSM restricts access to kernel internals even for root, especially in UEFI Secure Boot systems.

Boot-time kernel parameters:

# Block kernel memory access
lockdown=integrity
# Stricter mode, blocks more actions
lockdown=confidentiality

✅ Meant to prevent rootkits and kernel tampering post-boot.

GRSEC/PaX

  • Patchset for kernel hardening (used to be open, now commercial).
  • Provides memory protection, address space layout randomization (ASLR), etc.

✅ Used in Hardened Gentoo and some CTF setups.

IMA/EVM (Integrity Measurement Architecture / Extended Verification Module)

  • Cryptographically verifies the integrity of files and kernel modules.
  • Protects against unauthorized changes.

Kexec file load Restriction

Disables loading arbitrary kernels from userland (`kexec`), often locked down in Secure Boot setups.

Privilege boundary enforcement technique

Privilege boundary enforcement techniques are techanisms that enforce the separation between user space (Ring 3) and kernel space (Ring 0) to prevent privilege escalation and information leakage.

1. Supervisor Mode Execution Protection (SMEP: Blocks kernel execution of user-space code, Hardware (CPU), Sets user pages as non-executable in CR4 bit 20.
2. Supervisor Mode Access Prevention (SMAP): Blocks kernel read/write to user-space data, Hardware (CPU), Sets user pages as inaccessible in CR4 bit
3. Kernel Page Table Isolation (PTI: Prevents speculative side-channel leaks ,Software (OS) , Maintains separate user/kernel page table hierarchies.

grep -oE 'smep|smap|pti' /proc/cpuinfo | sort -u
cat /proc/cmdline
cat /sys/kernel/security/lsm 2>/dev/null
cat /sys/devices/system/cpu/vulnerabilities/meltdown 2>/dev/null

They sit alongside other mitigations like KASLR (randomization) and stack canaries (integrity checks) as layers of defense-in-depth for the kernel.

User-level security

1. Authentication & Access control
- Pluggable Authentication Modules (PAM)
- Discretionary Access Control (DAC)
- Access Control Lists (ACLs)
- Secure shell

2. Binary (executables) security

- Memory randomization (ASLR)
- Binary hardening (RELRO, PIE)
- Buffer overflow guard (Stack Canaries)
- Memory execution protection( NX Bit, DEP)

3. Filesytem security
- Full disk encryption (FDE)
- Data at rest encryption
- Hardware-based FDE/Self-Encrypting Drive (SED)

4. Network & services security
- TCP wrappers
- Firewall
- Port knocking

5. System auditing
- File integrity monitoring
- Intrusion detection

6. Monitoring & logging
- System logs
- Journalctl

7. Container & virtualization security
- Namespaces
- Control groups (Cgroups)

1. Authentication & Access control

These are the foundational building blocks of Linux security, every user, service, or attacker has to go through this layer first.

Authentication mechanisms

1. Username + Password

2. Pluggable Authentication Modules (PAM)

3. Secure shell (SSH keys)

4. Multi Factor Authetication (MFA)

Linux supports multiple authentication systems, usually via PAM (Pluggable Authentication Modules):

  • `pam_unix` — standard local password auth
  • (`/etc/passwd` + `/etc/shadow`)
  • `pam_tally2` — account lockout after X failed attempts
  • `pam_faillock` — similar but more modern
  • `pam_google_authenticator` — adds 2FA
  • SSH key authentication — passwordless and more secure
# Check PAM config
cat /etc/pam.d/common-auth
authselect check
authselect current
ls -alZ /lib*/security
# View failed login attempts
sudo faillock - user [user-name]
sudo lastb
sudo journalctl | grep -i "failed.*password"
# Login access control table
cat /etc/security/access.conf

Reset forgotten Linux user password

Reboot your system, at GRUB menu, press `e` to edit the boot entry, find the line starting with Linux — it looks like: `linux /boot/vmlinuz-… root=UUID=… ro quiet splash`

Replace `ro quiet splash` with: `rw init=/bin/bash`

Get 80h3m14n’s stories in your inbox

Join Medium for free to get updates from this writer.

Press `Ctrl + X` or `F10` to boot with these settings into the root shell.

Mount the root FS as read-write (if not already):

mount -o remount,rw /

Reset your user password:

# Reset password
passwd your_username

After that:

sync
reboot -f

🔄 Done
You’re back in. If you don’t see the GRUB menu, hold Shift (on BIOS) or Esc (on UEFI) right after powering on.

🔐 Encrypted Disk + Dual Boot Password Reset

1. Reboot and open GRUB

Reboot your PC, when you hit the GRUB menu, use arrow keys to highlight the Linux entry (usually first).

Press `e` keyboard key to edit.

2. Modify boot parameters
Find the line starting with:

linux /boot/vmlinuz-…

At the end of that line, replace `ro quiet splash` with `rw init=/bin/bash`

3. Unlock LUKS manually (if needed)
If the initrd doesn’t auto-unlock the disk, it’ll boot into a shell with an encrypted root — in that case:

Run:

cryptsetup luksOpen /dev/sdXY cryptroot

Replace `/dev/sdXY` with your encrypted partition (like `/dev/sda3`). If unsure, run `lsblk -f`. Look for something with `crypto_LUKS`

Then:

mount /dev/mapper/cryptroot /mnt
mount - bind /dev /mnt/dev
mount - bind /proc /mnt/proc
mount - bind /sys /mnt/sys
chroot /mnt

4. Reset the password
Once inside the chroot:

# reset password
passwd your_username

5. Cleanup and reboot

exit
reboot -f

Notes:
- If GRUB doesn’t show, press Shift (BIOS) or Esc (UEFI) at boot.
- If you’re using LVM on LUKS, you’ll need to activate it:

# Activate LVM
vgchange -ay

User permissions

Discretionary Access Control (DAC)

1. Root user — full privileges

2. Standard user

3. Normal user

Controls who can read/write/execute files or run commands:

# See file perms
ls -l /path
# Make file executeable
chmod +x file
# Change ownership
chown user:group
# Add user to a group
usermod -aG sudo John

- /etc/passwd — stores user info
- /etc/shadow — stores password hashes
- /etc/sudoers — controls who can run sudo

✅ Essential for hardening users, managing privileges, and limiting access.

User management

sudo su
sudo adduser [username]
sudo passwd [username]

Access Control Lists (ACLs)

ACLs offer fine-grained control over file permissions beyond the traditional user/group/others model.

# Disable login
usermod -s /usr/sbin/nologin username
# Lock an account
sudo usermod -L username
# Unlock an account
sudo usermod -U username
# Restrict who can use sudo
sudo visudo

✅Standard users are required to run commands with the sudo prefix for system level tasks

✅Do not log in as root unless you must

Secure shells

- SSHGuard
- DenyGosts
- Fail2ban
- Teleport

# SSH key auth
sudo nano /etc/ssh/sshd_config
# Change or add the line:
Port 2222

Binary (executables) security

1. Memory randomization
- ASLR

2. Binary hardening
- RELRO
- PIE

3. Buffer overflow guard
- Stack Canaries

4. Memory execution protection
- NX Bit
- DEP

# Check binary security
checksec - file ./[binary]

Address Space Layout Randomization (ASLR)

Randomizes memory locations of stack, heap, libs.

cat /proc/sys/kernel/randomize_va_space

NX (No eXecute) Bit / DEP (Data Execution Prevention)

Stops execution of code from data-only memory areas.

Stack Canaries

Detect buffer overflows before they overwrite return addresses.

RELRO (Read-Only Relocations)

Protects GOT from overwrite attacks. Partial or full.

PIE (Position Independent Executable)

Makes the binary relocatable (required for full ASLR).

File system security

Encryption makes all data on the drive instantly unreadable without the encryption key

1. Full-disk encryption (FDE)
- LUKS (Linux Unified Key Setup)
- Truecrypt
- McAfee Endpoint Encryption

2. Data at rest encryption
- dm-crypt
- fscrypt
- Shufflecake
- Gocryptfs
- CryFS
- eCryptfs
- SecureFS

3. Hardware-based FDE/Self-Encrypting Drive (SED)

Mount options

Use options like: `noexec,nosuid,nodev`

On `/tmp`, `/home`, or removable drives to block code execution and privilege abuse.

Network & service security

- TCP wrappers
- Firewall
- Port Knocking

TCP wrappers

Legacy, still usable for basic service access control via `/etc/hosts.allow` and /etc/hosts.deny

Firewall

Control incoming/outgoing traffic.

Popular firewalls

- `ufw`
- [firewalld](http://firewalld.org)
- `iptables` (legacy)
- `nftables`
- CSF
- Gufw
- OpenSnitch
- VyOS

# 1.ufw
sudo apt install ufw
sudo ufw -h
sudo ufw enable
## block/allow service on specified port
sudo ufw deny 23
sudo ufw allow ssh
# 2. firewalld
sudo firewalld -h
sudo firewall-config
sudo firewall-cmd - state

Port knocking

Obscure service ports until the correct “knock” sequence is received.

Security auditing

File integrity monitoring
- Tripwire
- Auditd
- OSSEC
- OSQuery
- OpenSCAP
- GVM

Intrusion detection
- AIDE
- Snort
- Suricata
- Zeek
- Wazuh

Auditd

Tracks system events (file access, logins, etc.)

sudo apt install auditd
sudo systemctl enable auditd
# View recent audit logs
sudo ausearch -x sshd
# Full audit log
sudo less /var/log/audit/audit.log
# list audit rules
auditctl -l
# search for bash events
ausearch -x bash

Monitoring & logging

Regular monitoring and logging are essential for detecting and responding to security incidents.

- System logs
- Journalctl

System logs

# Kernel Logs
cat /var/log/kern.log
# System Logs
cat /var/log/syslog
# Authentication Logs
cat /var/log/auth.log
# Application Logs
cat /var/log/apache2/error.log
cat /var/log/mysql/error.log
# Security Logs
cat /var/log/fail2ban.log
cat /var/log/ufw.log

Journalctl

sudo journalctl -xe

Setting up log rotation

sudo nano /etc/logrotate.conf

Fail2ban

Fail2ban protects your system from brute-force attacks by monitoring logs and blocking suspicious IP addresses.

sudo apt install fail2ban
sudo nano /etc/fail2ban/jail.local

Container & virtualization security

Tools
- Calico
- Clair
- Grafeas
- Trivy
- Dockle

Namespaces + Cgroups

Namespaces is a kernel feature that provides isolation for process resources, such as process IDs, network interfaces, and file systems.

Control Groups (cgroups) is a kernel feature that allows the management and limitation of resources allocated to process groups, including CPU, memory, and I/O

Security Modules (Seccomp, AppArmor, SELinux)

The kernel’s security modules restrict the actions that can be performed within a container.

These modules enhance security by limiting the attack surface, making containers a more secure option for application deployment.

Podman / Rootless containers

Run containers as non-root user.
Safer than Docker with root daemon.

Other security mechanisms

  • Sandboxing: bubblewrap, firejail, gVisor, Seccomp, Isolate, NsJail
  • PAM security limits: `/etc/security/`
  • Privilege management:`polkit`
  • VPN: StrongSwan, OpenVPN, WireGuard
  • WAFs: ModSecurity, Coraza
  • Patch management: Foreman, Katello, Uyuni
  • Password security: KeePassXC , VaultWarden
  • Modular sudo config:`sudoers.d`
  • Manage fine-grained capabilities: `capsh`, `setcap`

The framework is genuinely defense-in-depth — hardware, kernel, userspace

The problem is fragmentation. Most of these features are off by default and require explicit opt-in (Kconfig flags, sysctls, boot parameters, LSM policy files)

The Linux Security Module framework is what makes the whole thing coherent. SELinux, AppArmor, TOMOYO, SMACK, Landlock, BPF-LSM — they all plug into the same hooks. This is architecturally elegant: one mediation point, multiple policy engines. The tradeoff is that stacking multiple LSMs (e.g., SELinux + Landlock + BPF-LSM) creates a policy composition problem — interactions between layers can be subtle and hard to reason about.

--

--

80h3m14n
80h3m14n

Written by 80h3m14n

0 followers

Tech enthusiast and cyber security hobbyist