Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1617210 > unrolled thread
| Started by | David Howells <dhowells@redhat.com> |
|---|---|
| First post | 2017-04-05 19:20 +0200 |
| Last post | 2017-04-06 10:40 +0200 |
| Articles | 6 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH 00/24] Kernel lockdown David Howells <dhowells@redhat.com> - 2017-04-05 19:20 +0200
[PATCH 12/24] PCI: Lock down BAR access when the kernel is locked down David Howells <dhowells@redhat.com> - 2017-04-05 19:20 +0200
[PATCH 03/24] efi: Lock down the kernel if booted in secure boot mode David Howells <dhowells@redhat.com> - 2017-04-05 19:20 +0200
Re: [PATCH 00/24] Kernel lockdown David Howells <dhowells@redhat.com> - 2017-04-05 22:00 +0200
Re: [PATCH 00/24] Kernel lockdown James Morris <jmorris@namei.org> - 2017-04-06 10:30 +0200
Re: [PATCH 00/24] Kernel lockdown David Howells <dhowells@redhat.com> - 2017-04-06 10:40 +0200
| From | David Howells <dhowells@redhat.com> |
|---|---|
| Date | 2017-04-05 19:20 +0200 |
| Subject | [PATCH 00/24] Kernel lockdown |
| Message-ID | <tsWL8-5w8-5@gated-at.bofh.it> |
These patches provide a facility by which a variety of avenues by which
userspace can feasibly modify the running kernel image can be locked down.
These include:
(*) No unsigned modules and no modules for which can't validate the
signature.
(*) No use of ioperm(), iopl() and no writing to /dev/port.
(*) No writing to /dev/mem or /dev/kmem.
(*) No hibernation.
(*) Restrict PCI BAR access.
(*) Restrict MSR access.
(*) No kexec_load().
(*) Certain ACPI restrictions.
(*) Restrict debugfs interface to ASUS WMI.
The lock-down can be configured to be triggered by the EFI secure boot
status, provided the shim isn't insecure. The lock-down can be lifted by
typing SysRq+x on a keyboard attached to the system.
The patches can be found here also:
http://git.kernel.org/cgit/linux/kernel/git/dhowells/linux-fs.git/log/?h=efi-lockdown
They are dependent on the hwparam branch, which I posted separately.
David
---
Chun-Yi Lee (1):
kexec_file: Disable at runtime if securelevel has been set
Dave Young (1):
Copy secure_boot flag in boot params across kexec reboot
David Howells (7):
Add the ability to lock down access to the running kernel image
efi: Lock down the kernel if booted in secure boot mode
Enforce module signatures if the kernel is locked down
scsi: Lock down the eata driver
Prohibit PCMCIA CIS storage when the kernel is locked down
Lock down TIOCSSERIAL
Lock down module params that specify hardware parameters (eg. ioport)
Josh Boyer (3):
efi: Add EFI_SECURE_BOOT bit
hibernate: Disable when the kernel is locked down
acpi: Ignore acpi_rsdp kernel param when the kernel has been locked down
Kyle McMartin (1):
Add a sysrq option to exit secure boot mode
Lee, Chun-Yi (1):
bpf: Restrict kernel image access functions when the kernel is locked down
Linn Crosetto (2):
acpi: Disable ACPI table override if the kernel is locked down
acpi: Disable APEI error injection if the kernel is locked down
Matthew Garrett (8):
Restrict /dev/mem and /dev/kmem when the kernel is locked down
kexec: Disable at runtime if the kernel is locked down
uswsusp: Disable when the kernel is locked down
PCI: Lock down BAR access when the kernel is locked down
x86: Lock down IO port access when the kernel is locked down
x86: Restrict MSR access when the kernel is locked down
asus-wmi: Restrict debugfs interface when the kernel is locked down
ACPI: Limit access to custom_method when the kernel is locked down
arch/x86/Kconfig | 22 ++++++++++++++++++++
arch/x86/kernel/ioport.c | 4 ++--
arch/x86/kernel/kexec-bzimage64.c | 1 +
arch/x86/kernel/msr.c | 7 ++++++
arch/x86/kernel/setup.c | 40 ++++++++++++++++++++++++++++++++++++-
drivers/acpi/apei/einj.c | 3 +++
drivers/acpi/custom_method.c | 3 +++
drivers/acpi/osl.c | 2 +-
drivers/acpi/tables.c | 5 +++++
drivers/char/mem.c | 8 +++++++
drivers/input/misc/uinput.c | 1 +
drivers/pci/pci-sysfs.c | 9 ++++++++
drivers/pci/proc.c | 8 ++++++-
drivers/pci/syscall.c | 2 +-
drivers/pcmcia/cistpl.c | 5 +++++
drivers/platform/x86/asus-wmi.c | 9 ++++++++
drivers/scsi/eata.c | 7 ++++++
drivers/tty/serial/serial_core.c | 6 ++++++
drivers/tty/sysrq.c | 19 ++++++++++++------
include/linux/efi.h | 1 +
include/linux/input.h | 5 +++++
include/linux/kernel.h | 9 ++++++++
include/linux/security.h | 11 ++++++++++
include/linux/sysrq.h | 8 ++++++-
kernel/debug/kdb/kdb_main.c | 2 +-
kernel/kexec.c | 7 ++++++
kernel/kexec_file.c | 6 ++++++
kernel/module.c | 2 +-
kernel/params.c | 27 ++++++++++++++++++++-----
kernel/power/hibernate.c | 2 +-
kernel/power/user.c | 3 +++
kernel/trace/bpf_trace.c | 11 ++++++++++
security/Kconfig | 15 ++++++++++++++
security/Makefile | 3 +++
security/lock_down.c | 40 +++++++++++++++++++++++++++++++++++++
35 files changed, 291 insertions(+), 22 deletions(-)
create mode 100644 security/lock_down.c
[toc] | [next] | [standalone]
| From | David Howells <dhowells@redhat.com> |
|---|---|
| Date | 2017-04-05 19:20 +0200 |
| Subject | [PATCH 12/24] PCI: Lock down BAR access when the kernel is locked down |
| Message-ID | <tsWL9-5w8-35@gated-at.bofh.it> |
| In reply to | #1617210 |
From: Matthew Garrett <matthew.garrett@nebula.com>
Any hardware that can potentially generate DMA has to be locked down in
order to avoid it being possible for an attacker to modify kernel code,
allowing them to circumvent disabled module loading or module signing.
Default to paranoid - in future we can potentially relax this for
sufficiently IOMMU-isolated devices.
Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>
Signed-off-by: David Howells <dhowells@redhat.com>
---
drivers/pci/pci-sysfs.c | 9 +++++++++
drivers/pci/proc.c | 8 +++++++-
drivers/pci/syscall.c | 2 +-
3 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 25d010d449a3..f70b3668036f 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -727,6 +727,9 @@ static ssize_t pci_write_config(struct file *filp, struct kobject *kobj,
loff_t init_off = off;
u8 *data = (u8 *) buf;
+ if (kernel_is_locked_down())
+ return -EPERM;
+
if (off > dev->cfg_size)
return 0;
if (off + count > dev->cfg_size) {
@@ -1018,6 +1021,9 @@ static int pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr,
resource_size_t start, end;
int i;
+ if (kernel_is_locked_down())
+ return -EPERM;
+
for (i = 0; i < PCI_ROM_RESOURCE; i++)
if (res == &pdev->resource[i])
break;
@@ -1117,6 +1123,9 @@ static ssize_t pci_write_resource_io(struct file *filp, struct kobject *kobj,
struct bin_attribute *attr, char *buf,
loff_t off, size_t count)
{
+ if (kernel_is_locked_down())
+ return -EPERM;
+
return pci_resource_io(filp, kobj, attr, buf, off, count, true);
}
diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
index f82710a8694d..139d6f09ae7b 100644
--- a/drivers/pci/proc.c
+++ b/drivers/pci/proc.c
@@ -116,6 +116,9 @@ static ssize_t proc_bus_pci_write(struct file *file, const char __user *buf,
int size = dev->cfg_size;
int cnt;
+ if (kernel_is_locked_down())
+ return -EPERM;
+
if (pos >= size)
return 0;
if (nbytes >= size)
@@ -195,6 +198,9 @@ static long proc_bus_pci_ioctl(struct file *file, unsigned int cmd,
#endif /* HAVE_PCI_MMAP */
int ret = 0;
+ if (kernel_is_locked_down())
+ return -EPERM;
+
switch (cmd) {
case PCIIOC_CONTROLLER:
ret = pci_domain_nr(dev->bus);
@@ -233,7 +239,7 @@ static int proc_bus_pci_mmap(struct file *file, struct vm_area_struct *vma)
struct pci_filp_private *fpriv = file->private_data;
int i, ret, write_combine;
- if (!capable(CAP_SYS_RAWIO))
+ if (!capable(CAP_SYS_RAWIO) || kernel_is_locked_down())
return -EPERM;
/* Make sure the caller is mapping a real resource for this device */
diff --git a/drivers/pci/syscall.c b/drivers/pci/syscall.c
index 9bf993e1f71e..c09524738ceb 100644
--- a/drivers/pci/syscall.c
+++ b/drivers/pci/syscall.c
@@ -92,7 +92,7 @@ SYSCALL_DEFINE5(pciconfig_write, unsigned long, bus, unsigned long, dfn,
u32 dword;
int err = 0;
- if (!capable(CAP_SYS_ADMIN))
+ if (!capable(CAP_SYS_ADMIN) || kernel_is_locked_down())
return -EPERM;
dev = pci_get_bus_and_slot(bus, dfn);
[toc] | [prev] | [next] | [standalone]
| From | David Howells <dhowells@redhat.com> |
|---|---|
| Date | 2017-04-05 19:20 +0200 |
| Subject | [PATCH 03/24] efi: Lock down the kernel if booted in secure boot mode |
| Message-ID | <tsWL9-5w8-41@gated-at.bofh.it> |
| In reply to | #1617210 |
UEFI Secure Boot provides a mechanism for ensuring that the firmware will
only load signed bootloaders and kernels. Certain use cases may also
require that all kernel modules also be signed. Add a configuration option
that to lock down the kernel - which includes requiring validly signed
modules - if the kernel is secure-booted.
Signed-off-by: David Howells <dhowells@redhat.com>
---
arch/x86/Kconfig | 12 ++++++++++++
arch/x86/kernel/setup.c | 8 +++++++-
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index cc98d5a294ee..21f39855661d 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -1817,6 +1817,18 @@ config EFI_MIXED
If unsure, say N.
+config EFI_SECURE_BOOT_LOCK_DOWN
+ def_bool n
+ depends on EFI
+ prompt "Lock down the kernel when UEFI Secure Boot is enabled"
+ ---help---
+ UEFI Secure Boot provides a mechanism for ensuring that the firmware
+ will only load signed bootloaders and kernels. Certain use cases may
+ also require that all kernel modules also be signed and that
+ userspace is prevented from directly changing the running kernel
+ image. Say Y here to automatically lock down the kernel when a
+ system boots with UEFI Secure Boot enabled.
+
config SECCOMP
def_bool y
prompt "Enable seccomp to safely compute untrusted bytecode"
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 396285bddb93..85dfa745c442 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -69,6 +69,7 @@
#include <linux/crash_dump.h>
#include <linux/tboot.h>
#include <linux/jiffies.h>
+#include <linux/security.h>
#include <video/edid.h>
@@ -1185,7 +1186,12 @@ void __init setup_arch(char **cmdline_p)
break;
case efi_secureboot_mode_enabled:
set_bit(EFI_SECURE_BOOT, &efi.flags);
- pr_info("Secure boot enabled\n");
+ if (IS_ENABLED(CONFIG_EFI_SECURE_BOOT_LOCK_DOWN)) {
+ lock_kernel_down();
+ pr_info("Secure boot enabled and kernel locked down\n");
+ } else {
+ pr_info("Secure boot enabled\n");
+ }
break;
default:
pr_info("Secure boot could not be determined\n");
[toc] | [prev] | [next] | [standalone]
| From | David Howells <dhowells@redhat.com> |
|---|---|
| Date | 2017-04-05 22:00 +0200 |
| Message-ID | <tsZfX-6W2-17@gated-at.bofh.it> |
| In reply to | #1617210 |
Let me try sending this again again. Lee, Chun-Yi as a name causes the mail dispatcher to break :-/ David
[toc] | [prev] | [next] | [standalone]
| From | James Morris <jmorris@namei.org> |
|---|---|
| Date | 2017-04-06 10:30 +0200 |
| Message-ID | <ttaXL-63S-19@gated-at.bofh.it> |
| In reply to | #1617210 |
On Wed, 5 Apr 2017, David Howells wrote: > The patches can be found here also: > > http://git.kernel.org/cgit/linux/kernel/git/dhowells/linux-fs.git/log/?h=efi-lockdown > Do you mean the branch 'efi-lock-down' ? -- James Morris <jmorris@namei.org>
[toc] | [prev] | [next] | [standalone]
| From | David Howells <dhowells@redhat.com> |
|---|---|
| Date | 2017-04-06 10:40 +0200 |
| Message-ID | <ttb7s-66T-5@gated-at.bofh.it> |
| In reply to | #1617587 |
James Morris <jmorris@namei.org> wrote: > > The patches can be found here also: > > > > http://git.kernel.org/cgit/linux/kernel/git/dhowells/linux-fs.git/log/?h=efi-lockdown > > > > Do you mean the branch 'efi-lock-down' ? Sorry, yes. David
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web