History

efi/efi_test: Lock down /dev/efi_test and require CAP_SYS_ADMIN

The driver exposes EFI runtime services to user-space through an IOCTL interface, calling the EFI services function pointers directly without using the efivar API. Disallow access to the /dev/efi_test character device when the kernel is locked down to prevent arbitrary user-space to call EFI runtime services. Also require CAP_SYS_ADMIN to open the chardev to prevent unprivileged users to call the EFI runtime services, instead of just relying on the chardev file mode bits for this. The main user of this driver is the fwts [0] tool that already checks if the effective user ID is 0 and fails otherwise. So this change shouldn't cause any regression to this tool. [0]: https://wiki.ubuntu.com/FirmwareTestSuite/Reference/uefivarinfo

Javier Martinez Canillas committed 7 years ago

Commit 359efcc1 parent 220dd763 files · +10 −0Browse files

Unified · Split

3 files
  1. drivers/firmware/efi/test/efi_test.c +8 −0
  2. include/linux/security.h +1 −0
  3. security/lockdown/lockdown.c +1 −0
drivers/firmware/efi/test/efi_test.c+8−0
@@ -14,6 +14,7 @@ · 13 unmodified lines
1414 #include <linux/init.h>
1515 #include <linux/proc_fs.h>
1616 #include <linux/efi.h>
17+#include <linux/security.h>
1718 #include <linux/slab.h>
1819 #include <linux/uaccess.h>
1920
@@ -717,6 +718,13 @@ static long efi_test_ioctl(struct file *file, unsigned int cmd, · 697 unmodified lines
717718
718719 static int efi_test_open(struct inode *inode, struct file *file)
719720 {
721+ int ret = security_locked_down(LOCKDOWN_EFI_TEST);
722+
723+ if (ret)
724+ return ret;
725+
726+ if (!capable(CAP_SYS_ADMIN))
727+ return -EACCES;
720728 /*
721729 * nothing special to do here
722730 * We do accept multiple open files at the same time as we
include/linux/security.h+1−0
@@ -105,6 +105,7 @@ enum lockdown_reason { · 104 unmodified lines
105105 LOCKDOWN_NONE,
106106 LOCKDOWN_MODULE_SIGNATURE,
107107 LOCKDOWN_DEV_MEM,
108+ LOCKDOWN_EFI_TEST,
108109 LOCKDOWN_KEXEC,
109110 LOCKDOWN_HIBERNATION,
110111 LOCKDOWN_PCI_ACCESS,
security/lockdown/lockdown.c+1−0
@@ -20,6 +20,7 @@ static const char *const lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1] = { · 19 unmodified lines
2020 [LOCKDOWN_NONE] = "none",
2121 [LOCKDOWN_MODULE_SIGNATURE] = "unsigned module loading",
2222 [LOCKDOWN_DEV_MEM] = "/dev/mem,kmem,port",
23+ [LOCKDOWN_EFI_TEST] = "/dev/efi_test access",
2324 [LOCKDOWN_KEXEC] = "kexec of unsigned images",
2425 [LOCKDOWN_HIBERNATION] = "hibernation",
2526 [LOCKDOWN_PCI_ACCESS] = "direct PCI access",

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t