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
-
The Gnome Foundation Struggling to Stay Afloat
The foundation behind the Gnome desktop environment is having to go through some serious belt-tightening due to continued financial problems.
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.
-
OSI and LPI Form Strategic Alliance
With a goal of strengthening Linux and open source communities, this new alliance aims to nurture the growth of more highly skilled professionals.
-
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.