tpotyondy
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Default Security Paper **Something we will need to control for is for the repos that we are cloning that do not have MPUs** ## Related MPU Survey NDSS BAR workshop paper presents "taxonomy" to evaluate MPU usage by the following criteria: - **Code Integrity Protection (CIP)**: Code regions can be set as non-writable to prevent code injection and manipulation. - **Data Execution Prevention (DEP)**: Data regions like stack or heap can be set as non-executable to prevent buffer overflow exploitation. CIP and DEP map to WˆX or executable-space protection in general computing platforms. - **Coarse-grained StackGuard (CSG)**: An inaccessible memory hole is placed at the stack boundary to detect stack overflows. Note that CSG can only detect overflows to the entire stack region, not confusing with traditional StackGuard to function-level stack frames. - **Kernel Memory Isolation (KMI)**: User mode (un-privileged) code cannot access any memory belonging to the kernel space without invoking system calls, which is similar to the user space and kernel space separation in modern OSs. - **User Task Memory Isolation (TMI)**: User mode (unprivileged) tasks can only access its own memory except explicitly shared memory regions that belong to other tasks or kernel, which is similar to the process isolation in modern modern OSs. - **Peripherals Isolation (PI)**: Peripheral access is re-stricted to tasks that actually need it. ![image](https://hackmd.io/_uploads/HkQ5n9kL0.png) ## Zephyr Zephyr uses a handful of config flags in the overlay `prj.conf` to enable the above security features. 1. `CONFIG_HW_STACK_PROTECTION` 2. `CONFIG_USERSPACE` (allows creation of unprivledged threads) 3. `CONFIG_MPU_STACK_GUARD` [General Recommendations](https://docs.zephyrproject.org/latest/hardware/porting/board_porting.html#general-recommendations) > It is recommended to enable the MPU by default, if there is support for it in hardware. For boards with limitedmemory resources it is acceptable to disable it. When the MPU is enabled, it is recommended to also enable hardware stack protection (CONFIG_HW_STACK_PROTECTION=y) and, thus, allow the kernel to detect stack overflows when the system is running in privileged mode. **Zephyr provides a hardening guide with recommended security features:** ``` name | current | recommended || check result ================================================================================================ CONFIG_BOOT_BANNER | y | n || FAIL CONFIG_BUILD_OUTPUT_STRIPPED | n | y || FAIL CONFIG_FAULT_DUMP | 2 | 0 || FAIL CONFIG_HW_STACK_PROTECTION | n | y || FAIL CONFIG_MPU_STACK_GUARD | n | y || FAIL CONFIG_OVERRIDE_FRAME_POINTER_DEFAULT | n | y || FAIL CONFIG_STACK_SENTINEL | n | y || FAIL CONFIG_EARLY_CONSOLE | y | n || FAIL CONFIG_PRINTK | y | n || FAIL ``` **Zephyr design related to what we are doing:** > - Access to thread stack buffers will be controlled with a policy which partially depends on the underlying memory protection > hardware. > - A user thread will by default have read/write access to its own stack buffer. > - A user thread will never by default have access to user thread stacks that are not members of the same memory domain. > - A user thread will never by default have access to thread stacks owned by a supervisor thread, or thread stacks used to handle system call privilege elevations, interrupts, or CPU exceptions. > - A user thread may have read/write access to the stacks of other user threads in the same memory domain, depending on hardware. > - On MPU systems, threads may only access their own stack buffer. > - On MMU systems, threads may access any user thread stack in the same memory domain. Portable code should not assume this. > - By default, program text and read-only data are accessible to all threads on read-only basis, kernel-wide. This policy may be adjusted. > - User threads by default are not granted default access to any memory except what is noted above **Zephyr ensures for usermode threads**: > - We ensure the detection and safe handling of user mode stack overflows. > - We prevent invoking system calls to functions excluded by the kernel configuration. > - We prevent disabling of or tampering with kernel-defined and hardware- enforced memory protections. > - We prevent re-entry from user to supervisor mode except through the kernel- defined system calls and interrupt handlers. > - We prevent the introduction of new executable code by user mode threads, except to the extent to which this is supported by kernel system calls. _This is all entirely dependent on if the developer enables usermode for the given task_. ### Analysis of Intel's ECFW built on Zephyr - Only mention of `CONFIG_USERSPACE` is in `doc/doxyfile.in` - All tasks (defined in `misc/task_handler.c`) are started with [`K_INHERIT_PERMS`](https://docs.zephyrproject.org/latest/kernel/services/threads/index.html#c.K_INHERIT_PERMS), which inherits all permissions from the main thread. Threads can be later downgraded to user-mode threads, however that function [`k_thread_user_mode_enter`](https://docs.zephyrproject.org/latest/kernel/services/threads/index.html#group__thread__apis_1ga3fbe1c8a5f3ef1c25382c7d6fca35764) is not used anywhere. - Skimming over the generated assembly, it does not seem like the MPU is configured or used at all. (The MPU registers do not seem to be referenced anywhere) - Trying to enable `CONFIG_USERSPACE` complains about `ARCH_HAS_USERSPACE` not being enabled (which is weird, as that should be turned on for a Cortex-M, which the `mec1501_mtl_p` is) Evidence for high coupling: - Certain state is shared between multiple tasks, without any system call interface or other transition mechanism. - Possible function call stack that crosses task boundary: - `pwrseq_thread` (root of task, defined in `task_handler.c`) calls - `pwrseq_update` calls - `pwrseq_handle_transition_to_s0` calls - `power_on` calls - `soc_debug_consent_kbs` (if `CONFIG_SOC_DEBUG_AWARENESS`), calls - `kbs_keyseq_boot_detect` (if `CONFIG_POWER_SEQUENCE_DISABLE_TIMEOUT_HOTKEY`), - accesses `keyseq_det[type].detected` - `keyseq_det` (`.detected`) is defined in `kbs_matrix.c` - written by `fw_hotkeyseq_detection`, - called by `kscan_callback`, - called by `kbs_matrix_init`, - called by `kbc_init`, - called by `to_from_host_thread` (root of task, defined in `task_handler.c`) ## FreeRTOS Summary: you can use MPU for task isolation if you use `xTaskCreateRestricted()` to create tasks. However, this is opt-in. Normal tasks (run with privilege and no MPU isolation) can be made with `xTaskCreate()`. A secure repo would create all tasks with `xTaskCreateRestricted()` to explictly say which tasks are (un)privileged. [almost no one is using restricted processes ](https://github.com/search?q=xTaskCreateRestricted+AND+language%3AC+AND+%28NOT+path[…]%3Aworkspace%29++AND+%28NOT+path%3Ampu_wrappers.c%29+&type=code) - FreeRTOS is customised using a configuration file called FreeRTOSConfig.h. Every FreeRTOS application must have a FreeRTOSConfig.h header file https://www.freertos.org/a00110.html - See: "`/* FreeRTOS MPU specific definitions. */`" - I think option `configCHECK_FOR_STACK_OVERFLOW 3` has to be set for MPU stack overflow protection ([src](https://www.freertos.org/Stacks-and-stack-overflow-checking.html)) - functions to set MPU https://www.freertos.org/FreeRTOS-MPU-specific.html - not sure what this is, but it shows up on github a lot `configENABLE_MPU` - Can see the % occurrence of tasks which are started normally versus with MPU - `FreeRTOS-MPU Specifics` section of https://www.freertos.org/FreeRTOS-MPU-memory-protection-unit.html explains all the details - example in code: https://www.freertos.org/xTaskCreateRestricted.html > Using FreeRTOS with Memory Protection Unit (MPU) Support > > Description Memory Protection Unit (MPU) support in FreeRTOS ARMv8-M ports enables application tasks to execute in a privileged or unprivileged (user) mode, and provides fine grained memory and peripheral access control on a task by task basis. > >Unprivileged tasks: > > Are created using the xTaskCreateRestricted() API. > Default to having no RAM access other than to their own stacks. > Cannot execute code marked by the MPU as privileged access only. > Can optionally be assigned access up to three additional memory regions, which can be changed at run-time. > >A memory fault is triggered any time an unprivileged task tries to access any memory region for which it has not been granted access. The fault handler gives the application writer a chance to take an appropriate action, which may be terminating the offending task. > >Do not confuse the privilege level of a task with the security domain it executes in. The secure and non-secure sides of an ARMv8-M core each have their own MPU - so it is possible to have both privileged and unprivileged execution on both the secure and non-secure sides. > from https://www.freertos.org/2020/04/using-freertos-on-armv8-m-microcontrollers.html ### Flags/Functions `configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS` `configCHECK_FOR_STACK_OVERFLOW` `xTaskCreateRestricted` / `xTaskCreateRestrictedStatic` / `portSWITCH_TO_USER_MODE` ## RIOT - [VERY GOOD UP-TO-DATE LIST OF ALL SECURITY FEATURES](https://forum.riot-os.org/t/energy-management-in-riot/4163/6) - secure boot - only boot signed firmware - https://api.riot-os.org/group__pseudomodule__mpu__noexec__ram.html - need to manually enable - no results show up on GitHub - there are zero github repos which use the riot mpu_noexec_ram . every riot repo uses mpu_stack_guard as it is on by default, and I do not see anyone who turns it off. - https://github.com/search?q=%23define+MODULE_MPU_NOEXEC_RAM&type=code - https://api.riot-os.org/group__pseudomodule__mpu__stack__guard.html - Example usage https://github.com/RIOT-OS/RIOT/tree/master/tests/cpu/ - every board that has a `cortexm_mpu` (`FEATURES_PROVIDED += cortexm_mpu`) gets `c` [enabled by default](https://github.com/RIOT-OS/RIOT/blob/0ebb65710c7b0816fb17d8b913826a5ee7a3e58f/makefiles/pseudomodules.inc.mk#L284-L306) - [`mpu_configure`](https://github.com/RIOT-OS/RIOT/blob/master/core/sched.c#L35-L37) is only called for the two flags linked above. - cortexm_stack_limit - RIOT doesn't have processes. There are threads and there is proper multithreading - [No privilege levels kernel/user mode](https://forum.riot-os.org/t/running-riot-threads-as-unprivileged-user-mode/198) ([2](https://forum.riot-os.org/t/need-advice-for-research/3834)) - MODULE_MPU_STACK_GUARD only enabled by default in developer mode - TODO: measure the actual overhead of software and hardware stack overflow checks [supported boards](https://github.com/RIOT-OS/RIOT/tree/master/boards) ## Contiki-ng - no memory protection ## Data Collection Methods - perform github "repository search" for keyword (e.g. zephyr) - perform github "code search" for filename (e.g. west.yml) - manually confirm all repos with greater than 10 stars - not forks ### Result Zephyr results (w/o =y flag) ``` Total Repos Searched: 86 Total repos using hw_stack_protection: 19 Total repos using user_mode_threads: 17 Percentage of repos using hw_stack_protection: 21.8% Percentage of repos using user_mode_threads: 19.5% ``` Zephyr results (w/ full flag) ``` Total Repos Searched: 87 Total repos using hw_stack_protection: 17 Total repos using mpu_stack_guard: 6 Total repos using user_mode_threads: 9 Percentage of repos using hw_stack_protection: 19.5% Percentage of repos using mpu_stack_guard: 6.9% Percentage of repos using user_mode_threads: 10.3% ``` ---- FreeRTOS Results: ``` sw stack guard: hw stack guard: process isolation: ``` ---- Contiki-ng Results: ``` sw stack guard: hw stack guard: process isolation: ``` ---- RIOT Results: ``` sw stack guard: hw stack guard: process isolation: ``` --- ## Other Notes - Leon is building/looking into EC firmware.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully