LSM: Configuring Too Many LSMs Causes Kernel Panic on Boot
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
linux (Ubuntu) |
Fix Released
|
Medium
|
Matthew Ruffell | ||
Jammy |
Fix Released
|
Medium
|
Matthew Ruffell | ||
Kinetic |
Fix Released
|
Medium
|
Matthew Ruffell | ||
linux-oem-6.0 (Ubuntu) |
Invalid
|
Undecided
|
Unassigned | ||
Jammy |
Fix Released
|
Medium
|
Thadeu Lima de Souza Cascardo | ||
Kinetic |
Invalid
|
Undecided
|
Unassigned | ||
linux-oem-6.1 (Ubuntu) |
Invalid
|
Undecided
|
Unassigned | ||
Jammy |
Fix Released
|
Medium
|
Thadeu Lima de Souza Cascardo | ||
Kinetic |
Invalid
|
Undecided
|
Unassigned |
Bug Description
BugLink: https:/
[Impact]
The Ubuntu kernel carries an out of tree patchet, known as "LSM: Module stacking for AppArmor" upstream, to enable stackable LSMs for containers. The revision the Ubuntu kernel carries is an older one, from 2020, and has some slight divergences from the latest revision in development.
One such divergence, is support for Landlock as a stackable LSM. When the stackable LSM patchset was applied, Landlock was still in development and not mainlined yet, and wasn't present in the earlier revision of the "LSM: Module stacking for AppArmor" patchset. Support for this was added by us.
There was a minor omission made during enabling support for Landlock. The LSM slot type was marked as LSMBLOB_NEEDED, when it should have been LSMBLOB_NOT_NEEDED.
Landlock itself does not provide any of the hooks that use a struct lsmblob, such as secid_to_secctx, secctx_to_secid, inode_getsecid, cred_getsecid, kernel_act_as task_getsecid_subj task_getsecid_obj and ipc_getsecid.
When we set .slot = LSMBLOB_NEEDED, this indicates that we need an entry in struct lsmblob, and we need to increment LSMBLOB_ENTRIES by one to fit the entry into the secid array:
#define LSMBLOB_ENTRIES ( \
struct lsmblob {
u32 secid[LSMBLOB_
};
Currently, we don't increment LSMBLOB_ENTRIES by one to make an entry for Landlock, so for the Ubuntu kernel, we can fit a maximum of two entries, one for Apparmor and one for bpf.
If you try and configure three LSMs like so and reboot:
GRUB_CMDLINE_
You will receive the following panic:
LSM: Security Framework initializing
landlock: Up and running.
LSM support for eBPF active
Kernel panic - not syncing: security_add_hooks Too many LSMs registered.
CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.15.0-46-generic #49-Ubuntu
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.15.0-1 04/01/2014
Call Trace:
<TASK>
show_stack+
dump_stack_
dump_stack+
panic+0x149/0x321
security_
apparmor_
initialize_
ordered_
security_
start_
x86_64_
x86_64_
secondary_
</TASK>
---[ end Kernel panic - not syncing: security_add_hooks Too many LSMs registered. ]---
There is a check added in security_
if (lsmid->slot == LSMBLOB_NEEDED) {
if (lsm_slot >= LSMBLOB_ENTRIES)
panic("%s Too many LSMs registered.\n", __func__);
lsmid->slot = lsm_slot++;
init_debug("%s assigned lsmblob slot %d\n", lsmid->lsm,
lsmid->slot);
}
A workaround is to enable no more than 2 LSMs until this is fixed.
[Fix]
If you read the following mailing list thread on linux-security-
https:/
It is explained that Landlock does not provide any of the hooks that use a struct lsmblob, such as secid_to_secctx, secctx_to_secid, inode_getsecid, cred_getsecid, kernel_act_as task_getsecid_subj task_getsecid_obj and ipc_getsecid.
I verified this with:
ubuntu-jammy$ grep -Rin "secid_to_secctx" security/landlock/
ubuntu-jammy$ grep -Rin "secctx_to_secid" security/landlock/
ubuntu-jammy$ grep -Rin "inode_getsecid" security/landlock/
ubuntu-jammy$ grep -Rin "cred_getsecid" security/landlock/
ubuntu-jammy$ grep -Rin "kernel_act_as" security/landlock/
ubuntu-jammy$ grep -Rin "task_getsecid_
ubuntu-jammy$ grep -Rin "task_getsecid_obj" security/landlock/
ubuntu-jammy$ grep -Rin "ipc_getsecid" security/landlock/
The fix is to change Landlock from LSMBLOB_NEEDED to LSMBLOB_NOT_NEEDED.
Due to the "LSM: Module stacking for AppArmor" patchset being 25 patches long, it was impractical to revert just the below patch and reapply with the fix, due to a large amount of conflicts:
commit f17b27a2790e721
Author: Casey Schaufler <email address hidden>
Date: Mon Aug 17 16:02:56 2020 -0700
Subject: UBUNTU: SAUCE: LSM: Create and manage the lsmblob data structure.
Link: https:/
So instead, I wrote up a fix that just changes the Landlock LSM slots to follow the latest upstream development, from V37 of the patchset:
https://<email address hidden>/
I refactored the landlock_lsmid struct to only be in one place, and to be marked as extern from security/
[Testcase]
Launch a Jammy or Kinetic VM.
1. Edit /etc/default/grub and append the following to GRUB_CMDLINE_
"lsm=landlock,
2. sudo update-grub
3. reboot
The system will panic on boot.
If you install the test kernel from the following ppa:
https:/
Instead of a panic occurring, the kernel should display all LSMs initialising, and continue to boot.
[ 0.288224] LSM: Security Framework initializing
[ 0.289457] landlock: Up and running.
[ 0.290290] LSM support for eBPF active
[ 0.291189] AppArmor: AppArmor initialized
[Where problems could occur]
The risk of regression in changing Landlock from LSMBLOB_NEEDED to LSMBLOB_NOT_NEEDED is low, due to Landlock not needing a slot in the secid array in struct lsmblob in the first place.
The refactor is minor and unlikely to introduce any issues with Landlock or its security promises.
I feel that simply fixing this small bug is less regression risk than reverting the entire 25 patch patchset and applying the latest V37 upstream patchset, which has undergone significant changes from mid 2020. I think its best we consume the newer patchset once it makes its way into mainline in a future kernel instead.
If a regression were to occur, users could configure 2 LSMs instead of all 3, or not enable Landlock.
[Other Info]
This patchset was originally NACKed by Stefan Bader on request of John Johansen due to a minor misunderstanding on how LSMBLOB_NEEDED worked with blob slot registration.
ACK:
https:/
Applied:
https:/
NACK:
https:/
Revert:
https:/
This led to a off list discussion between myself, Stefan bader, Andrea Righi, John Johansen, Jay Vosburgh and Tim Gardner:
Subject:
Please Re-review LSM Stacking Patchset fix - Change Landlock from LSMBLOB_NEEDED to LSMBLOB_NOT_NEEDED
The discussion uses largely information found in this SRU template, plus some additional information from mailing list threads highlighting why it is safe to move to LSMBLOB_NOT_NEEDED.
From Matthew Ruffell
https:/
From John Johansen
https:/
https:/
From Matthew Ruffell
https:/
From Stefan Bader
https:/
Now that the misunderstanding has been cleared up, and the patchset has been double checked and approved by the Security Team, resubmitting the initial patch as V2.
Changed in linux (Ubuntu Jammy): | |
status: | New → In Progress |
Changed in linux (Ubuntu Kinetic): | |
status: | New → In Progress |
Changed in linux (Ubuntu Jammy): | |
importance: | Undecided → Medium |
Changed in linux (Ubuntu Kinetic): | |
importance: | Undecided → Medium |
Changed in linux (Ubuntu Jammy): | |
assignee: | nobody → Matthew Ruffell (mruffell) |
Changed in linux (Ubuntu Kinetic): | |
assignee: | nobody → Matthew Ruffell (mruffell) |
description: | updated |
tags: | added: jammy kinetic sts |
description: | updated |
Changed in linux (Ubuntu Kinetic): | |
status: | In Progress → Fix Committed |
Changed in linux (Ubuntu Jammy): | |
status: | In Progress → Fix Committed |
Changed in linux-oem-6.0 (Ubuntu Kinetic): | |
status: | New → Invalid |
Changed in linux-oem-6.0 (Ubuntu): | |
status: | New → Invalid |
Changed in linux-oem-6.0 (Ubuntu Jammy): | |
status: | New → In Progress |
assignee: | nobody → Thadeu Lima de Souza Cascardo (cascardo) |
importance: | Undecided → Medium |
Changed in linux-oem-6.0 (Ubuntu Jammy): | |
status: | In Progress → Fix Committed |
Changed in linux-oem-6.1 (Ubuntu Kinetic): | |
status: | New → Invalid |
Changed in linux-oem-6.1 (Ubuntu Jammy): | |
status: | New → In Progress |
importance: | Undecided → Medium |
assignee: | nobody → Thadeu Lima de Souza Cascardo (cascardo) |
Changed in linux-oem-6.1 (Ubuntu): | |
status: | New → Invalid |
Changed in linux-oem-6.1 (Ubuntu Jammy): | |
status: | In Progress → Fix Committed |
This bug is awaiting verification that the linux/5.15.0-53.59 kernel in -proposed solves the problem. Please test the kernel and update this bug with the results. If the problem is solved, change the tag 'verification- needed- jammy' to 'verification- done-jammy' . If the problem still exists, change the tag 'verification- needed- jammy' to 'verification- failed- jammy'.
If verification is not done by 5 working days from today, this fix will be dropped from the source code, and this bug will be closed.
See https:/ /wiki.ubuntu. com/Testing/ EnableProposed for documentation how to enable and use -proposed. Thank you!