Published on

  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide


  1. 1. Kumar R., Singhania A., Castner A., Kohler E Proceedings of Design Automation Conference Pages: 218 - 223 June 2007 04/15/10
  2. 2. <ul><li>Many embedded systems contain resource constrained microcontrollers where applications, operating system components and device drivers reside within a single address space with no form of memory protection. Programming errors in one application can easily corrupt the state of the operating system and other applications on the microcontroller. In this paper we propose a system that provides memory protection in tiny embedded processors. Our system consists of a software run-time working with minimal low-cost architectural extensions to the processor core that prevents corruption of state by buggy applications. We restrict memory accesses and control flow of applications to protection domains within the address space. The software run-time consists of a memory map: a flexible and efficient data structure that records ownership and layout information of the entire address space. </li></ul>Abstract - -
  3. 3. <ul><li>Memory map checks are done for store instructions by hardware accelerators that significantly improve the performance of our system. We preserve control flow integrity by maintaining a safe stack that stores return addresses in a protected memory region . Cross domain function calls are redirected through a software based jump table. Enhancements to the microcontroller call and return instructions use the jump table to track the current active domain. We have implemented our scheme on a VHDL model of ATMEGA103 microcontroller. Our evaluations show that embedded applications can enjoy the benefits of memory protection with minimal impact on performance and a modest increase in the area of the microcontroller. </li></ul>Abstract (cont.) - -
  4. 4. <ul><li>Memory corruption on tiny embedded processor </li></ul>What’s the Problem - - Microcontroller Address Space <ul><li>Single address space CPU </li></ul><ul><li>Shared by apps., drivers and OS </li></ul><ul><li>Buggy applications can easily corrupt the state of OS and other applications </li></ul><ul><li>Memory Protection is an enabling technology for building robust embedded software </li></ul>Memory is accessible to all SW modules via a single address space Program1 Program2 Program3 OS
  5. 5. <ul><li>MMU can provide protection domains </li></ul><ul><ul><li>However, No MMU in embedded micro-controllers </li></ul></ul><ul><ul><ul><li>MMU hardware requires lot of RAM </li></ul></ul></ul><ul><ul><ul><li>Increases area and power consumption </li></ul></ul></ul><ul><ul><ul><li>Poor performance - High context switch overhead </li></ul></ul></ul><ul><li>Memory Protection Unit (MPU) </li></ul><ul><ul><li>Static partition of address space into segments </li></ul></ul><ul><ul><li>However, not suited for complex embedded software (such as OS) </li></ul></ul><ul><ul><ul><li>Supports only two domains (user mode and supervisor mode) </li></ul></ul></ul><ul><ul><ul><ul><li>Protect the kernel from applications but not the applications from another </li></ul></ul></ul></ul><ul><li>Software-based Fault Isolation </li></ul><ul><ul><li>Run time checks to ensure all memory accesses reside within the segment allocated to it </li></ul></ul><ul><ul><li>The run time checks are introduced through compiler or binary rewrite </li></ul></ul><ul><ul><ul><li>However, Binary rewrite are quite error prone </li></ul></ul></ul>Related Work - - supervisor user P1 P2 P3 MPU
  6. 6. <ul><li>Memory protection suited for low-end microcontrollers </li></ul><ul><ul><li>Solve memory write Protection </li></ul></ul><ul><ul><ul><li>“ store ”, “ call ”, and “ return ” instructions </li></ul></ul></ul>The proposed Memory Protection Method - - Memory Map Table HW extension Program1 Program2 Program3 OS Domain B Domain C Domain D Domain N …… Domain A Domain B Domain C Domain N Memory Map Checker Control Flow Manager Jump Table Safe Stack Software Routine <ul><li>Hardware Software Co-Design approach to memory protection </li></ul>Domain A
  7. 7. Protection Domain - - <ul><li>Domains - Logical partitions of address space </li></ul><ul><li>Every software module stores its state in its own protection domain </li></ul><ul><li>Protect domain from corruption by other domains </li></ul><ul><ul><li>Modules are restricted from writing to memory outside their domain through run-time checks </li></ul></ul><ul><li>There is one single trusted domain in the system that is allowed to access all memory </li></ul>
  8. 8. Memory Map Data Structure - - Fine-grained layout and ownership information User Domain Kernel Domain Partition address space into blocks Memory is allocated to domains as segments (Sets of contiguous blocks) <ul><li>Store information for all blocks </li></ul><ul><li>Encoded information for all block </li></ul><ul><ul><li>Ownership – domain ID </li></ul></ul><ul><ul><li>Layout - start of a logical segment </li></ul></ul>A domain could be allocated multiple segments <ul><li>Efficiently encoded using 4 bits per block </li></ul><ul><ul><li>xxx0 - Start block of segment </li></ul></ul><ul><ul><li>xxx1 - Later block of segment </li></ul></ul><ul><ul><li>xxx is the 3-bit domain ID </li></ul></ul>Back
  9. 9. <ul><li>Functional unit that validates store operations </li></ul><ul><ul><li>Programs can write only into their domain </li></ul></ul><ul><ul><li>Invoked before every write access </li></ul></ul>Memory Map Checker - - DATA_BUS <ul><li>Triggered on a store instruction </li></ul><ul><li>Operations performed by the checker </li></ul><ul><ul><li>Lookup memory map for issued write address </li></ul></ul><ul><ul><li>Retrieve permission from memory map and validates stores </li></ul></ul><ul><ul><ul><li>Verify current executing domain is block owner </li></ul></ul></ul>CPU Memory Map Checker RAM CPU_ADDR CPU_WR_EN CPU_STALL MMC_ADDR MMC_WR_EN ST_INSTR
  10. 10. <ul><li>Assuming block size of 8 bytes, the nine significant bits of the address represent the block number </li></ul><ul><li>Permissions are packed into a byte </li></ul><ul><ul><li>If the encoded information is stored in four bits, then each byte would contain information of two contiguous blocks </li></ul></ul><ul><ul><li>Last bit of the block number represents the block offset of the permission </li></ul></ul><ul><li>The remaining bits index into the memory map tale </li></ul>Address  Memory Map Lookup - - Address (bits 11-0) Memory Map Table 1 Byte has 2 memory map records 8 1 Block Number (bits 11-3) Byte Offset (bits 2-0) mem_map_base Assume block size of 8 bytes Memory Map Offset (bits 11-4)
  11. 11. <ul><li>In cycle 2 </li></ul><ul><ul><li>First, it stalls the processor execution and take control of the address bus to memory </li></ul></ul><ul><ul><li>Perform address translation to lookup memory map for issued write address </li></ul></ul><ul><ul><li>Read memory map table to retrieve the permission </li></ul></ul><ul><li>In cycle 3 </li></ul><ul><ul><li>Retrieve permission from memory map, and compare the ownership information to the current executing domain ID </li></ul></ul><ul><ul><li>If check is successful, then MMC issues a write operation to data memory </li></ul></ul>Operations Performed by Memory Map Checker (MMC) - - CPU_WR_ADDR MMC_RD_ADDR Cycle 1 Cycle 3 Cycle 2 Regular Mode Protected Mode CLK CPU_ADDR CPU_WR_EN MMC_ADDR MMC_WR_EN CPU_STALL
  12. 12. <ul><li>The software library manages all the memory available </li></ul><ul><ul><li>Ensure memory map accurately reflects current ownership and layout </li></ul></ul><ul><ul><ul><li>The library provides “ malloc ”, “ free ” and “ change_own ” calls that automatically update the memory map data structure </li></ul></ul></ul><ul><ul><li>Only permit block owner to free/change its ownership </li></ul></ul><ul><ul><ul><li>To enforce this condition, the software library reads the current active domain ID </li></ul></ul></ul><ul><ul><li>Set up the memory map to be located in a protected region </li></ul></ul><ul><ul><ul><li>This prevents corruption of the memory map data structure </li></ul></ul></ul><ul><ul><li>Initialize the MMC with the proper block size, number of protection domains and the range of protected address space </li></ul></ul>Memory Map Software Library - - Back
  13. 13. <ul><li>Control flow can become corrupt at run-time </li></ul><ul><ul><li>EX: Returns on corrupted stack (return addresses are stored in stack) </li></ul></ul><ul><ul><li>Memory map can’t prevent such internal memory corruption </li></ul></ul><ul><ul><ul><li>Programming errors can cause a module to corrupt its own state </li></ul></ul></ul><ul><li>Control flow manager ensures that control can never flow out of a domain, except </li></ul><ul><ul><li>Via calls to functions exported by other domains </li></ul></ul><ul><ul><li>Via returns to calls from other domains </li></ul></ul><ul><li>The current executing domain also needs to be tracked </li></ul><ul><ul><li>Required by the memory map checker to validate write accesses </li></ul></ul>Control Flow Manager - - <ul><li>Preserve control flow integrity through the safe stack that stores return addresses </li></ul>
  14. 14. <ul><li>Each domain has its own jump table in flash memory that contains </li></ul><ul><ul><li>The set of functions exported by each domain </li></ul></ul><ul><li>The jump table can’t be corrupted </li></ul><ul><ul><li>Due to modules are not allowed to write to flash memory </li></ul></ul><ul><li>Each entry in the jump table is an instruction jump to a valid exported function </li></ul><ul><li>Re-directed through jump table to functions exported by a domain </li></ul>Cross Domain Linking - - Program Memory fooJT: jmp foo Domain B Jump Table Cross Domain Call Jump exception Jump exception Domain A call fooJT Domain B foo: … ret <ul><li>Verify call into jump table </li></ul><ul><li>Compute callee domain ID </li></ul>
  15. 15. <ul><li>Jump table of all domains are stored at fixed location in flash memory </li></ul><ul><ul><li>This simplifies the verifying of the target address of a call </li></ul></ul><ul><li>A valid target address has to reside in the jump table </li></ul><ul><li>The ID of the called domain can be easily determined </li></ul><ul><ul><li>First, computing the address offset from the base address of the jump table </li></ul></ul><ul><ul><li>Then, dividing it by the size of the jump table </li></ul></ul><ul><li>The cross domain call state machine </li></ul><ul><ul><li>Push the current domain ID into stack , during cross domain call </li></ul></ul><ul><ul><li>Restore the previous domain ID and transfer control back to the caller’s domain , during cross domain return </li></ul></ul>Domain Tracking - - jmp_tbl_base_address jmp_tbl_upper_bound call_addr <= < AND
  16. 16. <ul><li>Single stack shared by all domains </li></ul><ul><li>Protection Model </li></ul><ul><ul><li>Prevent corruption of stack belonging to a domain by any module belonging to a different domain </li></ul></ul><ul><li>Bounds set during cross domain call </li></ul><ul><ul><li>Processor copies the current stack pointer into a stack_bound register </li></ul></ul><ul><li>Enforced by MMC before all writes </li></ul><ul><ul><li>No writes beyond stack bound </li></ul></ul>Run-Time Stack Protection - - Run Time Stack Caller Domain Stack Frame Callee Domain Stack Frame Stack Ptr. Stack_Bound Stack Base <ul><li>Prevent cross domain corruption of stack </li></ul>
  17. 17. <ul><li>In spite of the stack are protected from corruption from modules in other domains </li></ul><ul><ul><li>However, programming errors can cause a module to corrupt its own stack </li></ul></ul><ul><li>Therefore, maintain an extra stack in protected memory </li></ul><ul><ul><li>To store return addresses in a separate stack that resides in a different protection domain </li></ul></ul><ul><li>Setup safe stack at the end of all global data and make it grows up toward run-time stack </li></ul>Safe Stack - - RUN-TIME STACK SAFE STACK HEAP and GLOBALS Safe Stack and Run-Time Stack approach one another
  18. 18. Performance Overhead (CPU Cycles) Introduced by the Memory Protection Mechanism - - Compare with software based approach through binary rewrite <ul><li>High overhead of software based memory map checker </li></ul><ul><ul><li>Due to require bit shift operations to translate write address to memory map lookup </li></ul></ul><ul><li>Cross domain call and return have an overhead of five cycles </li></ul><ul><ul><li>Due to push “current domain ID”, “stack bound” and “return address” to stack </li></ul></ul><ul><ul><ul><li>Information of five bytes needed to push to stack, and one byte can be written every cycle </li></ul></ul></ul><ul><ul><li>Restoring the values read from stack </li></ul></ul><ul><li>Saving and restoring return addresses doesn’t introduced added overhead </li></ul><ul><ul><li>Due to simply redirect the store of the return address to safe stack when processor pushes the return address to the run-time stack </li></ul></ul>Unit: CPU Cycles Superior performance of run-time checks in HW
  19. 19. <ul><li>Overhead introduced in memory map software library </li></ul><ul><ul><li>Due to memory map needs to be updated during allocation, free and transfer of memory </li></ul></ul><ul><li>Higher overheads of free and change_own calls </li></ul><ul><ul><li>Due to additional checks to prevent illegal freeing or ownership transfer of memory by non-owners </li></ul></ul>Performance Overhead (CPU Cycles) of Software Library Introduced by the Protection Mechanism - - Compare overhead of memory allocation routines in the presence and absence of the protection mechanism Unit: CPU Cycles
  20. 20. Code and Data Memory Usage of the Software Library <ul><li>Memory map size is 256 bytes for multi-domain protection </li></ul><ul><ul><li>This represents an overhead of 6.25% (256 bytes / 4KB) </li></ul></ul><ul><li>Flexible data-structure - Tradeoff RAM for protection </li></ul><ul><ul><li>Size of memory map required can be reduced </li></ul></ul><ul><ul><ul><li>By modifying portion of address space that required memory map for protection </li></ul></ul></ul><ul><li>The total code memory usage of the software library </li></ul><ul><ul><li>3674 bytes , an overhead of 2.8% (3674 bytes / 128KB) </li></ul></ul>- -
  21. 21. <ul><li>Most of the additions to the core area are in the memory map decoder </li></ul><ul><ul><li>That support arbitrary bit-shift in a single cycle </li></ul></ul><ul><ul><ul><li>We can eliminate this overhead for fixed block size and number of protection domains </li></ul></ul></ul><ul><li>32% overall increase in the core area </li></ul><ul><ul><li>This represents a modest increase in the overall chip area </li></ul></ul><ul><ul><ul><li>As core occupies only a small fraction of the overall area </li></ul></ul></ul>Hardware Overhead of the Memory Protection Mechanism - -
  22. 22. <ul><li>HW/SW co-design approach for memory protection </li></ul><ul><ul><li>Enabling technology for reliable embedded software systems </li></ul></ul><ul><ul><li>Combine flexibility of software with efficiency of hardware </li></ul></ul><ul><li>Building blocks for memory protection </li></ul><ul><ul><li>Memory map checker </li></ul></ul><ul><ul><li>Control flow manager </li></ul></ul><ul><li>Practical system with widespread applications </li></ul><ul><ul><li>Low resource utilization </li></ul></ul><ul><ul><li>Minimal performance overhead </li></ul></ul><ul><ul><li>Binary compatible with existing software and tool-chains </li></ul></ul><ul><ul><ul><li>The software library provides a standard programming interface </li></ul></ul></ul><ul><ul><ul><li>Doesn’t modify the instruction set architecture of the processor </li></ul></ul></ul>Conclusions - -
  23. 23. <ul><li>Memory protection suited for low-end microcontrollers </li></ul><ul><ul><li>Doesn’t static partition of address space </li></ul></ul><ul><ul><ul><li>Rely on a memory map data structure </li></ul></ul></ul><ul><ul><ul><ul><li>Record ownership and layout info. of the entire address space </li></ul></ul></ul></ul><ul><ul><li>Doesn’t rewrite binary to introduce run time checks </li></ul></ul><ul><ul><ul><li>Enhance the “ store ”, “ call ”, and “ return ” instructions to perform run time checks in hardware </li></ul></ul></ul><ul><ul><li>Hardware Software Co-Design approach to memory protection </li></ul></ul>The proposed Memory Protection Method - - Memory Map Checker (STORE instruction extension) Hardware Extensions Software Routine Memory Map Domain Tracker (CALL instruction extension) Domain Tracker (RETURN instruction extension) Jump Table Safe Stack <ul><li>Low cost architecture extension and software library work together to isolate from another </li></ul>