Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REBASE && FF] Add Stack Cookie Support for IA32, ARM, and AARCH64 #714

Merged
merged 7 commits into from
Feb 28, 2024

Commits on Feb 28, 2024

  1. remove edk2-basetools (microsoft#732)

    Removes edk2-basetools from pip-requirements.txt and any usage of it in
    the CISettings.py. The is done as there are changes in the build tools
    python source code that are available locally in BaseTools (as it is
    managed by Project Mu) that is not available in edk2-basetools.
    
    - [ ] Impacts functionality?
    - **Functionality** - Does the change ultimately impact how firmware
    functions?
    - Examples: Add a new library, publish a new PPI, update an algorithm,
    ...
    - [ ] Impacts security?
    - **Security** - Does the change have a direct security impact on an
    application,
        flow, or firmware?
      - Examples: Crypto algorithm change, buffer overflow fix, parameter
        validation improvement, ...
    - [ ] Breaking change?
    - **Breaking change** - Will anyone consuming this change experience a
    break
        in build or boot behavior?
    - Examples: Add a new library class, move a module to a different repo,
    call
        a function in a new library class in a pre-existing module, ...
    - [ ] Includes tests?
      - **Tests** - Does the change include any explicit test code?
      - Examples: Unit tests, integration tests, robot tests, ...
    - [ ] Includes documentation?
    - **Documentation** - Does the change contain explicit documentation
    additions
        outside direct code modifications (and comments)?
    - Examples: Update readme file, add feature readme file, link to
    documentation
        on an a separate Web page, ...
    
    Verified the build system continues to use the local python source
    
    N/A - only effects this repository's CI system.
    Javagedes authored and TaylorBeebe committed Feb 28, 2024
    Configuration menu
    Copy the full SHA
    e40eff0 View commit details
    Browse the repository at this point in the history
  2. Fix Null Lib Evaluation in Basetools

    Description
    
    When parsing INF files, Basetools treats both
    libraries and modules the same. When the library
    dependencies are being collected for a
    module/library, libraries linked via:
    
    `NULL|Path/To/Library`
    
    would be included in the list of dependencies for
    libraries which does not match how these expressions
    are expected to be interpreted.
    
    This update changes the evaluation loop to skip
    NULL links when collecting dependencies for
    libraries.
    
    - [x] Impacts functionality?
      - **Functionality** - Does the change ultimately impact how firmware functions?
      - Examples: Add a new library, publish a new PPI, update an algorithm, ...
    - [ ] Impacts security?
      - **Security** - Does the change have a direct security impact on an application,
        flow, or firmware?
      - Examples: Crypto algorithm change, buffer overflow fix, parameter
        validation improvement, ...
    - [ ] Breaking change?
      - **Breaking change** - Will anyone consuming this change experience a break
        in build or boot behavior?
      - Examples: Add a new library class, move a module to a different repo, call
        a function in a new library class in a pre-existing module, ...
    - [ ] Includes tests?
      - **Tests** - Does the change include any explicit test code?
      - Examples: Unit tests, integration tests, robot tests, ...
    - [ ] Includes documentation?
      - **Documentation** - Does the change contain explicit documentation additions
        outside direct code modifications (and comments)?
      - Examples: Update readme file, add feature readme file, link to documentation
        on an a separate Web page, ...
    
    How This Was Tested
    
    Tested in pipelines
    
    Integration Instructions
    
    N/A
    TaylorBeebe committed Feb 28, 2024
    Configuration menu
    Copy the full SHA
    e28ca99 View commit details
    Browse the repository at this point in the history
  3. Update StackCheckLibNull to Fix MSVC IA32 Builds and add GCC ARM Support

    Description
    
    MSVC IA32 requires the __security_check_cookie function to specify
    byte size (@__security_check_cookie@4). This change also declares
    __stack_chk_fail() in StackCheckLibNull.c to support GCC.
    
    - [x] Impacts functionality?
      - **Functionality** - Does the change ultimately impact how firmware functions?
      - Examples: Add a new library, publish a new PPI, update an algorithm, ...
    - [ ] Impacts security?
      - **Security** - Does the change have a direct security impact on an application,
        flow, or firmware?
      - Examples: Crypto algorithm change, buffer overflow fix, parameter
        validation improvement, ...
    - [ ] Breaking change?
      - **Breaking change** - Will anyone consuming this change experience a break
        in build or boot behavior?
      - Examples: Add a new library class, move a module to a different repo, call
        a function in a new library class in a pre-existing module, ...
    - [ ] Includes tests?
      - **Tests** - Does the change include any explicit test code?
      - Examples: Unit tests, integration tests, robot tests, ...
    - [ ] Includes documentation?
      - **Documentation** - Does the change contain explicit documentation additions
        outside direct code modifications (and comments)?
      - Examples: Update readme file, add feature readme file, link to documentation
        on an a separate Web page, ...
    
    How This Was Tested
    
    Tested on Q35 GCC and MSVC builds and an SBSA GCC build
    by purposefully overflowing the stack when the NULL library
    is in use.
    
    Integration Instructions
    
    N/A
    TaylorBeebe committed Feb 28, 2024
    Configuration menu
    Copy the full SHA
    659598e View commit details
    Browse the repository at this point in the history
  4. Generate Random Stack Cookie Value at Build Time

    Description
    
    This PR updates the GenC logic to generate a random stack cookie value
    for the stack check libraries. These random values improve security
    for modules which cannot update the global intrinsics.
    
    - [x] Impacts functionality?
      - **Functionality** - Does the change ultimately impact how firmware functions?
      - Examples: Add a new library, publish a new PPI, update an algorithm, ...
    - [ ] Impacts security?
      - **Security** - Does the change have a direct security impact on an application,
        flow, or firmware?
      - Examples: Crypto algorithm change, buffer overflow fix, parameter
        validation improvement, ...
    - [ ] Breaking change?
      - **Breaking change** - Will anyone consuming this change experience a break
        in build or boot behavior?
      - Examples: Add a new library class, move a module to a different repo, call
        a function in a new library class in a pre-existing module, ...
    - [ ] Includes tests?
      - **Tests** - Does the change include any explicit test code?
      - Examples: Unit tests, integration tests, robot tests, ...
    - [ ] Includes documentation?
      - **Documentation** - Does the change contain explicit documentation additions
        outside direct code modifications (and comments)?
      - Examples: Update readme file, add feature readme file, link to documentation
        on an a separate Web page, ...
    
    How This Was Tested
    
    Tested on MSVC and GCC builds of Q35 and a GCC build of SBSA
    by purposefully overflowing the stack.
    
    Integration Instructions
    
    N/A
    TaylorBeebe committed Feb 28, 2024
    Configuration menu
    Copy the full SHA
    4e5a2a9 View commit details
    Browse the repository at this point in the history
  5. Add Stack Cookie Support for IA32, ARM, and AARCH64

    Description
    
    This update replaces StackCheckLib with StackCheckLibStaticInit and
    StackCheckLibDynamicInit. The new libraries have GCC support for ARM,
    AARCH64, IA32 and X64 builds. The libraries have MSVC support for IA32
    and X64 builds.
    
    StackCheckLibStaticInit does not have a library constructor and
    should be used whenever the stack cookie value cannot be updated
    during driver execution (i.e. when the stack cookie is not in a
    writable or no RNG library is available).
    
    StackCheckLibDynamicInit has a library constructor and should be used
    whenever the stack cookie value can be updated at runtime (i.e. for
    DXE modules and shadowed PEIMs).
    
    This update also removes the stack cookie library definitions from
    MdeLibs.dsc.inc due to GCC build issues when the instanced versions are
    used during CI builds. The instanced versions will need to be explicitly
    added to the platform DSC files, and this is acceptable because
    platforms will likely want to mix and match the static and dynamic
    versions of the library for each module type.
    
    - [x] Impacts functionality?
      - **Functionality** - Does the change ultimately impact how firmware functions?
      - Examples: Add a new library, publish a new PPI, update an algorithm, ...
    - [x] Impacts security?
      - **Security** - Does the change have a direct security impact on an application,
        flow, or firmware?
      - Examples: Crypto algorithm change, buffer overflow fix, parameter
        validation improvement, ...
    - [x] Breaking change?
      - **Breaking change** - Will anyone consuming this change experience a break
        in build or boot behavior?
      - Examples: Add a new library class, move a module to a different repo, call
        a function in a new library class in a pre-existing module, ...
    - [ ] Includes tests?
      - **Tests** - Does the change include any explicit test code?
      - Examples: Unit tests, integration tests, robot tests, ...
    - [ ] Includes documentation?
      - **Documentation** - Does the change contain explicit documentation additions
        outside direct code modifications (and comments)?
      - Examples: Update readme file, add feature readme file, link to documentation
        on an a separate Web page, ...
    
    How This Was Tested
    
    Tested on a Q35 GCC and MSVC builds, and on an SBSA GCC build
    by purposefully performing a stack overflow.
    
    Integration Instructions
    
    Platforms will need to explicitly declare the
    StackCheckLib and StackCheckFailureLib instances for
    their platforms.
    
    EXAMPLE:
    
    ```
    StackCheckFailureLib|MdePkg/Library/StackCheckFailureLibNull/StackCheckFailureLibNull.inf
    [LibraryClasses.common.SEC, LibraryClasses.common.PEI_CORE]
      NULL|MdePkg/Library/StackCheckLibNull/StackCheckLibNull.inf
    
    [LibraryClasses.common.PEIM, LibraryClasses.common.MM_CORE_STANDALONE, LibraryClasses.common.MM_STANDALONE]
      NULL|MdePkg/Library/StackCheckLib/StackCheckLibStaticInit.inf
    
    [LibraryClasses.common.DXE_CORE, LibraryClasses.common.SMM_CORE, LibraryClasses.common.DXE_SMM_DRIVER, LibraryClasses.common.DXE_DRIVER, LibraryClasses.common.DXE_RUNTIME_DRIVER, LibraryClasses.common.DXE_SAL_DRIVER, LibraryClasses.common.UEFI_DRIVER, LibraryClasses.common.UEFI_APPLICATION]
      NULL|MdePkg/Library/StackCheckLib/StackCheckLibDynamicInit.inf
    ```
    TaylorBeebe committed Feb 28, 2024
    Configuration menu
    Copy the full SHA
    8336989 View commit details
    Browse the repository at this point in the history
  6. Update StackCheckFailureLib to StackCheckFailureHookLib, Add Failure …

    …Address as Argument
    
    Description
    
    To clarify the purpose of StackCheckFailureLib, this PR renames it to
    StackCheckFailureHookLib. Also, the failure address is passed
    as an argument to the hook function to allow the hook to trace the
    fault. An interrupt will still be called after the hook returns.
    
    - [x] Impacts functionality?
      - **Functionality** - Does the change ultimately impact how firmware functions?
      - Examples: Add a new library, publish a new PPI, update an algorithm, ...
    - [x] Impacts security?
      - **Security** - Does the change have a direct security impact on an application,
        flow, or firmware?
      - Examples: Crypto algorithm change, buffer overflow fix, parameter
        validation improvement, ...
    - [x] Breaking change?
      - **Breaking change** - Will anyone consuming this change experience a break
        in build or boot behavior?
      - Examples: Add a new library class, move a module to a different repo, call
        a function in a new library class in a pre-existing module, ...
    - [ ] Includes tests?
      - **Tests** - Does the change include any explicit test code?
      - Examples: Unit tests, integration tests, robot tests, ...
    - [ ] Includes documentation?
      - **Documentation** - Does the change contain explicit documentation additions
        outside direct code modifications (and comments)?
      - Examples: Update readme file, add feature readme file, link to documentation
        on an a separate Web page, ...
    
    How This Was Tested
    
    Tested on MSVC and GCC builds of Q35 and a GCC build of SBSA
    by purposefully corrupting the stack.
    
    Integration Instructions
    
    Platforms will need to update their StackCheckFailureLib instance
    to the new StackCheckFailureHookLib.
    
    EXAMPLE:
    
    ```
    StackCheckFailureHookLib|MdePkg/Library/StackCheckFailureHookLibNull/StackCheckFailureHookLibNull.inf
    ```
    TaylorBeebe committed Feb 28, 2024
    Configuration menu
    Copy the full SHA
    03cb1dc View commit details
    Browse the repository at this point in the history
  7. Update Toolsdef to Add Stack Cookies for MSVC IA32, and GCC Arm and A…

    …ARCH64
    
    Description
    
    This change adds stack cookies to the build commands for IA32 modules
    built with VS2019 and VS2022. It also adds stack cookies to GCC5
    AARCH64 builds.
    
    - [x] Impacts functionality?
      - **Functionality** - Does the change ultimately impact how firmware functions?
      - Examples: Add a new library, publish a new PPI, update an algorithm, ...
    - [ ] Impacts security?
      - **Security** - Does the change have a direct security impact on an application,
        flow, or firmware?
      - Examples: Crypto algorithm change, buffer overflow fix, parameter
        validation improvement, ...
    - [x] Breaking change?
      - **Breaking change** - Will anyone consuming this change experience a break
        in build or boot behavior?
      - Examples: Add a new library class, move a module to a different repo, call
        a function in a new library class in a pre-existing module, ...
    - [ ] Includes tests?
      - **Tests** - Does the change include any explicit test code?
      - Examples: Unit tests, integration tests, robot tests, ...
    - [ ] Includes documentation?
      - **Documentation** - Does the change contain explicit documentation additions
        outside direct code modifications (and comments)?
      - Examples: Update readme file, add feature readme file, link to documentation
        on an a separate Web page, ...
    
    How This Was Tested
    
    Tested by on Q35 GCC and MSVC builds and an SBSA GCC build by
    purposefully overflowing the stack.
    
    Integration Instructions
    
    Platforms will need to update to ensure that all modules have a
    StackCheckLib instanced linked. The instances are:
    
    StackCheckLibNull: Used to provide the cookie definitions but not
                       actually check the stack.
    StackCheckLibBuildInit: Used to provide the cookie definitions where
                            the stack cookie value is initialized at
                            build time.
    StackCheckLibRuntimeInit: Used to provide the cookie definitions where
                                the stack cookie value is initialized at
                                runtime.
    TaylorBeebe committed Feb 28, 2024
    Configuration menu
    Copy the full SHA
    c0fe779 View commit details
    Browse the repository at this point in the history