Hi, I’m in a process of making fast, (extrenely) secure, and modern laptop. Currently I have Arch Linux with encrypted root partition (unlocked with Nitrokey or long password), secure boot, linux-hardened, firewalld, etc.
I’m running linux-hardened with custom config. I enabled AMD SME, kernel lockdown, added some xanmod patch for more specific cpus, and disabled some unnedded drivers (only those that I’m 100% sure I don’t need - Intel, NVidia, Microsoft, Google, Amazon, Virtio). Currently it takes ~50 minutes to recompile the kernel. Are there any tutorials what drivers to disable to speed up this process? After doing that I will try to compile it with -O3 and LTO. Do you know any patches for performance?
I’m planning to enable encrypted swap, install ClaimAV and install flatpak versions for every non open-source app I have.
I also want to have SELinux. Does anyone know where can I learn it? I had it on Fedora and it was not fun using it.
What are other ways I can make my laptop more secure?
Look into installing AppArmor instead of SELinux. AppArmor is easier to configure, and SELinux is not officially supported on Arch.
I will try it out, thank you :)
SELinux is a pain on Arch, it actually working nicely could be viewed as Fedora’s killer feature.
Running SELinux under a Linux distribution requires three things: An SELinux enabled kernel, SELinux Userspace tools and libraries, and SELinux Policies (mostly based on the Reference Policy). Some common Linux programs will also need to be patched/compiled with SELinux features.
Now I know why I didn’t bother with selinux back when I used arch. I never had any issues with it on fedora with zero maintenance.
There are also some kernel settings that you may find useful. Currently I am on the mobile and cannot remember the names. Text me if you need help
Network:
Enable rp and arp filter
Disable IP forwarding if you don’t use docker
Disable tcp timestamp
Disable icmp broadcast
Enable syncookies
Enable source route checking
Other:
Enable hard and soft link protection (it is may broke your system, use carefully)
Enable kptr restrict
Disable kexec
Disable sysrq
Enable randomize virtual memory address
Disable JIT for ebpf programms
Disable loading drivers via modprobe in live kernel.
Also check which hardware mitigations is disabled in your kernel. (Spectre, meltdawn) You may enable KASL
Also use selinux or apparmor. I prefer Selinux.
Enable auditd and configure it for auditing actions that your find useful.
Thank you for the list! Do you maybe know where can I find explanations what does each option do? I know only half of them and I already use some of them.
I will describe settings that are not so easy to google and a few new thoughts.
kptr restrict:
https://wiki.archlinux.org/title/security
https://lwn.net/Articles/420403/
Kexec:
You may google about mechanics, but basically, it is just a mechanism to ‘reexec’ your kernel to something different, usually another kernel, but you can boot netboot.xyz, for example.
But now imagine that it will boot a kernel that will dump the output of all your traffic, or will dump all your keyboard keypresses (keylogger).
These are unlikely scenarios. But I prefer to disable this feature since I don’t use it anyway.
Also, about keyloggers. Any program inside your X session may grab all your keyboard events. Literally last week I wrote a keylogger in rust in 70 lines of code. Therefore, use Wayland.
Ebpf JIT:
There I misleaded you.
There is some new information about JIT and security. See https://youtu.be/kvt4wdXEuRU?si=3imn8PAEbvgjWTU3
According to the update, you need to set bpf_jit_harden=2 and unprivileged_bpf_disabled=1. (Even unprivileged ebpf may crash your kernel. For some unknown reason, this is not recognized as a problem.)
Randomize virtual memory address:
systemd
If you use systemd your can use systemd-analyze tool to harden your units settings.
Also, I remember the tool you can use.
There are some security certifications - most used are pcidss or stig. There are guidelines to improve security.
You can use openscap with a profile (pcidss or stig or both) and it will check if your system satisfies these guidelines.
This may give you some thoughts.
Thank you very much for this detailed explanation! Looks like kptr and kexec are already disabled and enabled randomized virtual memory address in the hardened kernel. I will check for ebpf. Security certs seem interesting, I will defenetly look into them.
50 minutes seems way too long - I run Gentoo on a 2nd gen i5 and my kernel compile is always under 20 minutes.
You are using
make -j4
ormake -j(number of CPU cores)
for parallel compile, right?On laptop with Ryzen 5 5500U (12 threads) it takes 50 minutes and on desktop with Ryzen 7 3700X (16 threads) it takes 20 minutes. I use all threads to compile the kernel.
It compiles way waster with Gentoo, because it has minimal config. I used the default config from Arch repos and modified it. It’s full of unneeded drivers, but I’m scared of disabling them. I already disabled wrong drivers a few times and had to use different kernel to boot.
(arch still use systemd)
and linux still not have base system software sandboxed (you can’t enforce)
Currently it takes ~50 minutes to recompile the kernel
try make with -j
I have
-j12
who cares how much money do you have, perhaps you have smt enabled?