TExcelTAD
Home › Security Foundations: Concepts, Law, Ethics & Your Lab › Processes, Privileges and System Calls

Processes, Privileges and System Calls

Every attack you will study in this track ends the same way: some code runs and asks the operating system to do something, such as open a file, send a packet or start another program. Whether the attack succeeds is decided at that moment, by the kernel, based on who the process is and what it is allowed to do. A web server bug that lets an attacker run commands is bad; whether it means "read one website's files" or "read every password hash on the machine" depends entirely on the identity the server process runs under.

This lesson looks at that decision point from the security side. The mechanics of processes and system calls are taught in the OS course (processes, user and kernel mode, system calls); here we focus on the identity a process carries, how the kernel checks it, and how defenders use the same mechanism to observe and restrict programs.

The model: one gatekeeper

user mode process: uid 1000 open("/etc/shadow", O_RDONLY) kernel mode seccomp uid/gid, mode capabilities LSM EACCES every check must pass before the kernel touches the file

A process cannot touch hardware, files or other processes directly. It runs in user mode and asks the kernel through a system call (openat, read, execve, connect, kill…). The CPU switches to kernel mode, and the kernel checks the request against the process's credentials before doing anything. That single choke point is what makes access control enforceable at all.

What a process carries

On Linux Meaning Security role
Real UID / GID The user who started it Who to bill, who may signal it
Effective UID / GID The identity used for permission checks Differs from the real UID in SUID programs such as passwd
Saved UID Lets a program drop privileges and take them back Programs that drop root should drop it permanently
Supplementary groups Extra groups (e.g. docker, adm) Membership in some groups is as good as root (docker)
Capabilities Pieces of root's power: CAP_NET_BIND_SERVICE, CAP_SYS_ADMIN, CAP_DAC_OVERRIDE… Grant one power instead of full root
Seccomp filter A list of system calls the process may make Sandboxes (browsers, containers) refuse whole classes of calls
LSM label SELinux or AppArmor context Mandatory rules on top of ordinary permissions
no_new_privs Once set, execve can never gain privileges (SUID bits are ignored) Used by container runtimes and systemd's NoNewPrivileges=

Windows has the same idea under different names: every process carries an access token with the user's SID, group SIDs, privileges such as SeDebugPrivilege and an integrity level, and the kernel's Security Reference Monitor compares it with each object's access-control list. That is the subject of Windows accounts and tokens.

Looking at a process's identity

Your sandbox session runs as the unprivileged user learner, without network. Every Linux process exposes its credentials in /proc/<pid>/status; self is the process reading the file:

bash · try it yourself
id
grep -E '^(Uid|Gid|Groups|CapEff|CapBnd|NoNewPrivs|Seccomp):' /proc/self/status
cat /etc/shadow; echo "exit code: $?"
uid=1000(learner) gid=1000(learner) groups=1000(learner)
Uid:	1000	1000	1000	1000
Gid:	1000	1000	1000	1000
Groups:	1000
CapEff:	0000000000000000
CapBnd:	00000000a80425fb
NoNewPrivs:	0
Seccomp:	2
cat: /etc/shadow: Permission denied
exit code: 1

The four Uid numbers are real, effective, saved and file-system UID, all 1000. CapEff (effective capabilities) is zero: no root powers at all. CapBnd is the bounding set, the most this process tree could ever gain; container runtimes shrink it, which is why even root inside a container is weaker than root on the host. Seccomp: 2 means a seccomp filter is installed (Docker's default profile). And the attempt to read the password hashes fails, as it should: /etc/shadow is readable only by root and the shadow group.

Watching the decision with strace

strace uses the kernel's tracing interface to print every system call a program makes and the kernel's answer. It is a debugging tool, and also the simplest way to see access control happen:

bash · try it yourself
strace -f -e trace=execve,openat -o trace.txt cat /etc/shadow /opt/sec-samples/files/hello.txt
grep -E 'execve|shadow|hello' trace.txt | sed -E 's/^[0-9]+ +//; s|, 0x[0-9a-f]+ /\* [0-9]+ vars \*/|, <environment>|'
cat: /etc/shadow: Permission denied
Hello from the lab.
This file is plain ASCII text.
execve("/usr/bin/cat", ["cat", "/etc/shadow", "/opt/sec-samples/files/hello.txt"], <environment>) = 0
openat(AT_FDCWD, "/etc/shadow", O_RDONLY) = -1 EACCES (Permission denied)
openat(AT_FDCWD, "/opt/sec-samples/files/hello.txt", O_RDONLY) = 3

(The sed drops the line prefix and the address of the environment block, which change from run to run.) The same program, the same system call, two answers: -1 EACCES for the protected file and a file descriptor (= 3) for the readable one. Nothing in cat decides this; the kernel does, from the effective UID and the file's mode bits. File permissions themselves are the subject of Linux users, groups and permissions.

Detection: system calls as evidence

What strace shows for one process, security tools collect for the whole machine:

  • auditd (the Linux audit framework) logs chosen system calls with the process's real and effective UIDs: every execve, every failed openat on /etc/shadow, every change to /etc/sudoers. A burst of EACCES results from a web server process is a sign of someone probing.
  • EDR agents and tools like Falco hook system calls or eBPF tracepoints and match rules such as "a shell spawned by a database process" or "a process read /etc/shadow and then opened a network connection".
  • On Windows, Sysmon and the Security log record process creation (event 4688 / Sysmon 1) with the parent process and the token's integrity level.

The key fields to collect are always the same: who (real and effective identity), what (call and arguments), from where (parent process, command line) and with what result.

Prevention: run with less

The defensive lesson of this model is least privilege at the process level:

  • Run services under their own unprivileged account, never as root, and give them a capability instead of root when they need one power (CAP_NET_BIND_SERVICE to listen on port 443).
  • Drop privileges early and permanently after the one privileged step, and set no_new_privs.
  • Add a seccomp filter and an AppArmor or SELinux profile, so that even code execution inside the service can't make the calls an attacker needs. systemd makes this a few lines in the unit file (service sandboxing).
  • Keep group memberships short: being in docker, disk or adm grants much more than it sounds.

Pitfalls

  • "It runs in a container, so it is safe." A container is a process with namespaces, a smaller capability set and a seccomp filter. Run as root with --privileged and most of that is gone.
  • Confusing real and effective identity. Logs that record only the real UID miss what a SUID program did as root.
  • Capabilities as a free pass. CAP_SYS_ADMIN is close to full root; CAP_DAC_OVERRIDE bypasses every file permission. Grant the narrow ones.
  • Tracing in production without care. strace slows a process down considerably and shows its data, including secrets. On real systems, use the audit framework or eBPF tools with filters.

Practice

  1. A process has real UID 1000 and effective UID 0. What kind of program is it probably running, and whose permissions does the kernel apply to its openat calls?
  2. Why does a web server that needs port 443 not need to run as root?
Answers
  1. A SUID-root program (such as passwd) started by user 1000. File-permission checks use the effective UID, so the kernel treats its openat calls as root's. That is exactly why every SUID-root program must be small and carefully written.
  2. Binding to a port below 1024 needs only CAP_NET_BIND_SERVICE. The service can get that one capability (systemd AmbientCapabilities=, or setcap on the binary), or start as root, bind, and drop to an unprivileged user, or sit behind a reverse proxy.

Test yourself

Where is the decision made whether cat /etc/shadow may read the file?

  1. In cat's source code
  2. In the shell
  3. In the kernel, when it handles the openat system call
  4. In the file itself

In the session, CapEff was 0000000000000000. What does that mean?

  1. The process has every capability
  2. The process has no effective capabilities: no part of root's power
  3. Seccomp is off
  4. The process is a zombie

What does no_new_privs prevent?

  1. Opening files
  2. Gaining privileges through execve, for example from SUID bits
  3. Creating child processes
  4. Network access

Which group membership on Linux is effectively equivalent to root?

  1. users
  2. docker
  3. audio
  4. plugdev