System for implementing software-based trusted execution environment for embedded device and method therefor

A software-based trusted execution environment for low-end embedded devices addresses the resource limitations by using stage-2 paging and DMA filtering to create a secure execution environment, ensuring secure data protection and communication without relying on hardware support for TEE.

WO2024232496A1PCT designated stage expired Publication Date: 2024-11-14THE IND & ACADEMIC COOP IN CHUNGNAM NAT UNIV (IAC)
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
PCT/KR2023/020250
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-05-10
Filing Date
2023-12-08
Publication Date
2024-11-14

AI Technical Summary

Technical Problem

Low-end embedded devices lack the necessary hardware resources to implement a trusted execution environment (TEE) due to limited processing performance and memory capacity, and existing hardware-based solutions like TrustZone are not easily accessible or supported in all devices.

Method used

A software-based trusted execution environment is implemented using a stage-2 paging unit for memory isolation, DMA filtering, temporary privilege elevation/demotion, and secure I/O operations to create a secure execution environment without relying on hardware support like TZ-ASC and TZ-PC.

Benefits of technology

This approach enables secure data protection and safe communication in embedded devices without hardware support for TEE, enhancing security and reliability by isolating memory and managing privileges effectively.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure KR2023020250_14112024_PF_FP_ABST
    Figure KR2023020250_14112024_PF_FP_ABST
Patent Text Reader

Abstract

The present invention relates to a system for implementing a software-based trusted execution environment for an embedded device and, more particularly, to a system for implementing a software-based trusted execution environment for an embedded device to construct a trusted execution environment in the embedded device, and a method therefor. According to the present invention, it is possible to securely protect data in an embedded environment that does not have hardware support for constructing a trusted execution environment, and to achieve secure input / output for secure communication between hardware and a trusted execution environment.
Need to check novelty before this filing date? Find Prior Art

Description

System and method for implementing a software-based trusted execution environment for embedded devices

[0001] The present invention relates to a system for implementing a software-based trusted execution environment for an embedded device, and more particularly, to a system for implementing a software-based trusted execution environment for an embedded device and a method therefor for building a trusted execution environment in an embedded device.

[0002] Low-end embedded devices typically have limited processing power and memory capacity. These limited hardware resources make it difficult to implement the security features necessary for a trusted execution environment. For example, implementing a root of trust using hardware security modules or keys can ensure good security. However, the lack of hardware resources on low-end embedded devices makes this approach difficult to implement.

[0003] A Trusted Execution Environment (TEE) is a reasonable security measure for protecting security-critical services and data in embedded devices. Considering ARM's high market share in mobile and embedded devices (90% for mobile, IoT, and in-vehicle systems), TrustZone, a security extension for ARM processors, is the most powerful means of enabling a TEE in embedded devices.

[0004] TEE technologies like ARM TrustZone enable memory protection and secure communication with peripherals. Despite their usefulness, their use has been limited. TEE implementations are typically confidential and only available to SoC developers, making them difficult for third parties to leverage. Furthermore, publicly available, low-spec devices like the RPI sometimes lack essential hardware features for TEE configuration.

[0005] In real-world environments, the deployment of TEEs is limited for the following reasons: Embedded devices sometimes lack the hardware implementation necessary to build a TEE. For example, the Broadcom BCM2837 SoC deployed in the smart hub, a user device, does not support the TrustZone extension for memory and peripheral isolation.

[0006] [Prior Art Literature]

[0007] [Patent Document]

[0008] Korean Patent Publication No. 2011-0037140 (published on April 13, 2011)

[0009] The purpose of the present invention is to provide a system and method for implementing a software-based trusted execution environment in an embedded device to supplement the absence of hardware support (TZ-ASC, TZ-PC) for building a trusted execution environment in a low-spec embedded device based on the ARM architecture.

[0010] According to the present invention, a stage-2 paging unit that independently manages memory in each execution environment by separating a software-based trusted execution environment (TEE) and a general execution environment (REE) of an embedded device, a DMA filtering unit that filters DMA transactions that directly transfer data from an input / output (I / O) device to memory in order to prevent malicious DMA attacks, a memory isolation and protection unit that isolates a TEE, a REE, a hypervisor, and a security monitor, a temporary privilege escalation / demotion unit that temporarily performs privilege escalation or demotion so that resources provided by a general execution environment can be used when performing security-related tasks in the trusted execution environment, and a secure input / output unit that logs and verifies input and output operations between the TEE and the REE.

[0011] The Memory Isolation and Protection Unit achieves memory isolation based on stage-2 paging of virtualization technology, thereby compensating for the absence of memory isolation hardware (TZ-ASC).

[0012] Additionally, the temporary privilege escalation / demotion part compensates for the absence of secure input / output hardware (TZ-PC) by reusing device drivers to temporarily escalate / degrade privileges in input / output operation code blocks.

[0013] Meanwhile, a method using a system for implementing a software-based trusted execution environment of an embedded device includes (a) a step in which the system separates a software-based trusted execution environment (TEE) and a general execution environment (REE) of the embedded device and independently manages memory in each execution environment, (b) a step in which the system filters DMA transactions that directly transfer data from an input / output (I / O) device to memory, (c) a step in which the system isolates a TEE, an REE, a hypervisor, and a security monitor, (d) a step in which the system performs privilege escalation or decriminalization so that resources provided by a general execution environment can be temporarily used when performing a security-related task in the trusted execution environment, and (e) a step in which the system performs logging and verification of input and output operations between the TEE and the REE.

[0014] According to the present invention, there is an effect of safely protecting data in an embedded environment without hardware support for establishing a trusted execution environment and achieving secure input / output for secure communication between hardware and the trusted execution environment.

[0015] FIG. 1 is a diagram illustrating a framework of a system for implementing a software-based trusted execution environment of an embedded device according to one embodiment of the present invention.

[0016] FIG. 2 is a configuration diagram showing a system for implementing a software-based trusted execution environment of an embedded device according to one embodiment of the present invention.

[0017] FIG. 3 is a flowchart illustrating a method using a system for implementing a software-based trusted execution environment of an embedded device according to one embodiment of the present invention.

[0018] Figure 4 illustrates the communication process between an application and a peripheral device.

[0019] Figure 5 illustrates the physical memory layout and memory permission settings for protecting TEE and MyTEE components.

[0020] Figure 6 illustrates MyTEE verifying DMA control blocks to prevent malicious DMA from being triggered on untrusted operating systems.

[0021] Figure 7 illustrates how MyTEE checks the CB settings in DMA 2-dimensional (TD) mode to ensure that the DMA does not access the protected area in each data transfer iteration.

[0022] Figure 8 shows that the combination of temporary privilege escalation in the device driver partition and shared and stage-2 page tables enables safe IO without bloating the TEE.

[0023] Figure 9 shows Listing 1: the original function with writel and Listing 2: the function with the MyTEE API added.

[0024] Figure 10 illustrates the communication process of security IO.

[0025] Figure 11 shows the results of running LMBench and CoreMark-PRO.

[0026] Figure 12 shows the performance of data transfer between memory in DMA TD mode with CB verified by MyTEE.

[0027] Figure 13 shows the performance (in microseconds) of random number generation and hashing with SHA1 and SHA256 in a hardware TPM.

[0028] The present invention is intended to supplement the absence of hardware support (TZ-ASC, TZ-PC) for establishing a trusted execution environment in low-spec embedded devices based on the ARM architecture, and proposes a system for implementing a software-based trusted execution environment in an embedded device that enables use of TEE even under the worst-case conditions where TEE essential hardware is not provided.

[0029] The core technology stack of myTEE includes memory separation / isolation technology based on virtualization technology, MMIO filtering, IOMMU, and secure IO channel with peripheral devices.

[0030] MyTEE is a solution for strengthening the Trusted Execution Environment (TEE). It protects and strengthens TEEs in environments without hardware support, such as TrustZone, a hardware security feature. This allows TEE platforms like the open-source OP-TEE platform to be protected even in restricted environments. MyTEE protects TEEs through memory protection, DMA attack prevention, and secure IO. For memory protection, it uses an active integrity monitor with stage-2 paging and a DMA filter to prevent DMA attacks. It also uses the MyTEE API to protect pDrv and cDrv for secure IO. These MyTEE components run in monitor and hypervisor modes, forming the Trusted Computing Base (TCB). This enhances the security of both the TEE and MyTEE.

[0031] In particular, the system for implementing a software-based trusted execution environment for an embedded device according to the present embodiment provides a myTEE API that elevates the privileges of a portion of the device driver's code instead of protecting the entire code, thereby enabling a developer to form a secure communication channel with a peripheral device while minimizing direct modification of privileged software.

[0032] The prototype demonstrated the feasibility of myTEE by implementing it on an RPi board that does not support most TrustZone extensions. As example software, myTEE was used to implement hardware TPM, framebuffer, and USB keyboard protection.

[0033] Regarding the effectiveness of TEE technology, TEE technology, which establishes an additional trusted execution environment within the system to protect critical services and data, is a promising security technology that can alleviate these issues. In particular, ARM TrustZone is a security extension for ARM processors primarily used in mobile and embedded devices. When TrustZone is activated, in addition to dividing the CPU state into secure and non-secure states, it also isolates the TEE area through hardware-based memory access control and enables direct communication between peripherals and the TEE, enabling secure IO configuration.

[0034] In one embodiment of the present invention, myTEE is proposed to complement the absence of hardware support (TZ-ASC, TZ-PC) for building a trusted execution environment in low-spec embedded devices based on the ARM architecture. The lowest-end device is assumed, which does not provide additional TrustZone functions other than CPU security state distinction. In other words, memory protection through the TrustZone Address Space Controller (TZASC) or secure communication with peripherals through the TrustZone Protection Controller (TZPC) are not possible. To enhance the reliability and security of the TEE in such an environment, the core of myTEE is a technology that provides TEE memory isolation, DMA attack defense, and secure communication methods with peripherals.

[0035] First, memory protection utilizes a page table management-based approach. Direct access to the TEE from the REE is controlled by not creating an s2 mapping for the TEE area. Furthermore, to prevent TEE access by hypervisor-privileged code that is not affected by s2 paging, the page tables used by the hypervisor are also managed in the TEE area. In addition to the page tables, other key instructions are emulated in the TEE area. When utilizing a DMA (Malicious Direct Memory Access) engine, an attacker can write or read any area in environments without an IOMMU (Input / Output Memory Management Unit) or TZASC (TrustZone Address Space Controller). This means that even the TEE area protected by s2 paging is vulnerable to attack. To prevent this, a filter is configured to trap and pre-verify MMIO requests to the DMA engine as s2. To ensure secure communication with peripherals, requests to peripherals are delegated to the REE area. First, the MMIO area of ​​the communication buffer and controller is protected by s2 paging. Furthermore, the privileges of a portion of the device driver code accessing this are elevated to the hypervisor, enabling normal operation. The resulting values ​​generated by the peripheral are written to a protected buffer, which is directly consumed by the TA. This method has the advantage of not increasing the size of the TEE area, thus creating no new attack vectors.

[0036] For the myTEE implementation, we used the RPI3 B+ board, which provides the BCM2837 SoC, as the implementation device. OP-TEE was used as the TEE software, and the REE used Raspbian OS with Linux version 4.15. OP-TEE is open source software that implements a secure execution environment (TEE) by utilizing ARM TrustZone. OP-TEE can be used on various operating systems such as Android and Linux, and operates on ARM-based processors such as the ARM Cortex-A series. OP-TEE provides secure applications and kernel modules that run in the TEE environment, and safely protects data in the TEE environment and provides secure authentication and encryption services.

[0037] Page table management and emulation for memory protection were implemented as part of ARM TF. ARM TrustZone Firmware (TF) is a program that runs on a TrustZone-enabled System-on-Chip (SoC) and is responsible for maintaining and managing the security and stability of TrustZone. A microhypervisor was implemented to protect MMIO filters and peripherals. In particular, hypervisor service calls, such as device driver privilege escalation, were implemented in the form of myTEE APIs so that they can be inserted into driver implementations. To demonstrate the practicality of myTEE, three security applications were implemented that ensure secure communication with peripherals—a hardware TPM, a framebuffer, and a USB keyboard. The myTEE API was inserted into the protocol controller (e.g., SPI and USB) and device drivers used by each peripheral to protect the buffers used for communication and to allow the code accessing these buffers to execute properly through partial privilege escalation.

[0038] FIG. 1 is a diagram illustrating a framework for explaining a system for implementing a software-based trusted execution environment of an embedded device according to one embodiment of the present invention.

[0039] As illustrated in Figure 1, MyTEE consists of an active integrity monitor for memory isolation, a DMA packet filter, and secure IO. It is a framework that can isolate and protect security-critical components based on Stage-2 paging and DMA filtering implementation of virtualization technology, and achieve secure I / O by utilizing security buffers and operation log verification.

[0040] The software-based trusted execution environment implementation system (MyTEE) for embedded devices according to this embodiment aims to enable TEEs in strictly restricted environments where hardware security extensions are not supported. This means that open-source TEE platforms, such as OP-TEE, can be protected by MyTEE even when deployed in such restricted environments. To support memory protection without TZASC, the active integrity monitor uses two-phase paging to isolate memory and release kernel privileges (VB). Furthermore, the DMA filter, which monitors all MMIO transactions to the DMA controller, prevents DMA attacks (VC). For secure IO, pDrv and cDrv are enhanced using the MyTEE API to protect the controller's IO buffers and memory-mapped registers and to ensure safe and seamless access by portions of device driver code (VD). Specifically, MyTEE, running in hypervisor and monitor mode, constitutes a trusted computing base (TCB). Specifically, DMA filtering and oversight of critical operations can strictly isolate trusted components from the untrusted OS. Additional trusted services, such as SecureIO, are built on top of isolation.

[0041] FIG. 2 is a configuration diagram of a system for implementing a software-based trusted execution environment of an embedded device according to one embodiment of the present invention.

[0042] As illustrated in FIG. 2, the system (10) for implementing a software-based trusted execution environment of an embedded device according to the present embodiment includes a stage-2 paging unit (110), a DMA filtering unit (120), a memory isolation and protection unit (130), a temporary privilege escalation / decrease unit (140), and a secure input / output unit (150).

[0043] The stage-2 paging unit (110) is a configuration that maps the virtual address space (VAS) to the physical memory space (Physical Memory). This stage-2 paging unit (110) is one of the virtualization technologies provided by the ARM architecture, and it isolates the TEE and REE and enables independent memory management in each execution environment. To this end, the stage-2 paging mechanism is used to map the virtual address space to the physical memory space.

[0044] Stage-2 paging, a virtualization technology provided by the ARM architecture, is a mechanism that maps a virtual address space (VAS) to physical memory. In virtualization technology, a hypervisor maps the virtual address space of a guest operating system to physical memory. However, the ARM architecture uses TrustZone technology, which is used in conjunction with the hypervisor, to separate a secure trusted execution environment (TEE) from a regular execution environment (REE), allowing each execution environment to manage memory independently.

[0045] Stage-2 paging in virtualization technology maintains separate page tables for each execution environment to isolate the Trusted Execution Environment (TEE) and Rich Execution Environment (REE). These page tables are used to map virtual address space to physical memory space, isolating memory access between the TEE and REE.

[0046] The page tables of the TEE and REE are used in different privilege modes, limiting the physical memory space accessible in each execution environment. In the ARM architecture, the TEE and REE run in their own privilege modes. The TEE runs in Secure Monitor mode, and the REE runs in Non-secure mode. Therefore, the TEE and REE operate in different privilege modes. These privilege modes are also called protected modes in ARM. Each protected mode defines the instruction set that the CPU can execute and limits memory access permissions, and the instructions for switching between protected modes are also different. The TEE has restricted instructions and memory access permissions to maintain a secure environment, while the REE has the same permissions as general applications.

[0047] Additionally, it provides memory protection using page tables and allows you to configure memory protection levels.

[0048] Stage-2 paging of this virtualization technology isolates the TEE and REE to enhance security and allows each execution environment to manage memory independently.

[0049] That is, the TEE and REE must be allocated different memory areas, and for this, virtualization technology's stage-2 paging is used. Each environment has its own virtual address space, which is mapped to physical memory. This allows the TEE and REE to independently manage memory in different memory areas, and code or data executed in the TEE does not affect other environments, such as the REE or hypervisor.

[0050] The DMA filtering unit (120) is configured to filter DMA transactions to defend against malicious DMA attacks. This prevents the TEE's memory from directly accessing the REE's input / output (I / O) devices.

[0051] Direct Memory Access (DMA) filtering is a configuration designed to protect the system from malicious DMA attacks. DMA is a technology that directly transfers data from input / output (I / O) devices to memory, improving I / O performance. However, because DMA is not typically monitored by the CPU, malicious code can access memory and compromise system security.

[0052] DMA filtering examines DMA transactions and blocks unsafe transactions to defend against these malicious DMA attacks. DMA filtering is implemented using a combination of hardware and software.

[0053] On the software side, a DMA filtering driver operates. This driver monitors DMA transactions and blocks unauthorized DMA transactions based on filtering rules. These filtering rules can vary depending on the system's security policy and include rules that restrict DMA transactions between input / output (I / O) devices and memory.

[0054] On the hardware side, the Input-Output Memory Management Unit (IOMMU) is used. The IOMMU provides the ability to map physical memory addresses to virtual addresses to protect DMA transactions. This limits the memory space accessible by DMA and prevents malicious DMA transactions.

[0055] Therefore, DMA filtering is an important security technology that protects the system from malicious DMA attacks while maintaining memory isolation of TEE and REE.

[0056] The memory isolation and protection unit (130) achieves memory isolation / protection by isolating the TEE, REE, hypervisor, and security monitor. This prevents security-related tasks executed in the TEE from affecting other environments, such as the REE or hypervisor.

[0057] The memory isolation and protection unit according to the present embodiment can achieve memory isolation based on stage-2 paging of virtualization technology, thereby compensating for the absence of memory isolation hardware (TZ-ASC).

[0058] TEEs and REEs must be allocated separate memory regions. To achieve this, virtualization technology's stage-2 paging prevents code or data running in the TEE from affecting other environments, such as the REE or the hypervisor. Furthermore, a security monitor controls memory access between the TEE and REE, preventing code or data running in the TEE from invading the REE's memory. The hypervisor hosts multiple virtual machines and isolates the various operating systems and applications running concurrently in each virtual machine, thereby protecting them from other environments.

[0059] These memory isolation and protection components are important elements that enhance the security of the system, ensuring that code or data running in the TEE performing security-critical tasks are protected from external sources.

[0060] Memory isolation and protection are implemented using stage-2 paging, a virtualization technology. This isolates the virtual address space of applications, restricts memory access permissions, and supports memory encryption when necessary. These features complement the absence of a hardware-based memory isolation system, the TrustZone Address Space Controller (TZ-ASC). In other words, the memory isolation and protection unit uses virtualization technology to achieve memory isolation through software. This can replace existing hardware-based memory isolation systems and provide a high level of security.

[0061] Memory isolation hardware (TZ-ASC) is a memory protection feature provided by the existing ARM TrustZone architecture that controls access to physical memory addresses. This memory protection is crucial for secure system operation against memory attacks. However, many devices without TZ-ASC use memory isolation technology to achieve memory protection. Memory isolation technology creates isolated environments, such as processes or containers, to prevent them from interfering with each other. MyTEE uses memory isolation technology to isolate the memory space of applications and the protected area. It does this by using stage-2 paging to separate the virtual address space of the protected area from the application. This prevents applications from directly accessing the memory space of the protected area. Instead, MyTEE provides the interfaces necessary to access and execute memory in the protected area and memory isolation.

[0062] In other words, MyTEE enables memory isolation and protection even on devices without memory isolation hardware (TZ-ASC). This ensures safer and more reliable system operation.

[0063] The temporary privilege escalation / demotion unit (140) allows temporary privilege escalation from the REE when performing security-related tasks in the TEE, if necessary. Furthermore, privilege escalation can be returned to the TEE after the task is completed.

[0064] The temporary privilege escalation / demotion according to this embodiment can compensate for the absence of secure input / output hardware (TZ-PC) by reusing device drivers to temporarily escalate / degrade privileges of input / output operation code blocks.

[0065] This temporary privilege escalation / demotion mechanism allows the REE to temporarily escalate privileges and access resources provided by the REE when security-related operations running in the TEE require such resources. This allows the TEE to run in its own securely isolated environment while still accessing resources provided by the REE when necessary.

[0066] Typically, TEEs and REEs run in different privilege modes, with the TEE running in least-privilege mode. Therefore, the TEE cannot directly access resources provided by the REE when performing security-related tasks. However, by utilizing the temporary privilege escalation / demotion provided by the REE, the TEE can temporarily use resources provided by the REE while remaining securely isolated.

[0067] For example, a TEE uses securely isolated storage to store encrypted data, while a REE uses a file system to store files. When the TEE needs to store encrypted data in the file system, the TEE cannot directly access the file system resources provided by the REE. In this case, the temporary privilege escalation / demotion provided by the REE can be used to temporarily access the file system resources provided by the REE to store encrypted data. Once the task is complete, the privileges are escalated back to the TEE. This temporary privilege escalation / demotion allows the TEE and REE to share necessary resources while maintaining secure isolation.

[0068] Secure Input / Output Hardware (TZ-PC) protects I / O by preventing user-space code from directly accessing I / O ports. However, in some scenarios, user-space code may need to access I / O ports directly. To address this, the temporary privilege escalation / demotion unit reuses device drivers to temporarily escalate / degrade privileges in I / O operation code blocks, thereby compensating for the absence of Secure Input / Output Hardware (TZ-PC).

[0069] That is, temporary privilege escalation / demotion allows user-space code to access and use I / O ports. However, this temporary privilege escalation / demotion is only possible for a short period of time, thus maintaining security. This compensates for the absence of secure I / O hardware (TZ-PC) and protects secure I / O.

[0070] Secure I / O hardware (TZ-PC) typically operates only in trusted environments and is not supported by standard operating systems. Therefore, MyTEE utilizes reusable device drivers to achieve temporary privilege escalation / demotion of I / O operation code blocks to support secure I / O even in standard operating system environments.

[0071] To facilitate temporary privilege escalation / demotion, MyTEE provides a new device driver implemented as a Linux kernel module. This driver handles secure I / O in the kernel, enabling temporary privilege escalation / demotion. This driver is loaded into kernel memory and leverages MyTEE's memory isolation and protection features to protect secure I / O buffers.

[0072] This driver can forward the results of requests processed by MyTEE to user space, and user space can transmit data through the driver. This means that it compensates for the absence of secure input / output hardware (TZ-PC) while ensuring secure data transfer between MyTEE and the general operating system through temporary privilege escalation / demotion.

[0073] The secure input / output unit (150) utilizes Secure I / O technology, utilizing input / output hardware operation logging and log verification technology to safely perform input / output operations between the TEE and the REE. This protects access to the REE's input / output devices from the TEE.

[0074] The secure input / output unit (150) is configured to securely perform input / output operations between the TEE and the REE. This configuration utilizes Secure I / O technology to log and verify input and output operations. This prevents the TEE from directly accessing the REE's input / output devices and instead processes input / output operations requested by the REE through the secure input / output unit. This allows the TEE to perform security-related operations independently of the REE, while remaining securely protected from security threats arising from the REE.

[0075] Additionally, the secure input / output unit performs security verification on input and output data. This involves verifying the integrity of input and output data and checking for attempts to falsify or alter it. Only data verified in this way is processed in the TEE.

[0076] Therefore, the secure input / output unit safely processes input / output operations between the TEE and REE, and plays a role in strengthening security.

[0077] FIG. 3 is a flowchart illustrating a method using a system for implementing a software-based trusted execution environment of an embedded device according to one embodiment of the present invention.

[0078] As illustrated in FIG. 3, a method using a system for implementing a software-based trusted execution environment of an embedded device (hereinafter referred to as the system) comprises: (a) a step in which the system separates a software-based trusted execution environment (TEE) and a general execution environment (REE) of the embedded device through a stage-2 paging unit and independently manages memory in each execution environment; (b) a step in which the system filters DMA transactions that directly transfer data from an input / output (I / O) device to memory through a DMA filtering unit; (c) a step in which the system isolates a TEE, a REE, a hypervisor, and a security monitor through a memory isolation and protection unit; (d) a step in which the system performs privilege escalation or decriminalization so that resources provided by a general execution environment can be temporarily used when performing a security-related task in the trusted execution environment through a temporary privilege escalation / demotion unit; and (e) a step in which the system logs and verifies input and output operations between the TEE and the REE through a secure input / output unit.

[0079] Hereinafter, a system for implementing a software-based trusted execution environment for an embedded device according to the present embodiment will be described.

[0080] The system for implementing a software-based trusted execution environment for embedded devices according to this embodiment proposes a method for safely configuring a TEE, assuming a worst-case scenario where the hardware functions utilized in TEE configuration are minimally supported. Furthermore, to prevent TEE bloat, secure IO is implemented by reusing device drivers. Furthermore, considering usability, the system provides a kernel API that device driver developers can easily use.

[0081] Here, bloating refers to the presence of unnecessary or duplicate code or functions, which renders the system inefficient in various aspects, including its size. Because TEEs must operate with limited memory and resources, a compact and lightweight configuration is ideal. Therefore, bloating can negatively impact TEE performance and stability. Therefore, to prevent TEE bloat, existing device drivers can be reused to implement necessary functions, while unnecessary functions can be removed to maintain a lightweight configuration.

[0082] In order to complement the absence of hardware support (TZ-ASC, TZ-PC) for building a trusted execution environment in low-spec embedded devices based on the ARM architecture, a system for implementing a software-based trusted execution environment in an embedded device is proposed. Specifically, the system utilizes the stage-2 paging of the virtualization technology provided by the ARM architecture and implements a DMA filter to defend against malicious DMA attacks, thereby isolating the general execution environment (REE, Rich Execution Environment) and the trusted execution environment (TEE, Trusted Execution Environment), hypervisor, and security monitor to achieve memory isolation / protection. In addition, secure input / output (Secure I / O) is achieved by utilizing temporary privilege escalation / demotion technology and input / output hardware operation logging and log verification technology. Based on these contents, memory isolation is achieved based on the stage-2 paging of the virtualization technology to complement the absence of memory isolation hardware (TZ-ASC).

[0083] In this embodiment, ARMv8, a 64-bit ARM architecture used in ARM development boards, is used as an example.

[0084] -Security states

[0085] On devices with TrustZone enabled as a security extension, the security state is divided into two: secure and non-secure. The non-secure state is used to configure the general execution environment and is divided into user, kernel, and hypervisor privileges. The user has the lowest privilege, and the hypervisor has the highest privilege. Access from low privilege to high privilege is possible by executing special instructions. For example, access from the user to the kernel is possible with svc, and access from the kernel to the hypervisor is possible with hvc. The secure state is used to configure a high-security execution environment, such as a trusted execution environment. Prior to ARMv8.4, user, kernel, and monitor modes were provided, and from version 8.4 onwards, hypervisor mode is also provided in the secure state.

[0086] Monitor mode, the highest-privileged mode in the system, is a special mode for transitioning between secure and non-secure states. Its primary function is to store contextual information about the environment in which each state is executed. Monitor mode can be entered synchronously using smc.

[0087] Monitor and hypervisor modes are primarily used to implement security technologies. To ensure kernel integrity, kernel code and data are mapped to the Resource Access Point (RO), and page tables are also mapped to the RO. Furthermore, updates to page tables and base registers are enforced by the monitor. In 64-bit environments, a similar approach is implemented using hypervisor mode. The hypervisor utilizes nested paging to override memory properties of less privileged software or trap privileged instructions, making it useful for implementing various security applications.

[0088] In addition to the security state, the following TrustZone hardware components are defined to enable the implementation of various security applications. TZASC or TZMA can be used to partition physical memory (DRAM or SRAM) and enforce hardware access control. For example, memory allocated to the Trusted Execution Environment (TEE) can be enforced to be accessible only when in the secure state. Furthermore, TZPC can be used to dynamically transition a specific device to a secure / non-secure state.

[0089] This ensures that the TEE has exclusive use of specific peripherals (e.g. keypads).

[0090] Unlike the preceding security state, these features are optional and their application may vary depending on the SoC.

[0091] -Execution states

[0092] ARMv8 supports both 32-bit and 64-bit architectures. Here, there is a condition for determining the execution state according to the mode's privilege: the execution state of a lower privilege must be equal to or lower than the execution state of a higher privilege. For example, if the monitor mode is implemented in 32 bits, the hypervisor and kernel above it are also implemented in 32 bits. If the hypervisor is 64 bits, the kernel can have either 32 or 64 bit execution states. In addition, in a 32-bit environment, two page table formats are supported. When using the 4-byte short-descriptor format, a 32-bit virtual address can be converted, and in the 8-byte long-descriptor format, up to 40 bits can be converted.

[0093] Hypervisor memory areas and nested paging use only the long-descriptor format, while the kernel and user can use both formats.

[0094] - Communication with Peripherals

[0095] Peripherals can communicate with the host computer using various protocols, such as Serial Peripheral Interface (SPI), Inter-Integrated Circuit (I2C), Peripheral Component Interconnect (PCI), and Universal Serial Bus (USB). Each protocol's controller handles communication management tasks, such as assigning device addresses, selecting communication channels, and initiating transactions. These tasks are accomplished by setting memory-mapped controller registers.

[0096] pDrv and cDrv are two sub-drivers among the device driver components that manage peripheral devices and controllers. pDrv: Peripheral Driver is a driver that controls peripheral devices connected to the system. Peripheral devices are external devices connected to the system, such as the mouse, keyboard, display, and network interface card. pDrv provides an interface between these peripheral devices and the kernel, and manages the interaction between the hardware and software of the devices.

[0097] cDrv: Controller Driver is a driver that manages hardware controllers that control peripheral devices. Controllers are devices that act as a bridge between hardware and software, such as disk controllers, network controllers, and USB controllers. cDrv manages the interaction between these controllers, hardware, and software, enabling efficient control of peripheral devices. Therefore, pDrv is a driver that manages the interface between peripheral devices and the kernel and manages the interaction between the hardware and software of the device, while cDrv is a driver that manages the hardware controller that controls the peripheral devices and manages the interaction between hardware and software.

[0098] User processes interact with device drivers to communicate with peripheral devices. The controller driver (cDrv) and the peripheral driver (pDrv) participate in this communication. pDrv provides interfaces such as ioctl, write, and read to interact with user processes. It also generates protocol (e.g., USB) messages that convey necessary information, such as IO buffers and peripheral device addresses. cDrv retrieves information from the messages and configures the controller via MMIO. It also reads data from the IO buffer and transmits it to the peripheral connected to the controller. The peripheral's responses are also read from and written to the buffer. These memory operations can be performed via DMA to minimize CPU load. For example, the cDrv of an SPI controller can configure a DMA controller, with the source and destination set to a buffer and an SPI FIFO register, respectively. Figure 4 illustrates the communication process between an application and a peripheral device.

[0099] Embedded devices are actively used in various fields such as IoT and FL, but the hardware-based security functions mentioned above are sometimes provided in a limited manner or not provided at all.

[0100] Table 1 below shows the hardware features related to TEE and the inclusion of SMMU functions in commonly used ARMv8-based embedded boards. Here, SMMU stands for System MMU, a device that maps virtual addresses to physical addresses in ARM architecture-based systems. SMMU strengthens system security by filtering access to specific devices or memory in a virtualized environment and managing securely isolated areas. SMMU, also known as IOMMU, performs virtual address mapping for input / output devices and plays a key role in strengthening memory isolation between TEE and REE. In ARMv8 architecture-based systems, SMMUv3 is the latest version.

[0101] [Table 1]

[0102]

[0103] The investigation focused primarily on SoC manuals, Linux, and the source code of the open-source TEE platform (OP-TEE). An "x" indicates that the hardware feature is not available, while an "O" indicates that the feature exists and its usage and other information are publicly available through the source code or manual. A "v" indicates that a similar feature exists in the specifications or source code, although its presence is not specifically specified in the board manual. For example, on the Coral board, OCRAM divides SRAM into secure and non-secure sections, and is assumed to be similar to the TZMA function. Regarding the TZASC of the hikey960, the existence of the "hikey960_tzc_init" function in the Trusted firmware indicated that TZASC was supported. However, only the registers and hard-coded values ​​newly defined by hisilicon, not the registers defined in the TZASC specification, were known. The specifications of the hardware security features required to implement a TEE are accessible only to contractors of the SoC manufacturer. Furthermore, these functions are controlled by TEE software provided by the manufacturer, such as QSEE, Tgris, and knibi.

[0104] These system software are locked with hardware keys and secure boot. Therefore, embedded service providers can only deploy user-level trusted applications, and system-level changes can only be implemented with the manufacturer's verification and consent. These issues hinder meeting time-to-market requirements and ultimately hinder the use of TEEs. This study aims to address these issues by reducing device manufacturers' reliance on TEEs and hardware TEE features (TZASC, TZPC, SMMU). Specifically, we configure a third-party TEE using only open TEE software (OP-TEE) and minimal hardware features, enabling users to maximize their benefits.

[0105] Regarding the attack model and assumptions, it follows the typical TEE attack model. That is, the OS is untrusted. Therefore, an untrusted OS can attempt to access or modify kernel code or data. It can also freely send requests to hardware devices such as DMA controllers. However, there are no TrustZone extension hardware features, such as TZASC, that can protect the TEE, and only CPU-based security states are supported. Therefore, even if TEE software such as OP-TEE is installed, free access to TEE memory is permitted (quote: optee-rpi). On the other hand, secure boot is assumed as the baseline defense, so modification of firmware, bootloader, and kernel images is impossible.

[0106] A typical secure boot relies on a root key embedded in the hardware to verify the integrity of the images loaded during boot. However, this approach is not feasible in environments like the RPi, where TEE-related hardware is not provided. Fortunately, an SD card-based secure boot method is available. This means that the area where the image is flashed on the SD card can be enforced to prevent tampering. Furthermore, the host device and its installed peripherals are assumed to be trusted and physically isolated.

[0107] Therefore, attacks such as malicious hardware, SD card modification, and cold boot attacks are not considered. Furthermore, side-channel attacks such as cache and speculative execution are excluded from the scope of this paper.

[0108] Regarding system design, this embodiment proposes a method for utilizing TEE functionality in environments where hardware security features are unavailable or limited. Based on RPI3, which provides the most outdated features, this paper proposes a method for supplementing the missing hardware features. Specifically, myTEE is added to the publicly available OP-TEE to ensure the intended security of the TEE while allowing for flexible application. To emulate the TZASC feature, which protects TEE memory, the hypervisor's s2 paging and deprivileging kernel technology are utilized.

[0109] Furthermore, to defend against attacks on the TEE area and myTEE that exploit DMA in environments where TZASC and SMMU are missing, we configure an MMIO monitoring-based DMA filter. To realize secure IO using TZPC, we propose a method to protect the device drivers of hypervisor-based peripherals and controllers. Instead of protecting the entire device driver, we protect the buffers passed to the device and the controller's memory-mapped registers with s2, and partially elevate the privileges of some of the driver code that accesses them to allow access to the area protected by s2. Furthermore, applications running in the TEE can directly read / write to the protected buffers, enabling IO without malicious kernel intervention. The privilege escalation and protection have the advantage of allowing the insertion of myTEE's API when implementing Linux device drivers and minimizing the hypervisor implementation.

[0110] Regarding Execution Environment Separation and Isolation (TEI), isolation for the TEE area can no longer be guaranteed due to the missing TZASC. To address this issue, traditional virtualization-based memory separation was implemented.

[0111] Basically, myTEE defines three areas: the TEE, the hypervisor, and the normal OS. The TEE is where TEE software, such as OP-TEE, resides. The hypervisor area defines handlers for handling several hypercalls defined by myTEE. myTEE also allows some kernel code to be executed with hypervisor privileges, and the stack memory and data areas used for this are also defined as hypervisor areas. In particular, the hypervisor uses the same page table as the OS kernel to elevate the privileges of the OS kernel code. This allows the kernel-defined API (memcpy) to be executed by changing the current CPU mode to the hypervisor without any significant hypervisor mapping changes.

[0112] To prevent this, memory permissions were configured so that the kernel could modify the page table to access the hypervisor area or TEE.

[0113] First, the kernel's page table maps all areas except the TEE. At this time, the hypervisor code area is granted execution privileges, while the stack and data areas are granted RW privileges, allowing elevated code to access and execute data in sec memory. Furthermore, the s2 page table is set at boot time to prevent the hypervisor and TEE areas from being accessed by the normal OS. This prevents the normal OS from directly accessing the hypervisor or TEE to launch attacks.

[0114] However, if the code executed through privilege escalation is compromised, it can attempt to access the TEE by modifying the OS page table. This is because hardware access control to the physical space is impossible due to the absence of TZASC, and therefore, the hypervisor can access the TEE space through page table manipulation. To prevent such attacks, methods such as TZRKP were used.

[0115] That is, the kernel page table itself is set to RO, and the instructions for updating the page table and base register are patched with SMC so that they can be updated after verification in the TEE area. This makes it impossible to tamper with even if a hypervisor that uses the same page table as the OS is compromised.

[0116] Furthermore, malicious page tables cannot be used because code executing with hypervisor privileges lacks instructions that can modify the base register. One possibility is to tamper with the execution flow of code executing with hypervisor privileges. However, even this attack is easily prevented. Privilege escalation occurs only with very simple code, such as memcpy, and is easily verifiable. Furthermore, address verification is performed before memcpy to prevent reads and writes to arbitrary memory.

[0117] Regarding DMA Filter, the explanation is as follows.

[0118] Properly defending against DMA attacks is crucial in myTEE's design. This is because, without hardware-based memory access control (TZASC), an attacker can exploit the DMA controller to modify myTEE API calls within the TEE, hypervisor, or kernel. DMA attacks can be broadly categorized into two types, depending on where they are triggered.

[0119] The first attack involves a malicious hardware device performing memory manipulation via DMA requests. However, this scenario is not considered because the presence of malicious hardware is assumed to be excluded. The second scenario involves a malicious kernel requesting read / write access to a specific memory region via DMA. This is possible by manipulating the source address, target address, and length values ​​of the request packets sent to the DMA controller. Therefore, packets sent from the kernel to the DMA controller must be properly monitored.

[0120] Packets are transmitted to the DMA controller via MMIO by passing the packet structure address. To monitor this, the area where the DMA controller's registers are mapped is made read-only using s2 paging. Whenever the kernel attempts to write to the register, an s2 page fault occurs, requiring a handler in the hypervisor space to verify and then perform DMA. Verification determines whether the source and target addresses, along with their lengths, belong to the kernel code and data, the TEE space, the hypervisor's exception handler and data space, and the monitored DMA controller MMIO space. If no problems are found, emulation is performed. To prevent race conditions that may occur between verification and emulation, the address value written to the controller is dereferencing to find the packet and copying it as a shadow packet in the hypervisor space. Furthermore, DMA to protected buffers, which are not relevant to the application, is also considered. For example, if the source or target is a protected buffer, the target or source address must also be a protected buffer. This is to prevent an attacker from leaking a secret value written by a normal device or modifying the value to a value known to the attacker (a random value generated by the TPM).

[0121] In addition to standalone DMA controllers, USB controllers sometimes have their own DMA engine. In these cases, unlike the previous DMA controller, DMA packets only have a single source or target address. For example, a value entered on a USB keyboard is read from the USB controller's FIFO and DMA'ed to a buffer specified in the packet. This situation must also be monitored, as an attacker can write to arbitrary areas even if they do not have complete control of the source data. Therefore, the register area for configuring the USB controller's DMA engine is also set to s2 RO and monitored. The monitoring rules are the same as for the previous general DMA controller, except for the rules for protected buffers. DMA to protected buffers is not permitted except in special cases. For example, when protecting keyboard input, only keystroke information transmitted from the keyboard is allowed to be DMA'ed to the protected buffer.

[0122] Regarding peripheral isolation, the TZPC is used to establish a secure channel between the peripheral and the TEE. However, low-end devices lack the TZPC, making it impossible to implement secure peripherals utilizing this hardware feature. In this embodiment, we will discuss how myTEE achieves peripheral isolation to enable secure use by the TA. Here, TA stands for Trusted Application, meaning a securely executed application. This application runs in the TEE and operates in a securely protected memory area. Through the interface between the TEE and the REE, the REE can execute the TA or transmit data to the TEE.

[0123] Regarding design primitives for secure peripherals, previously, TZPC was used to set peripherals to a secure state and device drivers were implemented within the TEE to provide dedicated peripheral access. However, this approach cannot be used in environments without hardware configurations like TZPC or TZASC, and implementing drivers within the TEE increases the potential vulnerabilities of the TEE.

[0124] myTEE, according to this embodiment, addresses these issues and allows secure use of peripherals even when they are shared with REE. myTEE's peripheral protection is based on the following design philosophies: (1) should not introduce a new attack surface to the TEE, (2) is flexible and easy to deploy, (3) operates precisely as expected, and (4) is not abused (priv up / down).

[0125] For (1), instead of implementing a kernel driver within the TEE, the kernel driver of the OS is reused. To achieve this, the CA is used as a proxy that forwards the TA's request to the kernel driver. The kernel drivers can be organized into pDrv and cDrv as previously explained. pDrv receives a user request and generates request data. cDrv protects both drivers by transmitting the request to the hardware via MMIO. Protecting both drivers increases the likelihood of vulnerabilities and increases security considerations (in particular, verification is impossible due to the need to protect all kernel APIs). Therefore, we protect only a portion of the device driver, not all of it. That is, we selectively protect the MMIO execution area for cDrv configuration and the input / output buffer of pDrv. At this time, depending on the peripheral device and scenario, the confidentiality of the buffer or

[0126] The level of integrity protection can vary. For example, when printing medical data on a display using fb, both confidentiality and integrity are important. When requesting the TPM to generate a random value, the confidentiality of the TPM command in the buffer is not important; it only needs to be able to verify that a valid value has been transmitted.

[0127] To protect the integrity and confidentiality of the buffer, a shadow buffer is used within the memory area protected by S2. The MMIO area of ​​cDrv is also made inaccessible using S2. Therefore, the general kernel cannot access the buffer or perform mmio operations. Therefore, existing buffer access / mmio execution code is temporarily elevated to hypervisor privileges and executed.

[0128] To achieve this, we provide a developer-friendly priv up / down API. This API performs a hypervisor call, allocating a new stack, disabling interrupts, checking where the call originated (to prevent exploitation), and then immediately returning with hypervisor privileges. Code following priv up is executed with hypervisor privileges, allowing access to otherwise inaccessible areas. After completing the task, priv down is used, performing the opposite operation of up. Input data is written directly from the TA to the hypervisor-mapped area, and output data is read directly by the TA.

[0129] For (2), we are satisfied with partially increasing the privileges of kernel code. That is, in the traditional trap & emulate approach, verification / protection logic must be implemented in hypervisor code. Given that device drivers are implemented by third-party developers, this is challenging. We address this issue by allowing portions of the kernel driver to execute with hypervisor privileges. Developers can directly implement our generated myTEE API or verification logic within existing kernel driver logic.

[0130] For (3), the peripheral device must accurately fulfill the user's request. This requires protecting the request data passed to the peripheral device, which is difficult because kernel drivers are reused.

[0131] For example, if a hypervisor call inserted into kernel code is not executed, the MMIO area may not be protected. Furthermore, even if protected, because of the presence of private up / down code, an attacker can inject malicious values ​​into the code executing within the private up / down block, resulting in unintended consequences. This is similar to a race condition. For example, in a TPM, a TA may request a random value and send that request to the MMIO. However, before the TA reads the value, the attacker can induce the TPM to generate a value known to them by making another request. For example, by generating a hash value, the TA will perform an operation using the value known to the attacker. To prevent such attacks, we utilize logging and verification APIs. By defining a sequence, we always protect the buffer and MMIO areas before logging it. Afterwards, we log the request data. The TA performs verification before using it.

[0132] For (4), in addition to logging, verification logic is performed. The expected attack involves modifying or exploiting the values ​​executed in priv_up. Considering mmio write, it is possible to tamper with the target address value to launch an attack on the TEE or hyp area. To prevent this, the values ​​used for mmio write are first copied to the hypervisor stack and then verified. This prevents TOCTOU attacks, which modify values ​​after verification by copying parameters to a protected area. The verification logic includes a context for cDrv to verify whether the dest area belongs to that area. This is possible because the controller's mmio area address is determined during the SoC design. Furthermore, as previously mentioned, priv_up and down are enforced to be called only from compiled code. Therefore, kernel drivers must be statically built into the kernel and cannot be used in dynamically loaded drivers.

[0133] Considering (1)-(4), the existing writel function is placed in a new wrapper function using myTEE to write to the mailbox controller for exchanging messages with the GPU, and it is verified that the mmio target address is located in the register area of ​​the mailbox controller. After that, the command to be transmitted to the mailbox is logged and writel is performed. The wrapper function is called between priv_up and down and is executed with elevated privileges.

[0134] Additionally, since mytee_priv_up resets the current stack pointer to memory that is not accessible to the kernel, local variables (ret) used within the wrapper can be protected. In this example, the 32-bit parameters passed to the wrapper do not require a separate copy operation as they are passed by value. However, if they are passed by address value, an additional operation is required to dereference the address before verification and copy it into the protected stack. In addition, the mmio address area of ​​the example code is protected as an area inaccessible to the kernel by the mytee_controller_lock API call inserted into pDrv. The API call can be omitted by an attacker, but can be detected by the TA due to the missing logging.

[0135] static int bcm2835_send_data(struct mbox_chan *link, void *data){

[0136] ...

[0137] writel(msg, mbox->regs + MAIL1_WRT);

[0138] ...

[0139] }

[0140] mytee_wrapper(u32 msg, u32 mmio_addr){

[0141] int ret;

[0142] ret = mytee_verify_mmio(MAILBOX_WRITE, mmio_addr, sizeof(u32));

[0143] if (!ret){

[0144] mytee_log_trx(MAILBOX_WRITE, msg);

[0145] writel(msg, mmio_addr);

[0146] }

[0147] }

[0148] static int bcm2835_send_data(struct mbox_chan *link, void *data){

[0149] ...

[0150] mytee_priv_up();

[0151] mytee_wrapper(msg, mbox->regs + MAIL1_WRT);

[0152] mytee_priv_down();

[0153] ...

[0154] }

[0155]

[0156] myTEE APIs

[0157]

[0158] To demonstrate the feasibility of the peripheral isolation technology described above, we implemented an example of safely utilizing peripherals in a TEE. Specifically, we enabled TEE-exclusive use of a TPM using the SPI protocol, a USB keyboard with DMA and USB, and a framebuffer using a GPU.

[0159] --- Secure TPM

[0160] TPM is a hardware chip that performs operations such as hashing, key generation, and random generation.

[0161] Infenion provides the TPM hardware chip and associated software. The hardware plugs into GPIO pins and communicates using the SPI protocol. To facilitate application use of the TPM, a kernel driver is provided in the Linux mainstream. The software consists of the pDRV and cDRV components described above. The pDRV receives TPM requests from user applications, converts them into SPI messages, and then passes them to the cDRV. The cDRV then transmits these requests to the TPM chip via the SPI controller.

[0162] Afterwards, the TPM performs the requested operation and passes the result back to the cDRV through MMIO.

[0163] A myTEE-based Secure TPM can be activated as follows: The CA loads the TA. The TA generates a TPM command and passes it to the CA. Here, CA stands for Client Application, referring to the application that calls services to utilize the TPM. In other words, in a myTEE-based Secure TPM, the TA generates a TPM command and passes it to the CA to activate the TPM.

[0164] The CA transmits the received command and the secure TPM usage request flag to a write system call. The pDRV verifies the flag, locks the SPI controller, and logs it. It then initializes the TPM, sets the received command in the SPI structure, and passes it to the SPI cDRV. The cDRV verifies the secure TPM flag added to the SPI structure and performs a myTEEsupported memwrite. First, it escalates to the hypervisor using mytee_priv_up. Then, it copies the spi structure to the secure stack. The spi structure stores command length information in addition to the command, which must be verified before writing to prevent toctou attacks. After verifying the memory write based on the copied structure, the write is performed. The write loops based on the length information, writing 1 byte at a time. After the write is complete, the written command is logged. Kernel privileges are restored.

[0165] After waiting for a certain period of time, the result value of the TPM is read, and the response message is also performed in a similar manner through command transmission and privilege escalation. At this time, multiple read attempts may be required depending on the TPM operation status. Since the first byte of the success response message starts with 0x0, this is checked and a loop is run to read 1 byte at a time and store it in secure memory. In addition, a dummy value is inserted into the buffer originally used by the kernel to prevent it from being exposed. After the operation is completed, the CA notifies this, and the TA verifies the logged information and uses the TPM generation value.

[0166] --- Secure I / O

[0167] As mentioned previously, using TrustZone's TZASC and TZPC, I / O devices can be dynamically mapped to a single domain and used exclusively. To demonstrate that myTEE can effectively protect I / O peripherals without utilizing these hardware devices, we implemented data protection technology for keyboard input and monitor output connected via USB as examples.

[0168] ---- Trusted Keyboard

[0169] General USB peripheral. In our experimental environment, we used a USB keyboard as a Trusted Input device. This chapter describes the operation of a typical USB keyboard. Typically, a USB device can have multiple configurations. Each configuration defines several interfaces, and depending on the type of peripheral, it can have one or more interfaces. For example, a headset has interfaces for a microphone and audio. Each interface can have multiple endpoints depending on the supported transmission type. Endpoints are used for communication between the host and the peripheral. Each endpoint can be divided into IN and OUT. IN is used when data is transferred from the peripheral to the host, and OUT is used when data is transferred from the host to the peripheral.

[0170] In particular, endpoint0 is used for control mag transfers to retrieve the configuration of a peripheral device or to configure its hardware settings. For a USB keyboard, a command to turn on the LED is sent via OUT endpoint0.

[0171] In Linux, messages sent and received from the host to the peripheral are called USB request blocks (URBs). A URB is generated by the pDRV and contains all the information necessary for a transaction, such as the entry point, device address, and buffer address. The cDrv, which receives the URB from the pDrv, ​​initiates a transaction with the USB controller based on the URB information. Typically, a USB controller has multiple channels for communicating with devices. Each channel has an identical set of configuration registers, which are mapped to host memory. The cDrv selects an idle channel to be used for communication with the device and configures the device information for that channel using the dev address and entry point information extracted from the URB. Meanwhile, the host memory buffer within the URB stores data necessary for communication between the host and the device. For example, when the host changes the device's configuration, a control message is stored in the buffer and transmitted to the device via the controller.

[0172] Additionally, to transmit key input to the host, key information entered by the device is written to a buffer. If the USB controller has its own DMA engine, reading and writing values ​​to the buffer can be performed via DMA. To do this, set the address of the buffer to be used in the DMA address register of the previously selected channel.

[0173] After the DMA transfer is completed, an interrupt occurs and the irq_handler pre-registered in pDrv is executed.

[0174] irq_handler retransmits the URB based on the URB information updated by the current transaction, or performs any necessary actions if successful. For example, if a URB for reading keystrokes is processed successfully, the key input information is retrieved from the buffer within the URB, converted to device-specific format, and then written to a kernel structure that can be consumed by the user application.

[0175] Trusted keyboard.

[0176] Based on the analysis, we implemented a Trusted Keyboard. The following requirements must be considered for a Trusted Keyboard: (1) Users must be able to recognize that their current keyboard is properly protected. (2) Key input confidentiality must be guaranteed. To meet these requirements, the design was as follows:

[0177] Control message inspection. First, the NUM key LED is used as an indicator that the Trusted Keyboard is enabled. Therefore, the LED should only be turned on when requested by the TA. To use the Trusted Keyboard, the TA stores a flag requesting Trusted Keyboard use in the CA's secure memory area and transmits the request to the CA. The CA then requests that the NUM key LED, the Trusted Keyboard indicator, be turned on via a virtual keyboard command. This triggers the USB keyboard's pDrv, ​​which generates and transmits a URB containing a control message to the keyboard. As previously described, the control message is transmitted to the keyboard device's OUT entrypoint0 through the USB controller channel. As mentioned in Section (), all DMA packets must be monitored. To this end, the memory-mapped USB controller's DMA address register is protected by S2. Protection is achieved at the smallest unit, 4KB. Since all channel configuration registers are located within 4KB, all channel configuration registers are protected. Therefore, all of the channel settings of the USB controller described above can be monitored by generating an S2 fault. This is used to monitor additional channel settings in addition to DMA address monitoring so that the NUM LED operates only when normal. The main targets of monitoring are the device information settings of the channel and the buffer address settings. The devaddr is extracted by decoding the value written to the MMIO in the S2 fault that occurs when setting the device information, and this is compared with the previously stored devaddr to verify that the current channel setting is for the keyboard device. In addition, the channel number is determined based on the address where the fault occurred.Since each channel maps the same set of configuration registers to memory sequentially, the current channel number can be determined based on the offset between the fault address and the first configuration register of the first channel. Then, when a fault occurs when setting the buffer address for the subsequent DMA, it is determined that the buffer is set for the keyboard channel based on the previously determined channel number. If true, the value to be written to the address that caused the fault (the value of the buffer) is copied to the hypervisor area and then decoded to determine whether it is a control message for turning the LED ON.

[0178] If true, check if TA's trusted keyboard flag is set, emulate write, and turn on the LED. If false, drop the message. This satisfies (1).

[0179] Here, devaddr becomes a key attack vector. Because the current control message is determined based on devaddr to determine whether it is intended for a keyboard, if the actual devaddr of the keyboard changes, the indicator LED can be turned on to prompt the user to enter a secret value without activating the Trusted Keyboard mechanism. To address this issue, myTEE continuously tracks whether the devaddr has changed. To do this, in addition to the control message for turning on the LED, it monitors two standard control messages. All USB devices, when first attached to a port, have a default address of 0x0. The kernel retrieves device information by sending a GET_DESCRIPTOR control message to this address. myTEE decodes this message and checks the class and protocol values ​​to determine that it is a hidden keyboard device. The kernel then assigns a new address via a SET_ADDRESS control message. The kernel decodes this message and stores the newly assigned devaddr as the address of the protected keyboard. Afterwards, an attacker may attempt to change the device's address using the SET_ADDRESS control msg. To prevent this, the SET_ADDRESS type control msg is monitored at runtime.

[0180] Key input protection.

[0181] Ensuring confidentiality of keystrokes is also implemented based on MMIO monitoring. Similar to the previous control message protection, the currently assigned channel number is acquired by exploiting the S2 fault that occurs when setting the USB controller channel for keyboard input. Subsequently, when attempting MMIO to set the DMA buffer address, the S2 fault corresponding to the previously acquired channel is trapped, switching the buffer address to the secure buffer address. While the buffer is inaccessible to the kernel, the hardware performing DMA can access it, enabling the acquisition of keyboard input information.

[0182] The buffer where the key input information is stored is accessed by the handler that handles the interrupt upon DMA completion. This buffer is located in a protected area and therefore inaccessible to general kernel code. This can be solved using the method mentioned in the section. However, since the parts that access the buffer are scattered throughout the handler, it is not easy to wrap and protect them individually. Therefore, as a more coarse-grained method, a function was implemented that converts the input key location information stored in the buffer into a keycode and stores it in secure memory accessible from the TA. This function is then processed with elevated privileges using the mytee_priv_up API.

[0183] For reference, the current implementation is implemented to the extent of converting simple alphabet keys and numeric keys. In the actual kernel code, if the key is converted to a special key (e.g. sound), the corresponding input event is passed on to another device and processed separately. However, in the implementation of this embodiment, this is delegated to the normal kernel for processing. In addition, keys processed with elevated privileges are changed to dummy values ​​and processed by the existing kernel. Another limitation is that key input is not processed in real time.

[0184] That is, in the proof-of-concept code, after the CA completes input through a function like scanf, it calls the TA again to use the value written to protected memory. To ensure real-time processing, interrupts generated by key input must be passed to the TEE and processed by a handler embedded within the TEE. However, this complicates the design and requires more changes to the privileged software. Furthermore, it potentially increases the risk by loading additional drivers into the TEE.

[0185] Additionally, rather than using priv_up / down for most MMIO cases, we added trap handler logic to the DMA Filter implemented in hypervisor code. This is because USB uses DMA, making it impossible to log and verify events later. Since incorrect DMA usage is caused by code changes, logging itself cannot be guaranteed.

[0186] ---- Trusted Display

[0187] Trusted output is also important for displaying accurate information, along with trusted input. To achieve this, we designed a framebuffer protection technique using myTEE. On the Raspberry Pi, memory for the framebuffer is allocated by the video core GPU. This is accomplished by the kernel sending a request message to the video core. Interprocessor communication between the CPU and GPU is handled by the mailbox controller, which, like other methods, forwards requests to MMIO. For example, if a user application requests to change display settings via the framebuffer pDrv, ​​the request is formatted as a mailbox message and written to the mailbox controller's memory-mapped register via cDrv. To ensure trusted output, the fb or display settings must not be arbitrarily modified by an attacker while the display is being used by the TEE. Therefore, the mailbox controller is first locked. This lock sets the display settings to default values ​​and protects the MMIO portion of the mailbox controller using s2 paging.

[0188] Therefore, after locking, all messages destined for the video core are trapped and verified. The message type is decoded and all display-related requests are dropped. Non-display requests (clock rate) are allowed. Afterwards, the TA passes the request to the framebuffer pDRV through the proxy CA for framebuffer access. Generally, the application can write values ​​to the framebuffer using the mmap method and the write method, and we explain the implementation of Trusted Display in both methods.

[0189] -----MMAP-based access

[0190] User applications can directly read and write the framebuffer by mmaping the framebuffer physical area. To support this method, the myTEE API was inserted at the end of the framebuffer pDRV's mmap handler. The inserted code block verifies the start address and size of the physical area mapped by mmap if the mmap requested by the proxy CA is performed normally, and locks the framebuffer area based on this information and inserts the information into the protected area. Afterwards, the TA maps it to its own area based on the lock log for the preceding mailbox controller, the fb buffer area lock log, and the stored fb physical address, and directly manipulates the fb.

[0191] Note that during verification, the physical address of the fb buffer cannot be known in advance, so the method described in the section using context to verify whether it is a specific physical address cannot be used. Therefore, simply checking whether the physical address is a hyp or TEE address is sufficient for implementing a trusted display. Even if an attacker provides an address other than the actual fb address, the TA writes to a protected area, so secrets are not exposed. Furthermore, the area is not displayed, indicating that the user is in an abnormal state of protection. Furthermore, since the framebuffer itself checks the mapping location, length, etc., a compromised CA cannot perform a boomerang attack even if it modifies information passed from the TA (e.g., the offset to mmap or its size). Another method is to perform a controller mmio on the mailbox within the validation function to determine the current fb address. However, this requires integrating additional functions, such as timer settings and synchronization, in addition to writing the message to mmio.

[0192] -----Write system call

[0193] Another way to write values ​​to the frame buffer is to send data through a write request to pDrv, ​​which causes the driver to write values ​​to fb. If the TA simply passes the display data to the CA, there is a risk of content exposure and tampering. Therefore, the TA stores the display data in the hypervisor memory and requests the CA to use a trusted fb along with the size of the data to be written to the fb. The CA performs a write system call to the fb based on the received information. Here, the CA is a component that loads the Trusted Application (TA), processes the request sent from the TA, calls the hypervisor or operating system function, and performs security control. In other words, it acts as an intermediary between the TA and the hardware.

[0194] In pDrv, ​​as before, the controller and fb are first locked. Then, the display data written by the TA to the hyp area is read and written to fb. At this time, the log verification previously performed by the TA in the mmap method is also performed. Since these tasks require access to the hyp memory in the kernel, they are wrapped with priv_up.

[0195] Implementation

[0196] The myTEE PoC was implemented on the rpi3 b+ board, which features a quad-core ARM Cortex-A53 processor. OP-TEE was used as the TEE software, and Linux version 4.14 was used as the operating system. Details regarding the myTEE implementation are as follows.

[0197] - ARM trusted firmware

[0198] A function that generates S2 page table mappings for kernel areas at boot time has been added. In particular, the area storing the protected buffer of the USB keyboard is mapped to the DMA coherence area, enabling communication with the hardware without cache flushes. Furthermore, the monitor vector has been modified to add a function to change the S2 page table to service critical functions such as page tables and base registers in the kernel at runtime and to protect the controller's MMIO area as RO via the myTEE API.

[0199] - OS Kernel and drivers

[0200] To ensure that the kernel and hypervisor use the same page table format, the large page extension feature was enabled using the LPE option. At boot time, the memmap option was used to reserve a 16MB hardware region as the hypervisor region and create a virtual address mapping. After the kernel and its embedded hypervisor region are loaded into memory, code that calls a service to protect the S2 page was added to the init function. Furthermore, commands that perform page table and base register modifications were patched to the SMC, ensuring that the TEE verifies and then provides the service.

[0201] Also, the myTEE API for implementing the TPM example was mainly patched, including the TPM pDrv code (drivers / char / tpm / tpm_tis_spi.c, tpm-dev.c), the SPI controller driver (drivers / spi / spi-bcm2835.c), the framebuffer driver code (drivers / video / fbdev / core / fbmem.c), the mailbox controller driver (drivers / mailbox / bcm2835-mailbox.c), the USB keyboard pDrv (drivers / hid / hid-core.c, drivers / hid / usbhid / hid-core.c), and the usb controller driver (drivers / usb / host / dwc_otg / dwc_otg_cil.c). In addition, a flag to notify the use of a trusted peripheral was added to the structures spi (struct spi_tranfer), mailbox (struct mbox_chan), and usb (struct urb) of each protocol.

[0202] - Hypervisor

[0203] The hypervisor was implemented from the ground up. HTTBR uses the TTBR value used by the kernel at boot time. Since the logic servicing the myTEE API, which uses hypercalls, is processed by the hypervisor, the code for DMA packet filtering and command emulation was also implemented as vectors.

[0204] - OP-TEE

[0205] There are no changes at the OS level. Mapping is required to write and read data from the TA to the hypervisor area. This is done using the API provided by default in OP-TEE. Additionally, log verification functionality for each fb and TPM example was implemented as an API.

[0206] Evaluation

[0207] - Security Analysis

[0208] -- Race condition attack.

[0209] To prevent attacks that allow attackers to bypass the myTEE API inserted into the kernel or tamper with commands sent to peripherals, logging is performed in privileged code blocks. A potential attack scenario is a race condition between verification and use in scenarios where a TA, such as a TPM, checks logging.

[0210] For example, when attempting to use a value written to a protected buffer after logging verification, an attacker can use a priv block in another core to send a command to a peripheral device, attempting to tamper with a predictable value. To defend against this attack, the TA first copies the value in the buffer to its own area and then performs verification. Furthermore, logging is performed immediately before writing within the priv up / down block, preventing logging from occurring after copying and verification by the TA are complete. In the case of a write operation in the framebuffer, elevated kernel code reads a value from the protected buffer and writes it to fb. At this time, an attacker can attempt to tamper with the contents of fb using an elevated code block in another core. Here, fb represents the framebuffer and refers to the memory area related to screen output. This attack is impossible because the elevated code block always reads values ​​from the protected buffer, which only the TA (Trusted Application) can write to, and writes them to fb.

[0211] -- Abusing myTEE API

[0212] If an attacker arbitrarily uses an API that elevates the privileges of a portion of code to hypervisor privileges, they can take control of the entire system, including the TEE. Although the TEE region is not mapped, an attacker can create a new mapping on the TEE side by manipulating the values ​​of the hypervisor's page table base registers. To prevent such attacks, priv up code is limited to executing in statically compiled areas of the kernel. Furthermore, they may attempt to exploit APIs and memwrites already embedded in kernel drivers. To this end, memwrites verify the region and, in particular, pass the current controller information during verification. This ensures that a specific priv up API can only access the MMIO region of the controller of the driver in which the API is embedded. This ensures that a privileged write attempt by driver A cannot manipulate the MMIO region of driver B.

[0213] -- Code vulnerability.

[0214] The code within the priv up / down blocks is a very simple function, such as memcpy or writel, and is therefore easily verifiable. In the case of fb, the keycode conversion code is placed within the block. However, this is also small enough to be verifiable. Even if the code within the block is exploited and the control flow is altered, the attacker cannot attack the TEE because there are no instructions in the kernel and hypervisor to update the page table base register. One possible attack option is an lkm attack. If the corresponding inst is inserted into a dynamically loaded kernel driver and the corresponding location is jumped to, a mapping to the TEE can be created, enabling an attack. This attack is possible by adding additional security elements when entering priv up. For example, the mapping to the lkm area can be removed during priv_up and remapped during down.

[0215] The use of TEEs in embedded devices is limited due to the lack of hardware capabilities or restricted access. To address these issues, we designed myTEE, which leverages the benefits of TEEs even in devices with limited TEE hardware access. myTEE enables TEE isolation and secure peripheral access without the need for TrustZone's extended hardware features, such as memory protection or Secure IO channels. Furthermore, secure peripheral access is made possible by embedding the myTEE API within device drivers, making it easily accessible to existing device driver developers. Feasibility was demonstrated by implementing three TEE applications (Secure TPM and Trusted keyboard and display) using myTEE.

[0216] Hereinafter, a system for implementing a software-based trusted execution environment of an embedded device according to one embodiment of the present invention will be described in detail.

[0217] Figure 5 illustrates the physical memory layout and memory permission settings for protecting TEE and MyTEE components. The system for implementing a software-based trusted execution environment for an embedded device according to this embodiment first sets up a physical memory layout to protect the TEE and MyTEE components. This is necessary to isolate the memory space used by the TEE and MyTEE from other system areas. Furthermore, by setting the memory space to specific permissions, it prevents external malware from invading the memory.

[0218] TEE and MyTEE operate in a separate space from the Regular Execution Environment (REE), such as the Linux OS. To achieve this, the memory layout must separate the memory space used by TEE and MyTEE from the REE. Furthermore, setting permissions for this memory space is essential to protect TEE and MyTEE.

[0219] Typically, register settings are used to protect memory. For example, the ARM architecture uses the Memory Management Unit (MMU) to manage page tables and set access permissions for each page. TEE and MyTEE implement memory protection by modifying register values ​​using MMU settings. Furthermore, TEE and MyTEE manage page tables and set necessary permissions. Physical memory layout and memory permission settings are critical factors in ensuring the security of TEE and MyTEE components.

[0220] Regarding execution environment isolation, MyTEE consists of a TEE and an REE component. The REE component comprises a small hypervisor embedded in the device driver and the MyTEE API. The TEE component, an active integrity monitor, runs in monitor mode and emulates critical kernel and hypervisor operations. Both components are protected by careful management of the kernel page table and stage-2 page table.

[0221] First, by removing the mapping between the TEE and the hypervisor from the stage-2 page table, MyTEE ensures that an untrusted OS cannot access either area. Furthermore, embedded kernel text, including MyTEE API calls, and hypervisor text are enforced as read-only. Stage-2 page tables are created as part of secure boot.

[0222] To elevate privileges for device drivers (VDs in Figure 1), the hypervisor uses kernel page tables to map virtual address spaces instead of maintaining its own page tables. This approach allows privileged code blocks to execute seamlessly with hypervisor privileges. This means that kernel APIs and dynamically allocated kernel objects can be accessed from the hypervisor using kernel virtual addresses without being mapped to a separate hypervisor page table. To achieve this, the kernel page table maps the entire REE (including the hypervisor) excluding the Trusted Execution Environment (TEE). However, untrusted OSes cannot access the hypervisor space due to Stage 2 page-based isolation. Furthermore, an active integrity monitor restricts the privileges of the kernel and hypervisor to prevent untrusted OSes or compromised hypervisors from manipulating the page table. The (shared) kernel page table is set to read-only, and the integrity monitor verifies and emulates page table updates. This ensures that new page table entries are not mapped to physical memory already allocated to protected components and invariants (e.g., the TEE, hypervisor, or kernel text).

[0223] Additionally, security-critical operations, such as managing system registers, are simulated. Instructions for these critical operations are replaced with Secure Monitor Calls (SMCs). The stage-2 page table is located in the TEE area, not mapped to the untrusted operating system, protecting it even if a hacker gains hypervisor privileges. Furthermore, security-critical instructions that manage the hypervisor system registers are ensured not to be included in the hypervisor. For example, the instructions that configure the hypervisor's VTTBR and System Control Register (SCTLR) are initialized and then removed from memory at boot time. VTTBR is a register that points to the starting address of the virtualized page table used to translate virtual addresses into physical addresses. SCTLR is a register that controls the entire system in the ARM architecture. This register controls functions such as cache, virtual memory, and interrupt management. In MyTEE, the instructions that configure VTTBR and SCTLR are initialized and then removed from memory at boot time. This prevents malicious attackers from exploiting these registers.

[0224] Finally, a watchpoint-based memory protection technique was adopted to monitor privileged malicious access to DMA controller registers. Figure 5 illustrates the memory layout with MyTEE.

[0225] Regarding the DMA filter, due to the lack of TZASC, MyTEE relies on careful page table management and privilege restrictions to protect its own and the TEE's memory. This means that a compromised peripheral device can be vulnerable to DMA attacks, which allow it to read and write any memory region arbitrarily. DMA attacks can be triggered by two different entities: malicious hardware or an untrusted operating system. This example assumes that the host device is physically isolated and that the peripherals on the device are not malicious. Therefore, DMA attacks by malicious hardware are not considered in our work. On the other hand, an untrusted operating system could maliciously program the DMA controller to compromise MyTEE's security. To prevent this, MyTEE filters out malicious DMA requests that could cause abnormal behavior. Because there are two types of DMA controllers—an internal DMA controller and an external DMA controller—slightly different monitoring strategies must be applied.

[0226] External DMA Controller. MyTEE monitors all DMA Control Blocks (CBs) to protect external DMA controllers. A CB is a data structure that specifies essential information required for data transfer, such as source and destination addresses, data size, and transfer type.

[0227] Figure 6 illustrates MyTEE's verification of DMA control blocks to prevent malicious DMA from being triggered in untrusted operating systems. As shown in Figure 6, since the CB address is passed through MMIO by the DMA controller, MyTEE traps and validates all accesses to the DMA controller's memory-mapped registers. In other words, it utilizes two-stage paging to lock the registers. Access to locked registers causes a page fault, which is trapped by the MyTEE hypervisor. MyTEE first dereferences the CB address and copies the CB to secure memory. Since multiple CBs can be linked by setting NEXT_CB, dereferencing and copying the CB value continues until the NEXT_CB value becomes 0x0. The copied CB is then verified, preventing DMA access to the protected area. DMA data transfers are performed differently depending on the TD_MODE flag setting in TXFR_INFO.

[0228] Figure 7 illustrates how MyTEE checks the CB settings in DMA 2-dimensional (TD) mode to ensure that the DMA does not access the protected area in each data transfer iteration.

[0229] As described in Figure 7, when this flag is set, the transfer between the source and destination memory buffers is performed in two-dimensional (TD) mode. The source data, whose size is specified by XLENGTH, is transferred to the destination memory. In addition, the transfer is performed YLENGTH times. D_STRIDE and S_STRIDE are signed integers and are added to SRC_ADDR and DST_ADDR to determine the source and destination addresses of the next transfer. The SRC_WIDTH, SRC_INC, DST_WIDTH, and DST_INC flags of TXFR_INFO also configure the address of the next transfer. In particular, when the SRC_INC or DST_INC flag is set, each memory read or write from the source or destination increases the source and destination addresses by 4 or 32, depending on the settings of SRC_WIDTH and DST_WIDTH. In contrast, the normal (non-TD) mode operates in a simpler manner. TXFR_LEN specifies the total amount of data to transfer. STRIDE is ignored in this mode.

[0230] By observing how CBs program the DMA controller, MyTEE pre-checks expected DMA accesses to filter out malicious CBs. Any CB that programs the controller to perform DMA to immutable regions (i.e., kernel text, hypervisor, TEE) is considered malicious and blocked. Here, CB stands for "Control Block," a data structure used for direct memory access (DMA) control. The CB is used to configure the data required for a DMA transfer into control registers. The CB is stored in a fixed location in memory, and the DMA controller reads the CB to perform the data transfer. The CB contains information about the DMA transfer, such as the DMA transfer size, source and destination addresses, and transfer mode.

[0231] Finally, the address of the copied CB is written to the DMA controller register instead of the original CB, eliminating the race condition between verification and use. Once the address is written to the controller register, each CB field is copied to a read-only register in the controller (COPY_OF_CB in Figure 6). Furthermore, DMA only allows access to secure buffers when both the source and destination buffers are hosted in secure memory. This prevents the buffer's confidential information from being leaked or manipulated by malicious DMA.

[0232] Built-in DMA controller. DMA controllers can be integrated into other devices. On the Raspberry Pi 3, the USB controller includes its own DMA controller. Compared to external DMA controllers, this type of built-in DMA controller has a simpler configuration mechanism. Instead of first searching memory and then being absorbed by the DMA controller, the operating system can directly update memory-mapped controller registers that configure the size and address of the data transfer memory. Furthermore, this DMA controller eliminates memory-to-memory operations. Either the source or destination is set to a FIFO in a peripheral connected to a USB hub. For example, a DMA operation to retrieve USB keyboard input would read the input from the FIFO and write it to a buffer in host memory. This feature of the built-in DMA controller simplifies DMA filtering. Controller registers are locked by stage-2 paging to monitor update attempts. However, there is no need to copy the CB from secure memory. In particular, updates to the registers that configure the buffer address and size are checked to prevent DMA access to kernel text and data, the hypervisor, the Trusted Execution Environment (TEE), and the locked registers themselves. Additionally, DMA accesses to safe buffers are dropped unless they are performed as part of a safe IO transaction.

[0233] Regarding peripheral isolation, configuring TrustZone-based secure IO can be difficult without TZPC and TZASC. Here, we describe how MyTEE establishes secure IO channels between TAs and peripherals without relying on these TrustZone extensions.

[0234] 1) Design Primitives for Secure IO: Previously, secure IO between the TEE and peripherals was enabled by configuring the TZPC to securely set the security state of the peripheral, allowing access to TZASC-protected memory. Furthermore, peripheral drivers were hosted in the TEE. However, this approach is not applicable to restricted environments that do not provide these hardware protections. Furthermore, moving the device driver to the TEE increases the attack surface of the TEE. MyTEE overcomes these limitations and satisfies the following requirements: R1) TEE bloat must not occur; R2) it must be easy to use and deploy; R3) IO must be verifiable; and R4) it must not be subject to misuse.

[0235] 2) Temporal privilege escalation: To meet R1, device drivers are re-examined instead of being hosted in the TEE. The CA acts as a proxy, forwarding requests from the TA. As previously explained, pDrv, ​​cDrv, and the controller participate in communication with peripherals. To enable secure I / O with peripherals, some of these are protected: the controller's memory-mapped registers and the buffers used to forward I / O requests and responses. Requirements for preserving the confidentiality or integrity of secure buffers vary depending on the type of peripheral and scenario. For example, medical data in a frame buffer must be both confidential and intact. On the other hand, TPM commands in the buffer are not secret but must be fully communicated to the TPM. Here, TPM stands for Trusted Platform Module, a chip or module designed to enhance the security of computer hardware or software. The TPM provides various security functions, such as generating and storing cryptographic keys, managing digital certificates, and verifying the system boot process. TPM commands are commands sent to the TPM to perform these functions, for example, a command that "instructs the TPM to perform trust verification."

[0236] Figure 8 shows that the combination of temporary privilege escalation in the device driver partition and shared and stage-2 page tables enables safe IO without bloating the TEE.

[0237] Figure 8 illustrates how secure IO is implemented in MyTEE. Memory-mapped registers are made inaccessible to the OS by managing stage-2 paging. Predefined IO buffers in secure (hypervisor) memory, rather than kernel-allocated buffers, are used upon request. Therefore, even device drivers participating in secure IO cannot read or write to these protected objects. Therefore, we temporarily elevate the privileges of the code blocks managing secure buffers and registers to prevent driver operations from being blocked. Page tables are shared to map the kernel and hypervisor. However, actual kernel space permissions are determined by a combination of kernel and stage-2 page table settings, so sharing page tables does not compromise hypervisor security. In other words, we can still apply different memory permissions between the kernel and hypervisor, and protected objects are only accessible when escalating to the hypervisor.

[0238] [Table 2]

[0239]

[0240] Privilege escalation wraps a selected block of code (Table 2) using the MyTEE APIs, mytee_priv_up and mytee_priv_down. These APIs are implemented as hypercalls. When mytee_priv_up is called, the current CPU mode switches to the hypervisor, a new stack is allocated in secure memory, and interrupts are disabled. While the hypervisor is trusted, the elevated code chunks are vulnerable and could allow an attacker to gain arbitrary read / write privileges with hypervisor privileges. This could compromise the DMA controller, potentially breaking page-based TEE isolation. To prevent such attacks, we employ debug watchpoint-based memory protection. The watchpoint is configured to monitor the MMIO region of the DMA controller for each privilege escalation. Therefore, any write access to the controller generates a watchpoint exception, which is handled by the trusted hypervisor. Finally, control flow passes to the instruction following the hypercall invocation, without any privilege transition to the kernel. Therefore, the code block following mytee_priv_up executes with hypervisor privileges and can access secure buffers and registers. mytee_priv_down is placed at the end of the code block and reverts the settings made in mytee_priv_up. To prevent attackers from exploiting these APIs, only drivers built statically into the kernel text are allowed to use them. This is distinguished from loadable kernel modules (LKMs) by checking the link register (LR), which is automatically updated when the function is called.

[0241] The use of the MyTEE API facilitates the establishment of secure IO channels with external devices (satisfying R2), which helps minimize the need to modify privileged software (i.e., the hypervisor) to expose the logic and data structures of a specific device. For example, all commands sent to the Trusted Platform Module (TPM) hardware must be logged for later verification by the Trusted Application (TA). This logging is necessary to understand protocols such as TPM command and SPI message formats, as well as the semantics of the TPM.

[0242] Here, SPI (Serial Peripheral Interface) is a communication protocol for serial communication between hardware devices. This protocol consists of four signal lines for data transmission and is primarily used for communication between microcontrollers and peripheral devices. SPI uses a synchronous communication method, and is configured so that when one device transmits data, the other device can receive it. SPI is a common communication protocol supported by most microcontrollers and peripheral devices.

[0243] The MyTEE API allows developers to manage data and logic for these specific devices in their own device drivers, instead of adapting the MyTEE hypervisor.

[0244] 3) Robustness and Security: Because MyTEE API calls are exposed in the device driver, they can be abused or bypassed by potential attackers. An attacker can simply manipulate the control flow to ensure that the MMIO region is not protected. Furthermore, privileged code blocks can be exploited to send malicious requests to the device. To mitigate this, it is recommended to log operations performed in privileged code blocks and have the TA verify these operations (R3). The mytee_log_txn API supports logging and is called from privileged code blocks to log events to secure memory. The operation type (e.g., MMIO register protection, command writing), the message sent to the device, and the controller's configuration values ​​are logged. Verification can be performed as follows: (1) ensuring that the buffer and MMIO regions are protected during the transaction and (2) ensuring that the request sent to the device is not corrupted. While malicious and multiple accesses to MMIO are possible, logging performed in privileged code blocks cannot be bypassed as long as the API is implemented correctly. If an unexpected log is detected (e.g. a TPM command change), the TA can either abort the transaction or continue and repeat it until it is completed normally.

[0245] Figure 9 shows Listing 1: the original function with writel and Listing 2: the function with the MyTEE API added.

[0246] writel is a function used to control hardware registers in the Linux kernel. The writel function uses memory-mapped input / output (I / O) to write a specified value to a register. In other words, it is used to change the value of the corresponding register. This function is used in hardware drivers and is used to read and write data from hardware. For example, writel(0x1234, 0x400) will write the value 0x1234 to the register located at address 0x400. This can be used to control hardware operation or change settings.

[0247] Memory operations (e.g., writel) within privileged blocks must not be exploited (R4). To this end, MyTEE supports the mytee_verify_memopr API. Because address and size verification are performed, the addresses of secure objects are deterministic. For example, the MMIO region of a peripheral is defined and fixed by the SoC manufacturer. Verification is simply performed by ensuring that the memory operation is performed within a valid memory range. Relevant parameters (e.g., source and destination addresses) and their referenced values ​​are marshaled to the secure stack before verification, preventing timing attacks.

[0248] Additionally, the privilege escalation driver block may be vulnerable. However, even if an attacker exploits the vulnerability to gain privileged "write-what-where" functionality, the read-only region remains immutable. This is because the TEE (i.e., the active integrity monitor) is the sole anchor for updating page tables. While writable objects such as logs can be compromised, the attack's effect is limited to the REE. Therefore, since the device driver is hosted outside the TEE, the attack does not directly compromise the TEE.

[0249] Finally, like typical TEE services, MyTEE-protected services are vulnerable to denial-of-service (DoS) attacks. However, MyTEE provides a way to establish a secure IO activation indicator to prevent unprotected IO from being disguised as secure IO. Furthermore, when IO devices are accessed simultaneously from REEs and TEEs, TEE access is always treated with higher priority. This approach is consistent with typical TEE-based secure IO, which suspends REEs while TEEs are performing IO.

[0250] 4) Instrumentation example: Listing 2 shows an example instrumentation of a device driver using MyTEE. On a Raspberry Pi, the operating system can communicate with the GPU using the Mailbox protocol. The bcm2835_send_data function writes a message to the Mailbox controller via MMIO and transmits it to the GPU. In this example, we assume that the MMIO region is already protected and want to log all messages written to this region. As shown in Listing 2, we first wrap the original writel function in the mytee_wrapper_writel function for validation and logging using additional MyTEE APIs.

[0251] MAILBOX_WRT, one of the API's input parameters, is a constant representing the current context. This value is used in the validation function to retrieve a valid address range with the Mailbox controller. Developers can add more granular filtering logic to capture only specific types of request messages passed to Mailbox, such as display configurations.

[0252] mytee_wrapper_writel is rewrapped with mytee_priv_up and mytee_priv_down , allowing it to operate with hypervisor privileges and access protected MMIO regions. In this example, the parameter is 4 bytes in size, so it is not marshaled for mytee_wrapper_writel . Therefore, it is passed using regular registers. However, to pass a variable whose address is taken as an argument, it must be marshaled on the secure stack.

[0253] In computer science, marshaling refers to the process of converting data into a different format. For example, it refers to reading data from computer memory and converting it into a different format, or converting data to a specific format when transferring it between different systems or processes. It is primarily used in programming languages ​​and databases, and converting data into a different format allows for control over data size and type.

[0254] Figure 10 illustrates the communication process of security IO.

[0255] Regarding Secure IO Applications, this section describes three examples demonstrating how MyTEE can enhance the communication channel between a TEE and peripherals such as a hardware TPM, a USB keyboard, and a frame buffer. While the implementation (specifically, how the driver is instrumented with the MyTEE API) may vary depending on the peripheral, secure IO supported by MyTEE can be described as shown in Figure 10.

[0256] A. Secure TPM

[0257] For the TPM security PoC, we used Infineon's SLB 9670 TPM. PoC stands for "Proof of Concept," which is a term used primarily in computer technology to refer to experiments to verify the practical operation of a new idea or technology. A PoC typically involves creating a prototype or sample software and applying it to demonstrate the effectiveness of the idea or technology. This is a hardware implementation of TPM 2.0, connected to the GPIO pins of a Raspberry Pi 3. Communication between the OS and the TPM is performed using the SPI protocol. The device drivers for the TPM (pDrv) and the SPI controller (cDrv) are integrated into the Linux mainstream. All requests from user applications bound to the TPM are first passed to pDrv, ​​where they are formatted as SPI messages. The messages are then written to the TPM via MMIO via the controller. The TPM's response is also read via MMIO via the controller. Both MMIO operations are performed by cDrv.

[0258] Secure IO to the TPM is structured and operates as follows: The TA generates a TPM command and passes it to the proxy CA. The CA passes the command, including the flag, to pDrv, ​​which then transmits the command along with the requested secure IO. The MMIO region for the SPI controller is protected by mytee_shield_mmio in pDrv, ​​and this protection is also recorded in secure (hypervisor) memory. After pDrv issues the init command, an SPI message containing the flag and command passed from the CA is sent to cDrv. cDrv checks the flag and performs the elevated MMIO. To achieve this, the bcm2835_wr function is instrumented in a manner similar to that described in Listing 2. The function is wrapped in a new wrapper function, and the mytee_priv_up and mytee_priv_down APIs are called before and after the wrapper function. Additional APIs for parameter marshalling, memory write verification, and command logging are placed in the wrapped function.

[0259] Specifically, the command and its length field are marshalled from the SPI message. The bcm2835_wr function writes the command to the slave (TPM)'s FIFO. One byte is written in each iteration of a loop following the SPI transfer protocol. Once all commands have been delivered to the TPM, authority is returned to the kernel.

[0260] Reading a response from the TPM requires privileged read access to the protected MMIO region. Therefore, the bcm2835_rd function is instrumented in a similar manner. Read operations are also performed with single-byte precision. In the TPM, each byte is written to a buffer in secure memory instead of the SPI message buffer. The TA later checks the log to verify that the TPM request was processed in a trustworthy manner and then consumes the output from the secure buffer. The header of the TPM response message contains a status flag for the transaction, and a successful response message delivers output (e.g., a random number) depending on the command type. Therefore, only successful responses are filtered and written to the secure buffer. Additionally, a transaction flag indicating the completion of a single transaction is maintained to prevent further (malicious) requests before the TA consumes the output. This flag is checked as part of the MMIO validation of the TPM command write, and the TA clears the flag after consuming the TPM output.

[0261] B. Trusted USB Keyboard

[0262] In this section, we first detail the communication mechanism between a host and a generic USB device, and then provide an example of securing communication with a USB keyboard to demonstrate how MyTEE establishes secure IO with a USB device.

[0263] 1) General USB peripherals: A USB device can have multiple configurations. Each configuration can also define multiple interfaces. For example, a USB headset has interfaces for a microphone and audio. Each individual interface has at least one endpoint, which is a hardware buffer for communication between the host and the peripheral. There are two types of endpoints: control endpoints and data endpoints. The control endpoint is used to configure and control the USB device (e.g., controlling the LEDs on a keyboard), and endpoint0 is dedicated for this purpose. The data endpoint is optional and is defined for data transfer. The direction of the endpoint is defined by the host. For example, the IN endpoint is used to transfer data from the peripheral to the host, while the OUT endpoint transfers data from the host to the device.

[0264] In Linux, a data structure called the USB Request Block (URB) is defined for data transfers with USB peripherals. The URB is generated from the pDrv and contains all the information required for the transaction, such as the endpoint, device address, and buffer address. When the cDrv of the USB controller receives the URB from the pDrv, ​​it configures the USB controller based on the information in the URB to initiate the transaction. Typically, a USB controller supports multiple channels for communication with peripherals, each with an identical set of configuration registers mapped to host memory. During the bootstrapping process for a transaction, the cDrv selects an idle channel and configures it based on the information in the URB, such as the device address and endpoint. The buffer address in the URB can also be configured in the controller to enable direct memory access (DMA) between the host and the peripheral.

[0265] DMA completion triggers an interrupt, which is handled by a kernel thread that calls the interrupt handler registered by pDrv. Interrupt handling is performed based on the updated information in the URB. The handler first checks a status flag indicating whether the transfer triggered by the previous URB was successful. If the status flag is set to failure, the URB is retransmitted. The handler executes a peripheral-specific service routine to process the URB with the success flag. For example, the URB fetches a scan code from the buffer, and the handler translates the scan code into a key code based on the key map. Additionally, keyboard input is written to a file (e.g., / dev / input / eventX) so that applications can consume the event.

[0266] 2) Trusted Keyboard: We designed a trusted keyboard based on MyTEE by analyzing USB device drivers in Linux. The trusted keyboard was designed with the following security requirements in mind: (1) Users must be able to recognize whether secure IO is currently established with the keyboard. (2) The confidentiality and integrity of communications must be guaranteed.

[0267] Control message inspection. We used the LED for the NUM Lock key as an indicator of secure IO activation. Therefore, the LED should only be turned on when the TA initializes and requests a trusted keyboard. The TA first sets the trusted keyboard flag in the hypervisor memory and requests the proxy CA to turn on the LED. Then, the CA simply turns on the NUM Lock LED using the xset utility. The xset utility is a command-line tool used to change the properties of the X server used in the X Window System. xset allows you to change server settings such as screen brightness, enabling or disabling the screensaver, and so on. In MyTEE, the xset utility was used to turn on the LED.

[0268] This triggers the USB keyboard's pDrv. A URB control message is generated from pDrv and transmitted to the USB controller's cDrv. Furthermore, all DMA packets are monitored. This locks the entire controller registers, not just the DMA address register, because the granularity of stage-2 pages is greater than 4 KB. Therefore, we can effectively block any attempt to configure the controller for a URB transfer. URB stands for USB Request Block, a data structure used to exchange data with USB peripherals. A URB transfer refers to exchanging data with a USB peripheral through this structure. The URB contains all the information necessary for the transaction, such as the address, endpoint, and buffer address, and the USB controller uses this information to configure and transmit the transaction. There are two types of URB transfers: a data endpoint that transmits data and a control endpoint that controls the USB peripheral. The IN endpoint transfers data from the peripheral to the host, while the OUT endpoint transfers data from the host to the peripheral. URB transfers are the core mechanism by which the USB controller exchanges data with peripherals.

[0269] Due to these characteristics, we additionally implemented a trap handler in the hypervisor to monitor channel configuration and DMA packets, thereby enabling access control to the LED. All attempts to write device (peripheral) addresses and buffer addresses to controller registers for channel configuration are monitored. First, the device address can be retrieved from the value written to the channel attribute register (hcchar). This can be used to filter URBs for other peripherals. Furthermore, the current channel number can be retrieved based on the trapped stage-2 page fault address. Specifically, since each channel has the same memory layout of configuration registers located in contiguous memory, the current channel number can be retrieved based on the offset between the first channel address and the fault address. Setting the buffer address used by the DMA controller also triggers a stage-2 page fault. The current channel number can be retrieved based on the fault address. If the current channel is assigned to the keyboard, we can copy and decode the contents of the buffer in secure (hypervisor) memory. MyTEE only turns on the LED when the trusted keyboard flag is set and LED control messages are found in the decoded content.

[0270] This section describes how data input from a USB keyboard is protected. It uses Memory Mapped Input / Output (MMIO) to monitor access to controller registers and, as previously described, retrieves the device address and channel number. Because it uses DMA to retrieve scan codes, it handles stage-2 page faults that occur when setting the buffer address for DMA configuration differently. The buffer is updated with the scan code retrieved by DMA. The integrity and confidentiality of the scan code must be protected. To achieve this, MyTEE protects the buffer by replacing it with a secure buffer during MMIO processing. This prevents untrusted operating systems from accessing the buffer, but still allows the hardware (the DMA controller) to access the secure buffer and retrieve the scan code.

[0271] During DMA completion interrupt processing, access to a secure buffer is required to execute peripheral-specific logic, such as converting scan codes. Therefore, privilege elevation is required to read data from protected memory. An approach to elevating the privileges of the driver code block shown in Listing 2 can be adopted. That is, the code block accessing the secure buffer can be wrapped with the mytee_priv_up and mytee_priv_down APIs. To simplify the implementation, we developed a new function that integrates the essential and minimal tasks of converting and protecting scan codes. Instead of wrapping this function in a distributed code block that accesses the secure buffer in the kernel, we wrap the entire function using the MyTEE API. The function converts the key code and writes the key code to secure memory for future use by the TA.

[0272] Note that device drivers can perform additional tasks beyond key code translation. For example, if a keyboard supports volume control keys, the driver can notify other (e.g., speaker) device drivers of key press events. In our example implementation, we leave this task to the non-elevated portion of the driver. Furthermore, key events are not processed directly in the TEE. Instead, they are handled by the operating system and device drivers instrumented with MyTEE. Specifically, each key event is processed in the REE until the CA completes collecting user input. The key codes stored in protected memory are then processed in the TA. Our approach has a clear advantage over directly handling interrupts in the TEE. Passing and handling interrupts to the TEE complicates the system design and makes the TEE unnecessarily large, as additional changes to the operating system and TEE are required.

[0273] Device address tracking. For example, device addresses must be kept up to date for reliable peripheral identification. To achieve this, two standard control messages are monitored: GET_DESCRIPTOR and SET_ADDRESS. USB devices have a default device address of 0x0 when first connected to a USB port. The operating system sends a GET_DESCRIPTOR URB to retrieve information such as the device's USB class and protocol. MyTEE hooks this URB to detect keyboard connections. It then monitors URBs such as SET_ADDRESS to assign a new address to the device.

[0274] C. Trusted Display

[0275] This section demonstrates how MyTEE protects the frame buffer for reliable display. On the Raspberry Pi, the video core (i.e., the GPU) manages display configuration, such as frame buffer allocation and display resolution settings. The OS can send display configuration requests to the video core. Interprocess communication between the CPU and the video core is performed through the mailbox controller. Requests and responses are exchanged by performing MMIO operations on mailbox controller registers.

[0276] For secure I / O, we first ensure that the display configuration is not maliciously modified. To achieve this, we lock the mailbox controller's memory-mapped registers using stage-2 paging. mytee_shield_mmio is called from the ioctl handler for the display configuration (i.e., FBIOPUT_VSCREENINFO) in pDrv. Furthermore, the mailbox controller's cDrv is also patched in a similar manner as shown in Listing 2 to enable access to protected registers under MyTEE surveillance. To prevent TOCTTOU attacks, after locking the mailbox controller registers, display configuration is restricted to only one operation. The validity of the configuration is verified before updating the frame buffer for the TA's original request. Typically, there are two interfaces for manipulating the frame buffer: write and mmap. MyTEE supports both mechanisms to achieve the following trusted output:

[0277] mmap-based access. pDrv typically provides an mmap mechanism to allow user applications to directly access the frame buffer. To implement secure IO, a privileged block containing MyTEE APIs is placed at the end of pDrv's mmap handler. When the proxy CA maps a frame buffer to handle an mmap request from the TA, the patched mmap handler is triggered. The physical address of the frame buffer is obtained during the normal mmap process. The privileged block then verifies the address and size of the mmap to ensure that no MyTEE-protected region is maliciously mapped to the TA (e.g., a Boomerang attack). Furthermore, valid regions are protected, and their (physical) addresses and sizes are written to secure memory. The TA then checks the controller and frame buffer-related logs and, based on the information in secure memory, requests the TEE OS to directly map the frame buffer into its address space.

[0278] The write system call. pDrv's write handler supports writing data directly to the frame buffer. To use this for secure IO, the system must ensure that the written data is not leaked or tampered with. To achieve this, the TA first places the secret data in secure memory and requests the CA to call the write system call with dummy data. Similar to the mmap-based approach, pDrv's write handler is modified to include a private code block to protect the frame buffer and verify memory operations. The secret data is then copied from secure memory to the protected frame buffer. Since updating the frame buffer is delegated to a modified device driver (unlike mmap support), log verification is performed in the private block. Furthermore, both approaches can implement an indicator indicating the successful establishment of a secure IO channel.

[0279] [Table 3]

[0280]

[0281] Regarding implementation, the MyTEE PoC was implemented on a Raspberry Pi 3 development board equipped with the Broadcom BCM2837 SoC. This SoC features an ARM Cortex-A53 quad-core processor, a DesignWare USB 2.0 controller, a 16-channel DMA controller, and an SPI controller. Only the CPU's secure state is supported, and TrustZone extensions such as TZPC, TZASC, and TZMA are not supported. OP-TEE and Linux (version 4.14) were deployed as the TEE and REE software platforms, respectively. Table 3 shows the sizes of the trusted components and device driver patches (and TA) for secure IO. Note that 673 LoC were added to the kernel and 821 LoC (ASM) were added to the monitor for TZ-RKP adoption. TZ-RKP stands for TrustZone Root Key Provisioning. To implement a secure boot process using TrustZone, we generate the TrustZone Root Key required and use it to build a Trusted Execution Environment (TEE), which is an area safely protected from attacks.

[0282] A. ARM Trusted Firmware

[0283] We updated the ARM trusted firmware to create a Phase-2 page table that isolates the TEE and hypervisor from the untrusted OS. Specifically, the memory areas of security-critical objects (e.g., the hypervisor stack, secure buffers), and the table itself are not mapped in the Phase-2 translation layer. To protect the controller's MMIO area as needed, runtime management of the Phase-2 page table is performed in monitor mode (i.e., in BL31 of the ARM trusted firmware). Furthermore, emulation of critical kernel operations, such as updating page tables and system registers, is also performed in monitor mode.

[0284] B. OS Kernel and Drivers

[0285] Kernel page tables are shared with the hypervisor. Therefore, the page table formats and virtual address ranges supported by the kernel and the hypervisor must be the same. When 64-bit virtual addresses are used, the virtual address range supported in hypervisor mode is smaller than in 32-bit address mode. In this mode, there are two types of page table descriptor formats: short descriptors and long descriptors. However, hypervisor mode only supports the long descriptor format. Therefore, the kernel was compiled as a 32-bit binary using the large physical address extension option (i.e., CONFIG_ARM_LPAE in the .config file) to use the long descriptor format.

[0286] After the kernel text, data, and hypervisor are loaded into memory, they are protected by stage-2 paging. A crafted init process generates a protection request to invoke MyTEE. Critical operations, such as page table updates, are patched by the SMC and verified and emulated by MyTEE. To find out where these critical operations are located in the kernel source, refer to the Samsung Open Source Project

[0013] , which provides kernel patches for the TZ-RKP implementation.

[0287] [Table 4]

[0288]

[0289] Table 4 lists important system registers that are dynamically reconfigured by the kernel at runtime, resulting in each configuration operation being emulated rather than eliminated. For example, TTBR0 is set on context switches, and SCTLR is configured to enable a memory alignment trap on kernel entry from user mode.

[0290] C. Hypervisor

[0291] The small hypervisor was implemented from the ground up using ASM. For page table sharing, we configured the Translation Table Base Register (HTTBR) with the same value as the Translation Table Base Register (TTBR1), which contains the kernel page table address. This configuration is performed at boot time, and the command that sets HTTBR is invalidated to prevent attackers from exploiting it. The hypercall handler is implemented to support MyTEE APIs, such as mytee_priv_up. When a hypercall is invoked, the kernel context is saved in the Saved Program State Register (SPSR). Normally, this saved context is restored when returning to the kernel using the eret instruction. However, instead, we use the ret instruction to return to the kernel without deprivileging the selected (wrapped) device driver block running with hypervisor privileges. Watchpoint-based DMA register protection is not implemented in the 32-bit hypervisor because watchpoint configuration for the 32-bit hypervisor is not supported on the ARM architecture.

[0292] D. OP-TEE

[0293] Implementing TA requires some OS-level services. For example, a page table mapping to the hypervisor-space's secure memory must be created to allow TA access to secure buffers. For this purpose, the OP-TEE API was used instead of being added. Meanwhile, specific peripheral logic required to implement secure IO, such as TPM command generation and log verification, was implemented in the TA. We used the OP-TEE GitHub branch to support Raspberry Pi OS (i.e., Raspbian).

[0294] Regarding security analysis, race condition attacks. MyTEE records operations in privileged blocks and allows the TA to verify them later. However, because these APIs can be arbitrarily called by an untrusted OS, the effectiveness of log verification can be reduced or eliminated using TOCTOU attacks. TOCTOU, short for Time-of-Check to Time-of-Use, is a race condition attack that occurs in security-vulnerable code. This attack occurs when there is a time lag between the execution of vulnerable code and the use of its results. This allows an attacker to alter the execution results of the code or achieve unexpected results.

[0295] For example, an untrusted OS could attempt to overwrite a random number requested from the TPM with a known hash value immediately after the TA verifies the TPM command log. To eliminate this race condition, transaction flags are maintained and completed transactions are verified before new commands are sent to the TPM. In the trusted display example, a similar race condition attack could cause multiple cores to write to the same protected frame buffer. However, exploiting the race condition does not benefit the untrusted OS, because the source of the frame buffer write operation in the privileged block is always fixed to a secure buffer that the TA can update.

[0296] Abuse of the MyTEE API. The privilege escalation feature can be abused to compromise the security of the TEE and MyTEE itself. Since the TEE is not mapped to a shared page table, privileged malicious code cannot directly access the TEE. Furthermore, the page table is read-only, preventing manipulation. However, an attacker could attempt to update the page table base registers (i.e., HTTBR, VTTBR) with a malicious page table mapped to the TEE. Therefore, we invalidate critical commands that configure system registers at boot time. Furthermore, we ensure that the mytee_priv_up API executes from static kernel text, not from a dynamically loaded module (e.g., LKM). Privileged memory operations can also be abused. To prevent this, we validate memory operations using context information from the target peripheral, ensuring that they occur within predefined areas of controller registers and secure buffers.

[0297] Exploiting vulnerabilities. The privileged code block is small enough to be formally verified. Even if an attacker exploits a vulnerability in the privileged block to hijack control flow, the TEE remains secure because critical instructions, such as configuring HTTBR, do not exist in executable regions. Furthermore, illegal writes to DMA controller registers are monitored using watchpoint-based memory protection. Additional security measures can be added to prevent privilege escalation, even when attackers collude with dynamically loaded kernel modules. For example, mappings to all executable regions other than the static kernel text can be removed when privilege is elevated. This is left for future work.

[0298] Regarding performance evaluation, MyTEE imposes a burden on the OS due to stage-2 paging and DMA packet filtering for memory isolation. To measure this burden, we ran LMBench and CoreMark-PRO to measure overhead. We also measured the performance of three secure IO examples: DMA and TPM, USB keyboard, and frame buffer.

[0299] A. LMBench

[0300] LMBench is a benchmark tool used to measure rudimentary operating system operations. For example, it can measure memory allocation and deallocation, file opening and closing, and process creation. This allows for measuring the time it takes to perform basic operating system tasks.

[0301] Figure 11 shows the results of running LMBench and CoreMark-PRO. As shown in Figure 11, when MyTEE's LMBench and CoreMark-PRO results are normalized to those of Linux, an overhead of up to 23% is observed at exit.

[0302] In this example, we measured basic OS operations by running LMBench. Figure 11(a) shows the average latency of 10 iterations of the LMBench test. For write and exit, we observed a minimum overhead of 2% and a maximum overhead of 23%. For execve and / bin / sh, relatively high overheads of 15% and 11% were observed. This high overhead is not simply due to enabling stage-2 paging, but also due to the emulation of critical operations performed in monitor mode. In particular, exit, execve, and / bin / sh generate more page faults to fork new processes and induce more context switches due to their relatively long execution times. Therefore, more overhead is imposed on CPU mode switching and the emulation of critical operations.

[0303] B. CoreMark-PRO

[0304] CoreMark-PRO is a benchmark designed to measure the performance of the processor and memory subsystem. It supports five integer workloads and four floating-point workloads to measure the performance of the processor and memory subsystem. In this example, each workload was run 10 times and the average latency was evaluated. As shown in Figure 11(b), the observed overhead was negligible. Most tests had an overhead of 1% to 2%. Considering that the average execution time of the CoreMark-PRO test was significantly longer than that of LMBench, it is possible that the overhead was partially masked by a certain increase in the overall runtime.

[0305] C. DMA Performance

[0306] The overhead imposed by DMA filtering was evaluated by measuring the configuration time of a DMA controller that was trapped, verified, and emulated in MyTEE. Specifically, the DMA controller was programmed to perform memory-to-memory data transfers in TD mode by creating controller blocks (CBs). The number of chained CBs and the number of transfers within a single CB were varied from 1 to 16. Figure 12 shows the performance of memory-to-memory data transfers in DMA TD mode with CBs verified by MyTEE. The CB verification overhead was reduced to 8% as the number of chained CBs increased.

[0307] This time includes the delay required to prepare the CB (e.g., uncached memory allocation) and MMIO with the controller. The performance impact of the number of transfers in a single CB was minimal. However, as the number of chained CBs increased, the average overhead decreased from 17% to 8%. Our analysis suggests that this is because the overhead gradually decreases as the number of chained CBs increases, as the time required for MyTEE verification (i.e., copying the CB and verifying the expected memory access) is shorter than the time required to create the CB.

[0308] D. Trusted Applications

[0309] 1) Hardware TPM: In this example, we evaluated the overhead imposed on the TPM due to the introduction of MyTEE. Among TPM operations, we measured the latency of random number generation and hashing using the SHA256 and SHA1 algorithms. SHA256 and SHA1 are hash functions. A hash function is an algorithm that converts data of arbitrary size into data of fixed size. This converted data is also called a hash value or message digest. SHA256 generates a 256-bit (32-byte) hash value, and SHA1 generates a 160-bit (20-byte) hash value. These hash functions are primarily used for data integrity verification, message authentication, and digital signatures.

[0310] The size of the random number generated by the TPM ranges from 2 to 32 bytes. For hashing, the input size varies from 64 to 1,024 bytes. Each TPM operation is performed 10 times, and the average delay time is illustrated in Figure 13.

[0311] Figure 13 shows the performance (in microseconds) of random number generation and SHA1 and SHA256 hashing on a hardware TPM. A 3.68x performance degradation was observed when generating 2-byte random numbers. However, performance improved slightly as the output size increased.

[0312] In contrast, hashing saw a performance degradation of up to 2.71x. This overhead stems from additional privileged operations, such as TPM command logging and TPM output protection, and the communication latency between the CA and the TA is also included in the overhead. For random number generation, we observed a slight decrease in overhead as the random number size increased. This is because the overhead imposed by MyTEE is nearly constant, and the time it takes for the TPM to generate a random number is generally affected by the random number size. In contrast, for the TPM's hashing operation, the impact of input size is minimal, resulting in a nearly constant overhead regardless of the input size.

[0313] 2) Framebuffer: We evaluated the overhead of framebuffer protection. To do this, we compared the performance of writing data ranging in size from 1.6MB to 6.4MB to protected and unprotected framebuffers.

[0314] This time, we evaluated the overhead of framebuffer protection. To do this, we compared the performance of sequentially writing data ranging in size from 1.6MB to 6.4MB to unprotected and protected framebuffers. Both mmap-based and write-based methods were evaluated.

[0315] [Table 5]

[0316]

[0317] Table 5 shows the average latency and resulting overhead for 10 runs of each test. The write-based method observed a 14% overhead when writing 1.6 MB of data. However, performance improved for larger data sets. For 3.2 MB and 6.4 MB of data, overheads of 32% and 38% were observed, respectively. The mmap-based method showed improved performance for writing to the protected framebuffer in all test cases. In particular, writing 6.4 MB of data to the framebuffer using mmap resulted in a 47% performance improvement. Our analysis revealed that the performance improvement was due to the privileged configuration of the code block accessing the protected framebuffer. This is because interrupts are disabled in privileged blocks, allowing write operations to be performed atomically. In contrast, the baseline method incurs multiple context switches during write operations, and the significant time consumed by these switches obscures the overhead of MyTEE.

[0318] 3) USB Keyboard: We evaluated the performance of the protected USB keyboard in two aspects: (1) the overhead of processing a single key input in the kernel and (2) the performance of the application generating a secure key input. One cycle of processing a single key input in the kernel consists of two steps: sending a URB to read a scan code from the keyboard via DMA, and handling the interrupt generated by the DMA completion. The performance of these two steps was measured separately, and the average latency of 10 runs is shown in Table 6.

[0319] [Table 6]

[0320]

[0321] Sending a URB takes approximately three times longer with MyTEE. In particular, the overhead of accessing the protected MMIO area while handling a two-stage paging fault is incurred. As described in Section VI-B2, these faults are monitored to track currently allocated channels and configure secure buffers as DMA targets. Interrupt handling performance was evaluated by measuring the execution time of the hid_irq_in function. This function defines several branches for URB processing, depending on the status field. The status field indicates whether the transmitted URB was processed successfully or with an error.

[0322] We measured only the processing time for successful URBs with the urb->status field cleared, which resulted in a 33% overhead. The main contributor to the overhead was the new function that translates the scan code, which is wrapped in a privileged code block.

[0323] In our application benchmarks, we generated between 125 and 1,000 virtual keystrokes, added a 10ms delay between each keystroke, and wrote the same number of characters to the framebuffer. The application overhead ranged from 5% to 9%. Given the smaller input sizes (e.g., passcodes, OTPs), the slower and less consistent human input speed compared to virtual keystrokes, and the fact that overhead (e.g., interrupts) is masked further, this overhead can be expected to be reasonable for typical secure IO scenarios.

Claims

1. Stage-2 paging unit that separates the software-based trusted execution environment (TEE) and the general execution environment (REE) of the embedded device and independently manages memory in each execution environment. A DMA filtering unit that filters DMA transactions that directly transfer data from input / output (I / O) devices to memory to defend against malicious DMA attacks. Memory isolation and protection unit that isolates TEE and REE, hypervisor, and security monitor; When performing security-related tasks in the above-mentioned trusted execution environment, a temporary privilege escalation / demotion section is provided to allow temporary use of resources provided in the general execution environment. A system for implementing a software-based trusted execution environment for an embedded device, characterized in that it includes a secure input / output unit that performs logging and verification of input and output operations between the TEE and the REE.

2. In paragraph 1, A system for implementing a software-based trusted execution environment for an embedded device, characterized in that the above memory isolation and protection unit achieves memory isolation based on stage-2 paging of virtualization technology, thereby supplementing the absence of memory isolation hardware (TZ-ASC).

3. In paragraph 1, A system for implementing a software-based trusted execution environment for an embedded device, characterized in that the temporary privilege escalation / demotion unit compensates for the absence of secure input / output hardware (TZ-PC) by reusing a device driver to temporarily escalate / degrade the privilege of an input / output operation code block.

4. A method using a software-based trusted execution environment implementation system for an embedded device, (a) a step in which the above system separates the software-based trusted execution environment (TEE) and the general execution environment (REE) of the embedded device and independently manages memory in each execution environment; (b) a step in which the system filters DMA transactions that directly transfer data from an input / output (I / O) device to memory; (c) a step in which the above system isolates the TEE, REE, hypervisor, and security monitor; (d) a step for enabling the system to temporarily use resources provided in a general execution environment by performing privilege escalation or privilege decriminalization when performing security-related tasks in the trusted execution environment; and (e) A method for implementing a software-based trusted execution environment for an embedded device, characterized in that the system includes a step of performing logging and verification of input and output operations between the TEE and the REE.

Citation Information

Patent Citations

  • Method and Apparatus for providing a private execution environment using ARM TrustZone

    KR101922798B1

  • Compuitng system for securely executing a secure application in a rich execution environment

    KR1020180051855A

  • Motor

    KR1020220164204A

  • Harmful animals trapping device having injury preventing structure

    KR102295254B1

  • Stable volatile data acquisition method and system in ARM processor-based mobile devices

    KR102474875B1