The four process ID’s
For each process, Linux manages four UID’s. When a process from a user with UID 1000 is started/forked, then the new process has normally also the UID 1000.
However, with SUID/GUID it becomes more complicated, since processes can get other UIDs than the one of the caller. When a process like passwd is created from a “normal” user, the process runs as root.
$ ls -lah /usr/bin/passwd
-rwsr-xr-x 1 root root 139K 7. Jul 15:30 /usr/bin/passwd
$ ps aux | grep passw
root 16041 0.0 0.0 10148 3200 pts/4 S+ 17:14 0:00 passw
We can see al IDs via grep Uid /proc/$pid/status. In this case:
$ grep Uid /proc/16041/status
Uid: 1000 0 0 0
The four numbers mean the following:
- Real UID shows who owns the process.
- Effective UID shows the ID which the kernel uses to determine the permissions.
- Save Set UID shows the ID this process can get back later, if it decides to drop the effective UID before. Basically, when a process drops higher permissions, it can get it back later.
- Filesystem UID shows the ID for filesystem operations.
Linux capabilities
Capabilities in Linux are a more fine-grained access controll mechanism then the traditional user / root privileges. Instead of have root privileges, a process can be given specific powerful privileges.
Cababilities can be assigned (with +) or removed (with -) to executeables like this:
sudo setcap cap_net_bind_service=+ep /opt/app
In this example, the capability cap_net_bind_service is granted to the /opt/app binary. This means, that the application can bind to all ports, also <1024 as a normal user. Without capabilities, only a root user can bind to ports below 1024.
To see the capabilities of a binary:
getcap /usr/bin/myapp
AppArmor / ApplicationArmor
AppArmor is a kernel module for linux which can restrict access of processes. It can restrict the access of a process to specific resources.
Each binary can be protected via a AppArmor configuration, which is usually in the /etc/apparmor.d/ directory. An example:
/usr/bin/myapp {
# Capabilities
capability net_bind_service,
# Network Access
network inet stream,
# File Access Rules
/etc/myapp/config r,
/var/log/myapp/ rw,
}
This application can only bind to network services, acces the network and read / write the specific files.
The status can been seen this way:
aa-status
Leave a Reply
You must be logged in to post a comment.