Securing the Linux kernel with lockdown mode
Lock It Up
Lockdown mode makes your Linux system more secure and even prevents root users from modifying the kernel.
The term lockdown does not have particularly positive connotations at present, but prior to COVID-19, the word was used in a very positive context as a term for air-tight security. Several months ago, Linux boss Linus Torvalds accepted a series of patches for the Linux kernel that introduced what is known as lockdown mode. Lockdown mode puts limits on the power of system users – including the once-all-powerful system administrator (root) account. Putting constraints on the root account might seem very strange to Unix/Linux veterans, but security experts are happy to see this powerful new feature in our dangerous times.
Long Time Ago
When Linus finally incorporated the lockdown patches into the official kernel at the end 2019, many observers described lockdown mode as a revolutionary new feature. But lockdown mode is not a new invention. In fact, the work on implementing the function took almost seven years. And for most of that time, the Linux kernel developers were arguing – sometimes heatedly – about the right way to do it (Figure 1). See the box entitled "Linux Security Modules" for more on a solution that arose from that heated debate.
Linux Security Modules
Some years ago, when Linux kernel developers began exploring ways to implement additional security features into the kernel, they soon realized the challenge would be to support different security technologies depending on the use case.
Compounding this problem was the need to ensure that the solution would allow different distributions to continue to develop their own independent security technologies. For example, Red Hat uses SELinux as its in-house solution for Mandatory Access Control, whereas Canonical and SUSE tend to use AppArmor.
Several years ago, Linux developers used a special trick to get the kernel to support both the Xen and KVM hypervisors: They implemented a framework that allowed KVM and Xen to tap into the same kernel functions.
The team used a similar trick for implementing alternative security technologies. The solution, which is known as Linux Security Modules (LSM), offers a uniform and orderly process for adding security features to the kernel. AppArmor and SELinux both use LSM, and Linus insisted on keeping lockdown mode compatible with LSM also.
The very generic LSM interface allows other code to hook into the kernel at certain points and implement security-related functions. This means that several LSM modules can be active in parallel. In other words, lockdown mode does not rule out the use of AppArmor and SELinux.
The use of the LSM interface has another great advantage: LSM has a policy interface to userland out of the box. In plain language, this means that the administrator can activate or deactivate certain security functions in the kernel, such as lockdown mode. However, the whole enchilada can then be configured from userspace, and, in fact, in a far more granular way than would be the case if it had to rely exclusively on kernel functions.
What's the Problem?
Which problem does the lockdown mechanism seek to solve? On a conventional Linux system, anyone with root privileges can do whatever they want. This means an attacker with sufficient privileges can change the core of the operating system and reload modules with new functionality. A highly sophisticated attacker can even replace central kernel features with their own versions of modules to deliberately cover their tracks.
Modern computers therefore try to defend themselves against this kind of attack on the firmware side. UEFI has a separate mechanism known as Secure Boot, which primarily affects the boot mode of the system. A system with active Secure Boot will only execute an OS boot loader if the boot loader has been digitally signed by a trusted party. The same applies to the kernel that this boot loader then starts. If Secure Boot is enabled, it also requires a digital signature. This is intended to create a chain of trust, thanks to which no malicious code ends up in the kernel.
The problem is, once an attacker gets past the boot loader, nothing in a conventional Linux system can prevent the loading of arbitrary modules. Even if the kernel is digitally signed, reloadable modules substantially weaken this security and the chain of trust breaks.
Lockdown mode can harden the kernel such that even the system user with the UID 0 is not allowed to change certain kernel structures.
Advanced LSM Features
To implement lockdown mode, the kernel developers had to expand the LSM stack. In its previous version, LSM was only designed to deal with problems once the userspace part (i.e., the environment that provides the kernel with policies) was active. However, an attacker could modify a system so that it loads malicious code immediately after start-up.
Part of the lockdown patch was therefore a new LSM module for early-stage security, which is loaded immediately after the kernel is started. At this time, the module has practically no kernel features available, and not even memory can be requested using malloc()
. However, an end-to-end security strategy is in place. Once the early stage module is loaded, all necessary precautions at this time will take effect as specified by the administrator.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.
-
Juno Tab 3 Launches with Ubuntu 24.04
Anyone looking for a full-blown Linux tablet need look no further. Juno has released the Tab 3.
-
New KDE Slimbook Plasma Available for Preorder
Powered by an AMD Ryzen CPU, the latest KDE Slimbook laptop is powerful enough for local AI tasks.
-
Rhino Linux Announces Latest "Quick Update"
If you prefer your Linux distribution to be of the rolling type, Rhino Linux delivers a beautiful and reliable experience.
-
Plasma Desktop Will Soon Ask for Donations
The next iteration of Plasma has reached the soft feature freeze for the 6.2 version and includes a feature that could be divisive.
-
Linux Market Share Hits New High
For the first time, the Linux market share has reached a new high for desktops, and the trend looks like it will continue.
-
LibreOffice 24.8 Delivers New Features
LibreOffice is often considered the de facto standard office suite for the Linux operating system.
-
Deepin 23 Offers Wayland Support and New AI Tool
Deepin has been considered one of the most beautiful desktop operating systems for a long time and the arrival of version 23 has bolstered that reputation.