Path: blob/master/drivers/firmware/efi/libstub/secureboot.c
26483 views
// SPDX-License-Identifier: GPL-2.01/*2* Secure boot handling.3*4* Copyright (C) 2013,2014 Linaro Limited5* Roy Franz <[email protected]6* Copyright (C) 2013 Red Hat, Inc.7* Mark Salter <[email protected]>8*/9#include <linux/efi.h>10#include <asm/efi.h>1112#include "efistub.h"1314/* SHIM variables */15static const efi_guid_t shim_guid = EFI_SHIM_LOCK_GUID;16static const efi_char16_t shim_MokSBState_name[] = L"MokSBStateRT";1718static efi_status_t get_var(efi_char16_t *name, efi_guid_t *vendor, u32 *attr,19unsigned long *data_size, void *data)20{21return get_efi_var(name, vendor, attr, data_size, data);22}2324/*25* Determine whether we're in secure boot mode.26*/27enum efi_secureboot_mode efi_get_secureboot(void)28{29u32 attr;30unsigned long size;31enum efi_secureboot_mode mode;32efi_status_t status;33u8 moksbstate;3435mode = efi_get_secureboot_mode(get_var);36if (mode == efi_secureboot_mode_unknown) {37efi_err("Could not determine UEFI Secure Boot status.\n");38return efi_secureboot_mode_unknown;39}40if (mode != efi_secureboot_mode_enabled)41return mode;4243/*44* See if a user has put the shim into insecure mode. If so, and if the45* variable doesn't have the non-volatile attribute set, we might as46* well honor that.47*/48size = sizeof(moksbstate);49status = get_efi_var(shim_MokSBState_name, &shim_guid,50&attr, &size, &moksbstate);5152/* If it fails, we don't care why. Default to secure */53if (status != EFI_SUCCESS)54goto secure_boot_enabled;55if (!(attr & EFI_VARIABLE_NON_VOLATILE) && moksbstate == 1)56return efi_secureboot_mode_disabled;5758secure_boot_enabled:59efi_info("UEFI Secure Boot is enabled.\n");60return efi_secureboot_mode_enabled;61}626364