Skip to content

Commit 359efcc

Browse files
martinezjavieringomolnar
authored andcommitted
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 Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Acked-by: Laszlo Ersek <lersek@redhat.com> Acked-by: Matthew Garrett <mjg59@google.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-efi@vger.kernel.org Link: https://lkml.kernel.org/r/20191029173755.27149-7-ardb@kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 220dd76 commit 359efcc

3 files changed

Lines changed: 10 additions & 0 deletions

File tree

‎drivers/firmware/efi/test/efi_test.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
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,
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‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ enum lockdown_reason {
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‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ static const char *const lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1] = {
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",

0 commit comments

Comments
 (0)