mirror of
https://github.com/Dasharo/linux.git
synced 2026-03-06 15:25:10 -08:00
Merge tag 'efi-next-for-v6.8' of git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi
Pull EFI updates from Ard Biesheuvel: - Fix a syzbot reported issue in efivarfs where concurrent accesses to the file system resulted in list corruption - Add support for accessing EFI variables via the TEE subsystem (and a trusted application in the secure world) instead of via EFI runtime firmware running in the OS's execution context - Avoid linker tricks to discover the image base on LoongArch * tag 'efi-next-for-v6.8' of git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi: efi: memmap: fix kernel-doc warnings efi/loongarch: Directly position the loaded image file efivarfs: automatically update super block flag efi: Add tee-based EFI variable driver efi: Add EFI_ACCESS_DENIED status code efi: expose efivar generic ops register function efivarfs: Move efivarfs list into superblock s_fs_info efivarfs: Free s_fs_info on unmount efivarfs: Move efivar availability check into FS context init efivarfs: force RO when remounting if SetVariable is not supported
This commit is contained in:
@@ -32,6 +32,4 @@ static inline unsigned long efi_get_kimg_min_align(void)
|
||||
|
||||
#define EFI_KIMG_PREFERRED_ADDRESS PHYSADDR(VMLINUX_LOAD_ADDRESS)
|
||||
|
||||
unsigned long kernel_entry_address(unsigned long kernel_addr);
|
||||
|
||||
#endif /* _ASM_LOONGARCH_EFI_H */
|
||||
|
||||
@@ -34,7 +34,6 @@ pe_header:
|
||||
|
||||
SYM_DATA(kernel_asize, .long _kernel_asize);
|
||||
SYM_DATA(kernel_fsize, .long _kernel_fsize);
|
||||
SYM_DATA(kernel_offset, .long _kernel_offset);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ __efistub_strcmp = strcmp;
|
||||
__efistub_kernel_entry = kernel_entry;
|
||||
__efistub_kernel_asize = kernel_asize;
|
||||
__efistub_kernel_fsize = kernel_fsize;
|
||||
__efistub_kernel_offset = kernel_offset;
|
||||
#if defined(CONFIG_EFI_EARLYCON) || defined(CONFIG_SYSFB)
|
||||
__efistub_screen_info = screen_info;
|
||||
#endif
|
||||
|
||||
@@ -143,7 +143,6 @@ SECTIONS
|
||||
_kernel_fsize = _edata - _text;
|
||||
_kernel_vsize = _end - __initdata_begin;
|
||||
_kernel_rsize = _edata - __initdata_begin;
|
||||
_kernel_offset = kernel_offset - _text;
|
||||
#endif
|
||||
|
||||
.gptab.sdata : {
|
||||
|
||||
@@ -301,3 +301,18 @@ config UEFI_CPER_X86
|
||||
bool
|
||||
depends on UEFI_CPER && X86
|
||||
default y
|
||||
|
||||
config TEE_STMM_EFI
|
||||
tristate "TEE-based EFI runtime variable service driver"
|
||||
depends on EFI && OPTEE
|
||||
help
|
||||
Select this config option if TEE is compiled to include StandAloneMM
|
||||
as a separate secure partition. It has the ability to check and store
|
||||
EFI variables on an RPMB or any other non-volatile medium used by
|
||||
StandAloneMM.
|
||||
|
||||
Enabling this will change the EFI runtime services from the firmware
|
||||
provided functions to TEE calls.
|
||||
|
||||
To compile this driver as a module, choose M here: the module
|
||||
will be called tee_stmm_efi.
|
||||
|
||||
@@ -42,3 +42,4 @@ obj-$(CONFIG_EFI_EARLYCON) += earlycon.o
|
||||
obj-$(CONFIG_UEFI_CPER_ARM) += cper-arm.o
|
||||
obj-$(CONFIG_UEFI_CPER_X86) += cper-x86.o
|
||||
obj-$(CONFIG_UNACCEPTED_MEMORY) += unaccepted_memory.o
|
||||
obj-$(CONFIG_TEE_STMM_EFI) += stmm/tee_stmm_efi.o
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <linux/ucs2_string.h>
|
||||
#include <linux/memblock.h>
|
||||
#include <linux/security.h>
|
||||
#include <linux/notifier.h>
|
||||
|
||||
#include <asm/early_ioremap.h>
|
||||
|
||||
@@ -187,6 +188,9 @@ static const struct attribute_group efi_subsys_attr_group = {
|
||||
.is_visible = efi_attr_is_visible,
|
||||
};
|
||||
|
||||
struct blocking_notifier_head efivar_ops_nh;
|
||||
EXPORT_SYMBOL_GPL(efivar_ops_nh);
|
||||
|
||||
static struct efivars generic_efivars;
|
||||
static struct efivar_operations generic_ops;
|
||||
|
||||
@@ -231,6 +235,18 @@ static void generic_ops_unregister(void)
|
||||
efivars_unregister(&generic_efivars);
|
||||
}
|
||||
|
||||
void efivars_generic_ops_register(void)
|
||||
{
|
||||
generic_ops_register();
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(efivars_generic_ops_register);
|
||||
|
||||
void efivars_generic_ops_unregister(void)
|
||||
{
|
||||
generic_ops_unregister();
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(efivars_generic_ops_unregister);
|
||||
|
||||
#ifdef CONFIG_EFI_CUSTOM_SSDT_OVERLAYS
|
||||
#define EFIVAR_SSDT_NAME_MAX 16UL
|
||||
static char efivar_ssdt[EFIVAR_SSDT_NAME_MAX] __initdata;
|
||||
@@ -419,6 +435,8 @@ static int __init efisubsys_init(void)
|
||||
platform_device_register_simple("efivars", 0, NULL, 0);
|
||||
}
|
||||
|
||||
BLOCKING_INIT_NOTIFIER_HEAD(&efivar_ops_nh);
|
||||
|
||||
error = sysfs_create_group(efi_kobj, &efi_subsys_attr_group);
|
||||
if (error) {
|
||||
pr_err("efi: Sysfs attribute export failed with error %d.\n",
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
#include <asm/efi.h>
|
||||
#include <asm/addrspace.h>
|
||||
#include "efistub.h"
|
||||
#include "loongarch-stub.h"
|
||||
|
||||
extern int kernel_asize;
|
||||
extern int kernel_fsize;
|
||||
extern int kernel_offset;
|
||||
extern int kernel_entry;
|
||||
|
||||
efi_status_t handle_kernel_image(unsigned long *image_addr,
|
||||
@@ -24,7 +24,7 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
|
||||
efi_status_t status;
|
||||
unsigned long kernel_addr = 0;
|
||||
|
||||
kernel_addr = (unsigned long)&kernel_offset - kernel_offset;
|
||||
kernel_addr = (unsigned long)image->image_base;
|
||||
|
||||
status = efi_relocate_kernel(&kernel_addr, kernel_fsize, kernel_asize,
|
||||
EFI_KIMG_PREFERRED_ADDRESS, efi_get_kimg_min_align(), 0x0);
|
||||
@@ -35,9 +35,10 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
|
||||
return status;
|
||||
}
|
||||
|
||||
unsigned long kernel_entry_address(unsigned long kernel_addr)
|
||||
unsigned long kernel_entry_address(unsigned long kernel_addr,
|
||||
efi_loaded_image_t *image)
|
||||
{
|
||||
unsigned long base = (unsigned long)&kernel_offset - kernel_offset;
|
||||
unsigned long base = (unsigned long)image->image_base;
|
||||
|
||||
return (unsigned long)&kernel_entry - base + kernel_addr;
|
||||
}
|
||||
|
||||
4
drivers/firmware/efi/libstub/loongarch-stub.h
Normal file
4
drivers/firmware/efi/libstub/loongarch-stub.h
Normal file
@@ -0,0 +1,4 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
|
||||
unsigned long kernel_entry_address(unsigned long kernel_addr,
|
||||
efi_loaded_image_t *image);
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <asm/efi.h>
|
||||
#include <asm/addrspace.h>
|
||||
#include "efistub.h"
|
||||
#include "loongarch-stub.h"
|
||||
|
||||
typedef void __noreturn (*kernel_entry_t)(bool efi, unsigned long cmdline,
|
||||
unsigned long systab);
|
||||
@@ -37,7 +38,8 @@ static efi_status_t exit_boot_func(struct efi_boot_memmap *map, void *priv)
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
unsigned long __weak kernel_entry_address(unsigned long kernel_addr)
|
||||
unsigned long __weak kernel_entry_address(unsigned long kernel_addr,
|
||||
efi_loaded_image_t *image)
|
||||
{
|
||||
return *(unsigned long *)(kernel_addr + 8) - VMLINUX_LOAD_ADDRESS + kernel_addr;
|
||||
}
|
||||
@@ -73,7 +75,7 @@ efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
|
||||
csr_write64(CSR_DMW0_INIT, LOONGARCH_CSR_DMWIN0);
|
||||
csr_write64(CSR_DMW1_INIT, LOONGARCH_CSR_DMWIN1);
|
||||
|
||||
real_kernel_entry = (void *)kernel_entry_address(kernel_addr);
|
||||
real_kernel_entry = (void *)kernel_entry_address(kernel_addr, image);
|
||||
|
||||
real_kernel_entry(true, (unsigned long)cmdline_ptr,
|
||||
(unsigned long)efi_system_table);
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
* space isn't setup. Once the kernel is fully booted we can fallback
|
||||
* to the more robust memremap*() API.
|
||||
*
|
||||
* Returns zero on success, a negative error code on failure.
|
||||
* Returns: zero on success, a negative error code on failure.
|
||||
*/
|
||||
int __init __efi_memmap_init(struct efi_memory_map_data *data)
|
||||
{
|
||||
@@ -77,6 +77,8 @@ int __init __efi_memmap_init(struct efi_memory_map_data *data)
|
||||
*
|
||||
* Use early_memremap() to map the passed in EFI memory map and assign
|
||||
* it to efi.memmap.
|
||||
*
|
||||
* Returns: zero on success, a negative error code on failure.
|
||||
*/
|
||||
int __init efi_memmap_init_early(struct efi_memory_map_data *data)
|
||||
{
|
||||
@@ -107,7 +109,7 @@ void __init efi_memmap_unmap(void)
|
||||
|
||||
/**
|
||||
* efi_memmap_init_late - Map efi.memmap with memremap()
|
||||
* @phys_addr: Physical address of the new EFI memory map
|
||||
* @addr: Physical address of the new EFI memory map
|
||||
* @size: Size in bytes of the new EFI memory map
|
||||
*
|
||||
* Setup a mapping of the EFI memory map using ioremap_cache(). This
|
||||
@@ -126,7 +128,7 @@ void __init efi_memmap_unmap(void)
|
||||
* runtime so that things like efi_mem_desc_lookup() and
|
||||
* efi_mem_attributes() always work.
|
||||
*
|
||||
* Returns zero on success, a negative error code on failure.
|
||||
* Returns: zero on success, a negative error code on failure.
|
||||
*/
|
||||
int __init efi_memmap_init_late(phys_addr_t addr, unsigned long size)
|
||||
{
|
||||
|
||||
236
drivers/firmware/efi/stmm/mm_communication.h
Normal file
236
drivers/firmware/efi/stmm/mm_communication.h
Normal file
@@ -0,0 +1,236 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0+ */
|
||||
/*
|
||||
* Headers for EFI variable service via StandAloneMM, EDK2 application running
|
||||
* in OP-TEE. Most of the structs and defines resemble the EDK2 naming.
|
||||
*
|
||||
* Copyright (c) 2017, Intel Corporation. All rights reserved.
|
||||
* Copyright (C) 2020 Linaro Ltd.
|
||||
*/
|
||||
|
||||
#ifndef _MM_COMMUNICATION_H_
|
||||
#define _MM_COMMUNICATION_H_
|
||||
|
||||
/*
|
||||
* Interface to the pseudo Trusted Application (TA), which provides a
|
||||
* communication channel with the Standalone MM (Management Mode)
|
||||
* Secure Partition running at Secure-EL0
|
||||
*/
|
||||
|
||||
#define PTA_STMM_CMD_COMMUNICATE 0
|
||||
|
||||
/*
|
||||
* Defined in OP-TEE, this UUID is used to identify the pseudo-TA.
|
||||
* OP-TEE is using big endian GUIDs while UEFI uses little endian ones
|
||||
*/
|
||||
#define PTA_STMM_UUID \
|
||||
UUID_INIT(0xed32d533, 0x99e6, 0x4209, \
|
||||
0x9c, 0xc0, 0x2d, 0x72, 0xcd, 0xd9, 0x98, 0xa7)
|
||||
|
||||
#define EFI_MM_VARIABLE_GUID \
|
||||
EFI_GUID(0xed32d533, 0x99e6, 0x4209, \
|
||||
0x9c, 0xc0, 0x2d, 0x72, 0xcd, 0xd9, 0x98, 0xa7)
|
||||
|
||||
/**
|
||||
* struct efi_mm_communicate_header - Header used for SMM variable communication
|
||||
|
||||
* @header_guid: header use for disambiguation of content
|
||||
* @message_len: length of the message. Does not include the size of the
|
||||
* header
|
||||
* @data: payload of the message
|
||||
*
|
||||
* Defined in the PI spec as EFI_MM_COMMUNICATE_HEADER.
|
||||
* To avoid confusion in interpreting frames, the communication buffer should
|
||||
* always begin with efi_mm_communicate_header.
|
||||
*/
|
||||
struct efi_mm_communicate_header {
|
||||
efi_guid_t header_guid;
|
||||
size_t message_len;
|
||||
u8 data[];
|
||||
} __packed;
|
||||
|
||||
#define MM_COMMUNICATE_HEADER_SIZE \
|
||||
(sizeof(struct efi_mm_communicate_header))
|
||||
|
||||
/* SPM return error codes */
|
||||
#define ARM_SVC_SPM_RET_SUCCESS 0
|
||||
#define ARM_SVC_SPM_RET_NOT_SUPPORTED -1
|
||||
#define ARM_SVC_SPM_RET_INVALID_PARAMS -2
|
||||
#define ARM_SVC_SPM_RET_DENIED -3
|
||||
#define ARM_SVC_SPM_RET_NO_MEMORY -5
|
||||
|
||||
#define SMM_VARIABLE_FUNCTION_GET_VARIABLE 1
|
||||
/*
|
||||
* The payload for this function is
|
||||
* SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME.
|
||||
*/
|
||||
#define SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME 2
|
||||
/*
|
||||
* The payload for this function is SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE.
|
||||
*/
|
||||
#define SMM_VARIABLE_FUNCTION_SET_VARIABLE 3
|
||||
/*
|
||||
* The payload for this function is
|
||||
* SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO.
|
||||
*/
|
||||
#define SMM_VARIABLE_FUNCTION_QUERY_VARIABLE_INFO 4
|
||||
/*
|
||||
* It is a notify event, no extra payload for this function.
|
||||
*/
|
||||
#define SMM_VARIABLE_FUNCTION_READY_TO_BOOT 5
|
||||
/*
|
||||
* It is a notify event, no extra payload for this function.
|
||||
*/
|
||||
#define SMM_VARIABLE_FUNCTION_EXIT_BOOT_SERVICE 6
|
||||
/*
|
||||
* The payload for this function is VARIABLE_INFO_ENTRY.
|
||||
* The GUID in EFI_SMM_COMMUNICATE_HEADER is gEfiSmmVariableProtocolGuid.
|
||||
*/
|
||||
#define SMM_VARIABLE_FUNCTION_GET_STATISTICS 7
|
||||
/*
|
||||
* The payload for this function is SMM_VARIABLE_COMMUNICATE_LOCK_VARIABLE
|
||||
*/
|
||||
#define SMM_VARIABLE_FUNCTION_LOCK_VARIABLE 8
|
||||
|
||||
#define SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_SET 9
|
||||
|
||||
#define SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_GET 10
|
||||
|
||||
#define SMM_VARIABLE_FUNCTION_GET_PAYLOAD_SIZE 11
|
||||
/*
|
||||
* The payload for this function is
|
||||
* SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT
|
||||
*/
|
||||
#define SMM_VARIABLE_FUNCTION_INIT_RUNTIME_VARIABLE_CACHE_CONTEXT 12
|
||||
|
||||
#define SMM_VARIABLE_FUNCTION_SYNC_RUNTIME_CACHE 13
|
||||
/*
|
||||
* The payload for this function is
|
||||
* SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO
|
||||
*/
|
||||
#define SMM_VARIABLE_FUNCTION_GET_RUNTIME_CACHE_INFO 14
|
||||
|
||||
/**
|
||||
* struct smm_variable_communicate_header - Used for SMM variable communication
|
||||
|
||||
* @function: function to call in Smm.
|
||||
* @ret_status: return status
|
||||
* @data: payload
|
||||
*/
|
||||
struct smm_variable_communicate_header {
|
||||
size_t function;
|
||||
efi_status_t ret_status;
|
||||
u8 data[];
|
||||
};
|
||||
|
||||
#define MM_VARIABLE_COMMUNICATE_SIZE \
|
||||
(sizeof(struct smm_variable_communicate_header))
|
||||
|
||||
/**
|
||||
* struct smm_variable_access - Used to communicate with StMM by
|
||||
* SetVariable and GetVariable.
|
||||
|
||||
* @guid: vendor GUID
|
||||
* @data_size: size of EFI variable data
|
||||
* @name_size: size of EFI name
|
||||
* @attr: attributes
|
||||
* @name: variable name
|
||||
*
|
||||
*/
|
||||
struct smm_variable_access {
|
||||
efi_guid_t guid;
|
||||
size_t data_size;
|
||||
size_t name_size;
|
||||
u32 attr;
|
||||
u16 name[];
|
||||
};
|
||||
|
||||
#define MM_VARIABLE_ACCESS_HEADER_SIZE \
|
||||
(sizeof(struct smm_variable_access))
|
||||
/**
|
||||
* struct smm_variable_payload_size - Used to get the max allowed
|
||||
* payload used in StMM.
|
||||
*
|
||||
* @size: size to fill in
|
||||
*
|
||||
*/
|
||||
struct smm_variable_payload_size {
|
||||
size_t size;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct smm_variable_getnext - Used to communicate with StMM for
|
||||
* GetNextVariableName.
|
||||
*
|
||||
* @guid: vendor GUID
|
||||
* @name_size: size of the name of the variable
|
||||
* @name: variable name
|
||||
*
|
||||
*/
|
||||
struct smm_variable_getnext {
|
||||
efi_guid_t guid;
|
||||
size_t name_size;
|
||||
u16 name[];
|
||||
};
|
||||
|
||||
#define MM_VARIABLE_GET_NEXT_HEADER_SIZE \
|
||||
(sizeof(struct smm_variable_getnext))
|
||||
|
||||
/**
|
||||
* struct smm_variable_query_info - Used to communicate with StMM for
|
||||
* QueryVariableInfo.
|
||||
*
|
||||
* @max_variable_storage: max available storage
|
||||
* @remaining_variable_storage: remaining available storage
|
||||
* @max_variable_size: max variable supported size
|
||||
* @attr: attributes to query storage for
|
||||
*
|
||||
*/
|
||||
struct smm_variable_query_info {
|
||||
u64 max_variable_storage;
|
||||
u64 remaining_variable_storage;
|
||||
u64 max_variable_size;
|
||||
u32 attr;
|
||||
};
|
||||
|
||||
#define VAR_CHECK_VARIABLE_PROPERTY_REVISION 0x0001
|
||||
#define VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY BIT(0)
|
||||
/**
|
||||
* struct var_check_property - Used to store variable properties in StMM
|
||||
*
|
||||
* @revision: magic revision number for variable property checking
|
||||
* @property: properties mask for the variable used in StMM.
|
||||
* Currently RO flag is supported
|
||||
* @attributes: variable attributes used in StMM checking when properties
|
||||
* for a variable are enabled
|
||||
* @minsize: minimum allowed size for variable payload checked against
|
||||
* smm_variable_access->datasize in StMM
|
||||
* @maxsize: maximum allowed size for variable payload checked against
|
||||
* smm_variable_access->datasize in StMM
|
||||
*
|
||||
*/
|
||||
struct var_check_property {
|
||||
u16 revision;
|
||||
u16 property;
|
||||
u32 attributes;
|
||||
size_t minsize;
|
||||
size_t maxsize;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct smm_variable_var_check_property - Used to communicate variable
|
||||
* properties with StMM
|
||||
*
|
||||
* @guid: vendor GUID
|
||||
* @name_size: size of EFI name
|
||||
* @property: variable properties struct
|
||||
* @name: variable name
|
||||
*
|
||||
*/
|
||||
struct smm_variable_var_check_property {
|
||||
efi_guid_t guid;
|
||||
size_t name_size;
|
||||
struct var_check_property property;
|
||||
u16 name[];
|
||||
};
|
||||
|
||||
#endif /* _MM_COMMUNICATION_H_ */
|
||||
616
drivers/firmware/efi/stmm/tee_stmm_efi.c
Normal file
616
drivers/firmware/efi/stmm/tee_stmm_efi.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -63,6 +63,7 @@ int efivars_register(struct efivars *efivars,
|
||||
const struct efivar_operations *ops)
|
||||
{
|
||||
int rv;
|
||||
int event;
|
||||
|
||||
if (down_interruptible(&efivars_lock))
|
||||
return -EINTR;
|
||||
@@ -77,6 +78,13 @@ int efivars_register(struct efivars *efivars,
|
||||
|
||||
__efivars = efivars;
|
||||
|
||||
if (efivar_supports_writes())
|
||||
event = EFIVAR_OPS_RDWR;
|
||||
else
|
||||
event = EFIVAR_OPS_RDONLY;
|
||||
|
||||
blocking_notifier_call_chain(&efivar_ops_nh, event, NULL);
|
||||
|
||||
pr_info("Registered efivars operations\n");
|
||||
rv = 0;
|
||||
out:
|
||||
|
||||
@@ -77,6 +77,7 @@ bool efivarfs_valid_name(const char *str, int len)
|
||||
static int efivarfs_create(struct mnt_idmap *idmap, struct inode *dir,
|
||||
struct dentry *dentry, umode_t mode, bool excl)
|
||||
{
|
||||
struct efivarfs_fs_info *info = dir->i_sb->s_fs_info;
|
||||
struct inode *inode = NULL;
|
||||
struct efivar_entry *var;
|
||||
int namelen, i = 0, err = 0;
|
||||
@@ -118,7 +119,7 @@ static int efivarfs_create(struct mnt_idmap *idmap, struct inode *dir,
|
||||
inode->i_private = var;
|
||||
kmemleak_ignore(var);
|
||||
|
||||
err = efivar_entry_add(var, &efivarfs_list);
|
||||
err = efivar_entry_add(var, &info->efivarfs_list);
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
|
||||
@@ -16,6 +16,9 @@ struct efivarfs_mount_opts {
|
||||
|
||||
struct efivarfs_fs_info {
|
||||
struct efivarfs_mount_opts mount_opts;
|
||||
struct list_head efivarfs_list;
|
||||
struct super_block *sb;
|
||||
struct notifier_block nb;
|
||||
};
|
||||
|
||||
struct efi_variable {
|
||||
@@ -33,7 +36,8 @@ struct efivar_entry {
|
||||
struct kobject kobj;
|
||||
};
|
||||
|
||||
int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *),
|
||||
int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *,
|
||||
struct list_head *),
|
||||
void *data, bool duplicates, struct list_head *head);
|
||||
|
||||
int efivar_entry_add(struct efivar_entry *entry, struct list_head *head);
|
||||
@@ -64,6 +68,4 @@ extern struct inode *efivarfs_get_inode(struct super_block *sb,
|
||||
const struct inode *dir, int mode, dev_t dev,
|
||||
bool is_removable);
|
||||
|
||||
extern struct list_head efivarfs_list;
|
||||
|
||||
#endif /* EFIVAR_FS_INTERNAL_H */
|
||||
|
||||
@@ -15,10 +15,29 @@
|
||||
#include <linux/slab.h>
|
||||
#include <linux/magic.h>
|
||||
#include <linux/statfs.h>
|
||||
#include <linux/notifier.h>
|
||||
#include <linux/printk.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
LIST_HEAD(efivarfs_list);
|
||||
static int efivarfs_ops_notifier(struct notifier_block *nb, unsigned long event,
|
||||
void *data)
|
||||
{
|
||||
struct efivarfs_fs_info *sfi = container_of(nb, struct efivarfs_fs_info, nb);
|
||||
|
||||
switch (event) {
|
||||
case EFIVAR_OPS_RDONLY:
|
||||
sfi->sb->s_flags |= SB_RDONLY;
|
||||
break;
|
||||
case EFIVAR_OPS_RDWR:
|
||||
sfi->sb->s_flags &= ~SB_RDONLY;
|
||||
break;
|
||||
default:
|
||||
return NOTIFY_DONE;
|
||||
}
|
||||
|
||||
return NOTIFY_OK;
|
||||
}
|
||||
|
||||
static void efivarfs_evict_inode(struct inode *inode)
|
||||
{
|
||||
@@ -166,7 +185,8 @@ static struct dentry *efivarfs_alloc_dentry(struct dentry *parent, char *name)
|
||||
}
|
||||
|
||||
static int efivarfs_callback(efi_char16_t *name16, efi_guid_t vendor,
|
||||
unsigned long name_size, void *data)
|
||||
unsigned long name_size, void *data,
|
||||
struct list_head *list)
|
||||
{
|
||||
struct super_block *sb = (struct super_block *)data;
|
||||
struct efivar_entry *entry;
|
||||
@@ -221,7 +241,7 @@ static int efivarfs_callback(efi_char16_t *name16, efi_guid_t vendor,
|
||||
}
|
||||
|
||||
__efivar_entry_get(entry, NULL, &size, NULL);
|
||||
__efivar_entry_add(entry, &efivarfs_list);
|
||||
__efivar_entry_add(entry, list);
|
||||
|
||||
/* copied by the above to local storage in the dentry. */
|
||||
kfree(name);
|
||||
@@ -291,13 +311,11 @@ static int efivarfs_parse_param(struct fs_context *fc, struct fs_parameter *para
|
||||
|
||||
static int efivarfs_fill_super(struct super_block *sb, struct fs_context *fc)
|
||||
{
|
||||
struct efivarfs_fs_info *sfi = sb->s_fs_info;
|
||||
struct inode *inode = NULL;
|
||||
struct dentry *root;
|
||||
int err;
|
||||
|
||||
if (!efivar_is_available())
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
sb->s_maxbytes = MAX_LFS_FILESIZE;
|
||||
sb->s_blocksize = PAGE_SIZE;
|
||||
sb->s_blocksize_bits = PAGE_SHIFT;
|
||||
@@ -319,11 +337,16 @@ static int efivarfs_fill_super(struct super_block *sb, struct fs_context *fc)
|
||||
if (!root)
|
||||
return -ENOMEM;
|
||||
|
||||
INIT_LIST_HEAD(&efivarfs_list);
|
||||
|
||||
err = efivar_init(efivarfs_callback, (void *)sb, true, &efivarfs_list);
|
||||
sfi->sb = sb;
|
||||
sfi->nb.notifier_call = efivarfs_ops_notifier;
|
||||
err = blocking_notifier_chain_register(&efivar_ops_nh, &sfi->nb);
|
||||
if (err)
|
||||
efivar_entry_iter(efivarfs_destroy, &efivarfs_list, NULL);
|
||||
return err;
|
||||
|
||||
err = efivar_init(efivarfs_callback, (void *)sb, true,
|
||||
&sfi->efivarfs_list);
|
||||
if (err)
|
||||
efivar_entry_iter(efivarfs_destroy, &sfi->efivarfs_list, NULL);
|
||||
|
||||
return err;
|
||||
}
|
||||
@@ -333,19 +356,35 @@ static int efivarfs_get_tree(struct fs_context *fc)
|
||||
return get_tree_single(fc, efivarfs_fill_super);
|
||||
}
|
||||
|
||||
static int efivarfs_reconfigure(struct fs_context *fc)
|
||||
{
|
||||
if (!efivar_supports_writes() && !(fc->sb_flags & SB_RDONLY)) {
|
||||
pr_err("Firmware does not support SetVariableRT. Can not remount with rw\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct fs_context_operations efivarfs_context_ops = {
|
||||
.get_tree = efivarfs_get_tree,
|
||||
.parse_param = efivarfs_parse_param,
|
||||
.reconfigure = efivarfs_reconfigure,
|
||||
};
|
||||
|
||||
static int efivarfs_init_fs_context(struct fs_context *fc)
|
||||
{
|
||||
struct efivarfs_fs_info *sfi;
|
||||
|
||||
if (!efivar_is_available())
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
sfi = kzalloc(sizeof(*sfi), GFP_KERNEL);
|
||||
if (!sfi)
|
||||
return -ENOMEM;
|
||||
|
||||
INIT_LIST_HEAD(&sfi->efivarfs_list);
|
||||
|
||||
sfi->mount_opts.uid = GLOBAL_ROOT_UID;
|
||||
sfi->mount_opts.gid = GLOBAL_ROOT_GID;
|
||||
|
||||
@@ -356,13 +395,14 @@ static int efivarfs_init_fs_context(struct fs_context *fc)
|
||||
|
||||
static void efivarfs_kill_sb(struct super_block *sb)
|
||||
{
|
||||
struct efivarfs_fs_info *sfi = sb->s_fs_info;
|
||||
|
||||
blocking_notifier_chain_unregister(&efivar_ops_nh, &sfi->nb);
|
||||
kill_litter_super(sb);
|
||||
|
||||
if (!efivar_is_available())
|
||||
return;
|
||||
|
||||
/* Remove all entries and destroy */
|
||||
efivar_entry_iter(efivarfs_destroy, &efivarfs_list, NULL);
|
||||
efivar_entry_iter(efivarfs_destroy, &sfi->efivarfs_list, NULL);
|
||||
kfree(sfi);
|
||||
}
|
||||
|
||||
static struct file_system_type efivarfs_type = {
|
||||
|
||||
@@ -369,7 +369,8 @@ static void dup_variable_bug(efi_char16_t *str16, efi_guid_t *vendor_guid,
|
||||
*
|
||||
* Returns 0 on success, or a kernel error code on failure.
|
||||
*/
|
||||
int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *),
|
||||
int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *,
|
||||
struct list_head *),
|
||||
void *data, bool duplicates, struct list_head *head)
|
||||
{
|
||||
unsigned long variable_name_size = 1024;
|
||||
@@ -420,7 +421,7 @@ int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *),
|
||||
status = EFI_NOT_FOUND;
|
||||
} else {
|
||||
err = func(variable_name, vendor_guid,
|
||||
variable_name_size, data);
|
||||
variable_name_size, data, head);
|
||||
if (err)
|
||||
status = EFI_NOT_FOUND;
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ struct screen_info;
|
||||
#define EFI_WRITE_PROTECTED ( 8 | (1UL << (BITS_PER_LONG-1)))
|
||||
#define EFI_OUT_OF_RESOURCES ( 9 | (1UL << (BITS_PER_LONG-1)))
|
||||
#define EFI_NOT_FOUND (14 | (1UL << (BITS_PER_LONG-1)))
|
||||
#define EFI_ACCESS_DENIED (15 | (1UL << (BITS_PER_LONG-1)))
|
||||
#define EFI_TIMEOUT (18 | (1UL << (BITS_PER_LONG-1)))
|
||||
#define EFI_ABORTED (21 | (1UL << (BITS_PER_LONG-1)))
|
||||
#define EFI_SECURITY_VIOLATION (26 | (1UL << (BITS_PER_LONG-1)))
|
||||
@@ -1348,4 +1349,15 @@ bool efi_config_table_is_usable(const efi_guid_t *guid, unsigned long table)
|
||||
|
||||
umode_t efi_attr_is_visible(struct kobject *kobj, struct attribute *attr, int n);
|
||||
|
||||
/*
|
||||
* efivar ops event type
|
||||
*/
|
||||
#define EFIVAR_OPS_RDONLY 0
|
||||
#define EFIVAR_OPS_RDWR 1
|
||||
|
||||
extern struct blocking_notifier_head efivar_ops_nh;
|
||||
|
||||
void efivars_generic_ops_register(void);
|
||||
void efivars_generic_ops_unregister(void);
|
||||
|
||||
#endif /* _LINUX_EFI_H */
|
||||
|
||||
Reference in New Issue
Block a user