Skip to content

[CIQ 6.12.y] additional SecureBoot Lockdown patches #185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions arch/x86/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,8 @@ void __init setup_arch(char **cmdline_p)
if (efi_enabled(EFI_BOOT))
efi_init();

efi_set_secure_boot(boot_params.secure_boot);

reserve_ibft_region();
x86_init.resources.dmi_setup();

Expand Down Expand Up @@ -1070,20 +1072,6 @@ void __init setup_arch(char **cmdline_p)
/* Allocate bigger log buffer */
setup_log_buf(1);

if (efi_enabled(EFI_BOOT)) {
switch (boot_params.secure_boot) {
case efi_secureboot_mode_disabled:
pr_info("Secure boot disabled\n");
break;
case efi_secureboot_mode_enabled:
pr_info("Secure boot enabled\n");
break;
default:
pr_info("Secure boot could not be determined\n");
break;
}
}

reserve_initrd();

acpi_table_upgrade();
Expand Down
2 changes: 1 addition & 1 deletion ciq/configs/kernel-aarch64-64k-debug.config
Original file line number Diff line number Diff line change
Expand Up @@ -7830,7 +7830,7 @@ CONFIG_SECURITY_YAMA=y
# CONFIG_SECURITY_SAFESETID is not set
CONFIG_SECURITY_LOCKDOWN_LSM=y
CONFIG_SECURITY_LOCKDOWN_LSM_EARLY=y
# CONFIG_LOCK_DOWN_IN_EFI_SECURE_BOOT is not set
CONFIG_LOCK_DOWN_IN_EFI_SECURE_BOOT=y
CONFIG_LOCK_DOWN_KERNEL_FORCE_NONE=y
# CONFIG_LOCK_DOWN_KERNEL_FORCE_INTEGRITY is not set
# CONFIG_LOCK_DOWN_KERNEL_FORCE_CONFIDENTIALITY is not set
Expand Down
2 changes: 1 addition & 1 deletion ciq/configs/kernel-aarch64-64k.config
Original file line number Diff line number Diff line change
Expand Up @@ -7808,7 +7808,7 @@ CONFIG_SECURITY_YAMA=y
# CONFIG_SECURITY_SAFESETID is not set
CONFIG_SECURITY_LOCKDOWN_LSM=y
CONFIG_SECURITY_LOCKDOWN_LSM_EARLY=y
# CONFIG_LOCK_DOWN_IN_EFI_SECURE_BOOT is not set
CONFIG_LOCK_DOWN_IN_EFI_SECURE_BOOT=y
CONFIG_LOCK_DOWN_KERNEL_FORCE_NONE=y
# CONFIG_LOCK_DOWN_KERNEL_FORCE_INTEGRITY is not set
# CONFIG_LOCK_DOWN_KERNEL_FORCE_CONFIDENTIALITY is not set
Expand Down
2 changes: 1 addition & 1 deletion ciq/configs/kernel-aarch64-debug.config
Original file line number Diff line number Diff line change
Expand Up @@ -7836,7 +7836,7 @@ CONFIG_SECURITY_YAMA=y
# CONFIG_SECURITY_SAFESETID is not set
CONFIG_SECURITY_LOCKDOWN_LSM=y
CONFIG_SECURITY_LOCKDOWN_LSM_EARLY=y
# CONFIG_LOCK_DOWN_IN_EFI_SECURE_BOOT is not set
CONFIG_LOCK_DOWN_IN_EFI_SECURE_BOOT=y
CONFIG_LOCK_DOWN_KERNEL_FORCE_NONE=y
# CONFIG_LOCK_DOWN_KERNEL_FORCE_INTEGRITY is not set
# CONFIG_LOCK_DOWN_KERNEL_FORCE_CONFIDENTIALITY is not set
Expand Down
2 changes: 1 addition & 1 deletion ciq/configs/kernel-aarch64.config
Original file line number Diff line number Diff line change
Expand Up @@ -7814,7 +7814,7 @@ CONFIG_SECURITY_YAMA=y
# CONFIG_SECURITY_SAFESETID is not set
CONFIG_SECURITY_LOCKDOWN_LSM=y
CONFIG_SECURITY_LOCKDOWN_LSM_EARLY=y
# CONFIG_LOCK_DOWN_IN_EFI_SECURE_BOOT is not set
CONFIG_LOCK_DOWN_IN_EFI_SECURE_BOOT=y
CONFIG_LOCK_DOWN_KERNEL_FORCE_NONE=y
# CONFIG_LOCK_DOWN_KERNEL_FORCE_INTEGRITY is not set
# CONFIG_LOCK_DOWN_KERNEL_FORCE_CONFIDENTIALITY is not set
Expand Down
1 change: 1 addition & 0 deletions drivers/firmware/efi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ subdir-$(CONFIG_EFI_STUB) += libstub
obj-$(CONFIG_EFI_BOOTLOADER_CONTROL) += efibc.o
obj-$(CONFIG_EFI_TEST) += test/
obj-$(CONFIG_EFI_DEV_PATH_PARSER) += dev-path-parser.o
obj-$(CONFIG_EFI) += secureboot.o
obj-$(CONFIG_APPLE_PROPERTIES) += apple-properties.o
obj-$(CONFIG_EFI_RCI2_TABLE) += rci2-table.o
obj-$(CONFIG_EFI_EMBEDDED_FIRMWARE) += embedded-firmware.o
Expand Down
5 changes: 4 additions & 1 deletion drivers/firmware/efi/efi-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,10 @@ void __init efi_init(void)
{
struct efi_memory_map_data data;
u64 efi_system_table;
u32 secure_boot;

/* Grab UEFI information placed in FDT by stub */
efi_system_table = efi_get_fdt_params(&data);
efi_system_table = efi_get_fdt_params(&data, &secure_boot);
if (!efi_system_table)
return;

Expand All @@ -237,6 +238,8 @@ void __init efi_init(void)
return;
}

efi_set_secure_boot(secure_boot);

reserve_regions();
/*
* For memblock manipulation, the cap should come after the memblock_add().
Expand Down
124 changes: 93 additions & 31 deletions drivers/firmware/efi/efi.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <linux/memblock.h>
#include <linux/security.h>
#include <linux/notifier.h>
#include <linux/bsearch.h>

#include <asm/early_ioremap.h>

Expand Down Expand Up @@ -993,40 +994,101 @@ int efi_mem_type(unsigned long phys_addr)
return -EINVAL;
}

struct efi_error_code {
efi_status_t status;
int errno;
const char *description;
};

static const struct efi_error_code efi_error_codes[] = {
{ EFI_SUCCESS, 0, "Success"},
#if 0
{ EFI_LOAD_ERROR, -EPICK_AN_ERRNO, "Load Error"},
#endif
{ EFI_INVALID_PARAMETER, -EINVAL, "Invalid Parameter"},
{ EFI_UNSUPPORTED, -ENOSYS, "Unsupported"},
{ EFI_BAD_BUFFER_SIZE, -ENOSPC, "Bad Buffer Size"},
{ EFI_BUFFER_TOO_SMALL, -ENOSPC, "Buffer Too Small"},
{ EFI_NOT_READY, -EAGAIN, "Not Ready"},
{ EFI_DEVICE_ERROR, -EIO, "Device Error"},
{ EFI_WRITE_PROTECTED, -EROFS, "Write Protected"},
{ EFI_OUT_OF_RESOURCES, -ENOMEM, "Out of Resources"},
#if 0
{ EFI_VOLUME_CORRUPTED, -EPICK_AN_ERRNO, "Volume Corrupt"},
{ EFI_VOLUME_FULL, -EPICK_AN_ERRNO, "Volume Full"},
{ EFI_NO_MEDIA, -EPICK_AN_ERRNO, "No Media"},
{ EFI_MEDIA_CHANGED, -EPICK_AN_ERRNO, "Media changed"},
#endif
{ EFI_NOT_FOUND, -ENOENT, "Not Found"},
#if 0
{ EFI_ACCESS_DENIED, -EPICK_AN_ERRNO, "Access Denied"},
{ EFI_NO_RESPONSE, -EPICK_AN_ERRNO, "No Response"},
{ EFI_NO_MAPPING, -EPICK_AN_ERRNO, "No mapping"},
{ EFI_TIMEOUT, -EPICK_AN_ERRNO, "Time out"},
{ EFI_NOT_STARTED, -EPICK_AN_ERRNO, "Not started"},
{ EFI_ALREADY_STARTED, -EPICK_AN_ERRNO, "Already started"},
#endif
{ EFI_ABORTED, -EINTR, "Aborted"},
#if 0
{ EFI_ICMP_ERROR, -EPICK_AN_ERRNO, "ICMP Error"},
{ EFI_TFTP_ERROR, -EPICK_AN_ERRNO, "TFTP Error"},
{ EFI_PROTOCOL_ERROR, -EPICK_AN_ERRNO, "Protocol Error"},
{ EFI_INCOMPATIBLE_VERSION, -EPICK_AN_ERRNO, "Incompatible Version"},
#endif
{ EFI_SECURITY_VIOLATION, -EACCES, "Security Policy Violation"},
#if 0
{ EFI_CRC_ERROR, -EPICK_AN_ERRNO, "CRC Error"},
{ EFI_END_OF_MEDIA, -EPICK_AN_ERRNO, "End of Media"},
{ EFI_END_OF_FILE, -EPICK_AN_ERRNO, "End of File"},
{ EFI_INVALID_LANGUAGE, -EPICK_AN_ERRNO, "Invalid Languages"},
{ EFI_COMPROMISED_DATA, -EPICK_AN_ERRNO, "Compromised Data"},

// warnings
{ EFI_WARN_UNKOWN_GLYPH, -EPICK_AN_ERRNO, "Warning Unknown Glyph"},
{ EFI_WARN_DELETE_FAILURE, -EPICK_AN_ERRNO, "Warning Delete Failure"},
{ EFI_WARN_WRITE_FAILURE, -EPICK_AN_ERRNO, "Warning Write Failure"},
{ EFI_WARN_BUFFER_TOO_SMALL, -EPICK_AN_ERRNO, "Warning Buffer Too Small"},
#endif
};

static int
efi_status_cmp_bsearch(const void *key, const void *item)
{
u64 status = (u64)(uintptr_t)key;
struct efi_error_code *code = (struct efi_error_code *)item;

if (status < code->status)
return -1;
if (status > code->status)
return 1;
return 0;
}

int efi_status_to_err(efi_status_t status)
{
int err;

switch (status) {
case EFI_SUCCESS:
err = 0;
break;
case EFI_INVALID_PARAMETER:
err = -EINVAL;
break;
case EFI_OUT_OF_RESOURCES:
err = -ENOSPC;
break;
case EFI_DEVICE_ERROR:
err = -EIO;
break;
case EFI_WRITE_PROTECTED:
err = -EROFS;
break;
case EFI_SECURITY_VIOLATION:
err = -EACCES;
break;
case EFI_NOT_FOUND:
err = -ENOENT;
break;
case EFI_ABORTED:
err = -EINTR;
break;
default:
err = -EINVAL;
}
struct efi_error_code *found;
size_t num = sizeof(efi_error_codes) / sizeof(struct efi_error_code);

return err;
found = bsearch((void *)(uintptr_t)status, efi_error_codes,
sizeof(struct efi_error_code), num,
efi_status_cmp_bsearch);
if (!found)
return -EINVAL;
return found->errno;
}

const char *
efi_status_to_str(efi_status_t status)
{
struct efi_error_code *found;
size_t num = sizeof(efi_error_codes) / sizeof(struct efi_error_code);

found = bsearch((void *)(uintptr_t)status, efi_error_codes,
sizeof(struct efi_error_code), num,
efi_status_cmp_bsearch);
if (!found)
return "Unknown error code";
return found->description;
}
EXPORT_SYMBOL_GPL(efi_status_to_err);

Expand Down
12 changes: 11 additions & 1 deletion drivers/firmware/efi/fdtparams.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enum {
MMSIZE,
DCSIZE,
DCVERS,
SBMODE,

PARAMCOUNT
};
Expand All @@ -26,6 +27,7 @@ static __initconst const char name[][22] = {
[MMSIZE] = "MemMap Size ",
[DCSIZE] = "MemMap Desc. Size ",
[DCVERS] = "MemMap Desc. Version ",
[SBMODE] = "Secure Boot Enabled ",
};

static __initconst const struct {
Expand All @@ -43,6 +45,7 @@ static __initconst const struct {
[MMSIZE] = "xen,uefi-mmap-size",
[DCSIZE] = "xen,uefi-mmap-desc-size",
[DCVERS] = "xen,uefi-mmap-desc-ver",
[SBMODE] = "",
}
}, {
#endif
Expand All @@ -53,6 +56,7 @@ static __initconst const struct {
[MMSIZE] = "linux,uefi-mmap-size",
[DCSIZE] = "linux,uefi-mmap-desc-size",
[DCVERS] = "linux,uefi-mmap-desc-ver",
[SBMODE] = "linux,uefi-secure-boot",
}
}
};
Expand All @@ -64,6 +68,11 @@ static int __init efi_get_fdt_prop(const void *fdt, int node, const char *pname,
int len;
u64 val;

if (!pname[0]) {
memset(var, 0, size);
return 0;
}

prop = fdt_getprop(fdt, node, pname, &len);
if (!prop)
return 1;
Expand All @@ -81,7 +90,7 @@ static int __init efi_get_fdt_prop(const void *fdt, int node, const char *pname,
return 0;
}

u64 __init efi_get_fdt_params(struct efi_memory_map_data *mm)
u64 __init efi_get_fdt_params(struct efi_memory_map_data *mm, u32 *secure_boot)
{
const void *fdt = initial_boot_params;
unsigned long systab;
Expand All @@ -95,6 +104,7 @@ u64 __init efi_get_fdt_params(struct efi_memory_map_data *mm)
[MMSIZE] = { &mm->size, sizeof(mm->size) },
[DCSIZE] = { &mm->desc_size, sizeof(mm->desc_size) },
[DCVERS] = { &mm->desc_version, sizeof(mm->desc_version) },
[SBMODE] = { secure_boot, sizeof(*secure_boot) },
};

BUILD_BUG_ON(ARRAY_SIZE(target) != ARRAY_SIZE(name));
Expand Down
6 changes: 6 additions & 0 deletions drivers/firmware/efi/libstub/fdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ static efi_status_t update_fdt(void *orig_fdt, unsigned long orig_fdt_size,
}
}

fdt_val32 = cpu_to_fdt32(efi_get_secureboot());
status = fdt_setprop(fdt, node, "linux,uefi-secure-boot",
&fdt_val32, sizeof(fdt_val32));
if (status)
goto fdt_set_fail;

/* Shrink the FDT back to its minimum size: */
fdt_pack(fdt);

Expand Down
44 changes: 44 additions & 0 deletions drivers/firmware/efi/secureboot.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

/* Core kernel secure boot support.
*
* Copyright (C) 2017 Red Hat, Inc. All Rights Reserved.
* Written by David Howells ([email protected])
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public Licence
* as published by the Free Software Foundation; either version
* 2 of the Licence, or (at your option) any later version.
*/

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/efi.h>
#include <linux/kernel.h>
#include <linux/printk.h>
#include <linux/security.h>

/*
* Decide what to do when UEFI secure boot mode is enabled.
*/
void __init efi_set_secure_boot(enum efi_secureboot_mode mode)
{
if (efi_enabled(EFI_BOOT)) {
switch (mode) {
case efi_secureboot_mode_disabled:
pr_info("Secure boot disabled\n");
break;
case efi_secureboot_mode_enabled:
set_bit(EFI_SECURE_BOOT, &efi.flags);
#ifdef CONFIG_LOCK_DOWN_IN_EFI_SECURE_BOOT
lock_kernel_down("EFI Secure Boot",
LOCKDOWN_INTEGRITY_MAX);
#endif
pr_info("Secure boot enabled\n");
break;
default:
pr_warn("Secure boot could not be determined (mode %u)\n",
mode);
break;
}
}
}
6 changes: 5 additions & 1 deletion drivers/mtd/devices/phram.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,11 @@ static int phram_param_call(const char *val, const struct kernel_param *kp)
#endif
}

module_param_call(phram, phram_param_call, NULL, NULL, 0200);
static const struct kernel_param_ops phram_param_ops = {
.set = phram_param_call
};
__module_param_call(MODULE_PARAM_PREFIX, phram, &phram_param_ops, NULL,
0200, -1, KERNEL_PARAM_FL_HWPARAM | hwparam_iomem);
MODULE_PARM_DESC(phram, "Memory region to map. \"phram=<name>,<start>,<length>[,<erasesize>]\"");

#ifdef CONFIG_OF
Expand Down
Loading