1. namespaces ------------- sudo unshare --fork --pid --mount-proc bash ls ls /proc sudo unshare --fork --pid bash ls ls /proc sudo nsenter -t 30476 -a sudo nsenter -t 30476 -p -r ps aux ls -al /proc//ns pseudo-files for each kernel namespace supported by a process used by setns and nsenter to refer to per process namespaces https://elixir.bootlin.com/linux/v2.5.75/source/kernel/sys.c#L1175 https://elixir.bootlin.com/linux/v7.3/source/kernel/sys.c#L1447 https://elixir.bootlin.com/linux/latest/source/include/linux/sched.h#L737 The former implementation of gethostname(): ------------------------------------------ asmlinkage long sys_gethostname(char __user *name, int len) { .. if (copy_to_user(name, system_utsname.nodename, i)) errno = -EFAULT; } (system_utsname is a global) kernel/sys.c, Kernel v2.6.11.5 A new method called utsname() added: ----------------------------------- static inline struct new_utsname *utsname(void) { return ¤t->nsproxy->uts_ns->name; } The new implementation of gethostname(): SYSCALL_DEFINE2(gethostname, char __user *, name, int, len) { struct new_utsname *u; ... u = utsname(); if (copy_to_user(name, u->nodename, i)) errno = -EFAULT; ------- hostname example puru@synerg:~$ puru@synerg:~$ sudo unshare --fork --pid --mount-proc bash [sudo] password for puru: root@synerg:~# hostname synerg root@synerg:~# hostname newsynerg root@synerg:~# hostname newsynerg root@synerg:~# exit puru@synerg:~$ sudo unshare --fork -u --pid --mount-proc bash root@synerg:~# hostname newsynerg root@synerg:~# hostname newsynerg root@synerg:~# 2. cgroups ----------- /proc/cgroups /proc//cgroup /* cgroup information */ The path to the cgroup relative to the cgroup root mount point (/sys/fs/cgroup). ls -al /sys/fs/cgroup/ /* cgroup operations interaction, cgroup controllers */ (show mount points of different processes) mkdir /sys/fs/cgroup/memory/mygroup echo $$ > /sys/fs/cgroup/memory/mygroup/tasks echo 1M > /sys/fs/cgroup/memory/mygroup/memory.limit_in_bytes echo 1 > /sys/fs/cgroup/memory/mygroup/memory.oom_control ~puru/temp/a.out echo 0 > /sys/fs/cgroup/memory/mygroup/memory.oom_control do_exit https://elixir.bootlin.com/linux/latest/source/kernel/exit.c#L805 cgroup_exit https://elixir.bootlin.com/linux/latest/source/kernel/cgroup/cgroup.c#L6662 struct css_set https://elixir.bootlin.com/linux/latest/source/include/linux/cgroup-defs.h#L212 *cgroups https://elixir.bootlin.com/linux/latest/source/include/linux/sched.h#L1221 3. chroot + images chroot --- change the root directory for a (running) process chroot /home/puru/temp/ bash ldd /bin/bash linux-vdso.so.1 - virtual shared library loaded in each processes memory by kernel to speed up system calls no file backing cp /lib/x86_64-linux-gnu/libtinfo.so.5 /lib/x86_64-linux-gnu/libdl.so.2 /lib/x86_64-linux-gnu/libc.so.6 temp/lib cp /lib64/ld-linux-x86-64.so.2 temp/lib64/ chroot /home/puru/temp/ bash ls ldd /bin/ls cp /lib/x86_64-linux-gnu/libselinux.so.1 /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libpcre.so.3 /lib/x86_64-linux-gnu/libdl.so.2 /lib/x86_64-linux-gnu/libpthread.so.0 temp/lib cp /lib64/ld-linux-x86-64.so.2 temp/lib64 chroot /home/puru/temp/ bash ls 4. capabilities - https://man7.org/linux/man-pages/man7/capabilities.7.html - sudo getpcaps - sudo capsh --drop=all --print -- -c "/usr/bin/ping -c 4 8.8.8.8" - seccomp_policy.c - - docker run --cap-drop=ALL --cap-add=NET_RAW ... - docker run seccomp=profile.json