Skip to main content
AI
  • Get started with AI

    • Red Hat AI

      Accelerate the development and deployment of enterprise AI solutions.

    • AI learning hub

      Explore learning materials and tools, organized by task.

    • AI interactive demos

      Click through scenarios with Red Hat AI, including training LLMs and more.

    • AI/ML learning paths

      Expand your Red Hat OpenShift AI knowledge using these learning resources.

    • AI quickstarts

      Focused AI use cases designed for fast deployment on Red Hat AI platforms.

    • No-cost AI training

      Foundational Red Hat AI training.

  • Featured resources

    • Red Hat OpenShift AI
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

Red Hat AI Factory with NVIDIA

Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.

Learn
  • Self-guided

    • Documentation

      Find answers, get step-by-step guidance, and learn how to use Red Hat products.

    • Learning paths

      Explore curated walkthroughs for common development tasks.

    • Guided learning

      Receive custom learning paths powered by our AI assistant.

    • See all learning
  • Hands-on

    • Developer Sandbox

      Spin up Red Hat's products and technologies without setup or configuration.

    • Interactive labs

      Learn by doing in these hands-on, browser-based experiences.

    • Interactive demos

      Click through product features in these guided tours.

  • Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics
  • Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
Build
  • Get started

    • Red Hat build of Podman Desktop

      A downloadable, local development hub to experiment with our products and builds.

    • Developer Sandbox

      Spin up Red Hat's products and technologies without setup or configuration.

  • Download products

    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products
  • Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset
  • References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
Community
  • Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions
  • Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github
  • Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

Join the Red Hat Developer program

Download Red Hat products and project builds, access support documentation, learning content, and more.

ConsoleDocsSupport Search
New For you

Recommended

We'll recommend resources you may like as you browse. Try these suggestions for now.

  • Product downloads
  • Cheat sheets
  • Red Hat Developer learning portal
  • Developer blog
  • E-books
  • Developer Sandbox
Log in

Get more with a Red Hat Developer account

  • Product downloads
  • Console access
  • Event registration
  • Training & trials
Explore more account benefitsLog in or register

A subscription may be required for some services.

Contact us

Stack clash mitigation in GCC, Part 3

May 22, 2020
Jeff Law
Related topics:
SecurityC, C#, C++Linux

    In previous posts, Stack Clash Mitigation in GCC — Background and Stack Clash mitigation in GCC: Why -fstack-check is not the answer, I hopefully showed the basics of how stack clash attacks are structured and why GCC's existing -fstack-check mechanism is insufficient for protection.

    So, what should we do? Clearly we want something similar to -fstack-check, but without the fundamental problems. Enter a new option: -fstack-clash-protection.

    The key principles for code generation to prevent a stack clash attack are:

    • No single allocation can be greater than a page. The compiler must translate large requests into a series of page- or smaller-sized requests.
    • As pages are allocated, emit instructions to probe them. (Let's call these explicit probes.)
    • A series of sub-page allocations without intervening probes can not allocate more than a page in total.

    A naive implementation around these principles could be highly inefficient, but this option provides the basis for building a secure, high-performance implementation.

    Implicit probes to improve performance

    A stack access that occurs naturally in the code is an implicit probe. An implicit probe implies no additional cost; therefore, using an implicit probe rather than an explicit probe is advantageous. For example, an implicit probe might occur due to the behavior of the target architecture, the requirements of the application binary interface (ABI), or by analysis of existing memory references in the program.

    For example, the call instruction on many processors pushes the return address onto the stack. Thus, the call instruction would fault if the stack was in the stack guard. This is an implicit probe at *sp. Some application binary interfaces require that *sp always contains a back-chain pointer (the pointer to the next outer stack frame). Thus, every stack allocation is required to atomically update *sp. Again, this is an implicit probe of *sp.

    We can also analyze the generated code. For example, on one target the caller allocates space for the callee to save registers. Thus, in the callee, a register save to *(sp + 48) is an implicit probe at *(sp + 48). On other targets, the callee often pushes pairs of registers onto the stack at function entry. Those pushes are implicit probes at *sp.

    It turns out that taking advantage of the implicit probes noted above can dramatically decrease the amount of explicit probing. If we look at glibc as an example on x86 and PPC we see that less than 2% of the functions in glibc require explicit probing in their prologues. For example, if a function allocates less than a page of stack space on these architectures, then no explicit probe is necessary.

    Current status

    Red Hat's engineers implemented -fstack-clash-protection for all Red Hat Enterprise Linux (RHEL) targets starting with RHEL 7.5. RHEL 7.5 enables -fstack-clash-protection for glibc only. Starting with RHEL 8, the entire distribution is compiled with -fstack-clash-protection and annobin/annocheck are used to verify that the distribution was compiled with the proper flags.

    Fedora 27 and later enable -fstack-clash-protection by default for all packages using the standard default compilation options (note that there is no -fstack-clash-protection support for 32-bit ARM targets).

    GCC 8 includes -fstack-clash-protection support for the Intel, IBM Power, IBM Z series, and ARM's aarch64 targets.

    LLVM 11 will include stack clash protections for Intel 64 and AMD64 written by Serge Guelton.

    Testing

    Red Hat's engineers have written a variety of tests to verify the analysis of static and dynamic stack utilization. Red Hat's engineers have also written regression tests for all bugs reported against -fstack-clash-protection since its introduction to GCC. These tests run as a part of the standard regression testing process for GCC. Most of the tests are portable enough to be usable on other targets if one was to implement stack clash mitigation on a currently unsupported target.

    Red Hat's engineers also implemented a scanner that can examine relocatable objects, executables, and dynamic shared objects. The scanner looks for violations of the key principles listed above within an instruction window and notifies the developer of suspicious code. Red Hat has used the scanner to scan key libraries and objects (with hand verification of all the sequences reported as potentially vulnerable by the scanner). This practice proved particularly useful in verifying that Fedora 27 was consistently using -fstack-clash-protection and invalidating improvements to the aarch64 implementation made by ARM's engineers.

    Last updated: May 19, 2020

    Recent Posts

    • A day in the life of an NVIDIA H100 on Red Hat OpenShift 5

    • Migrate BuildConfigs to builds for Red Hat OpenShift with one plug-in install

    • Run Red Hat Enterprise Linux CoreOS on NVIDIA BlueField DPUs

    • Agent harness engineering: Separating model capabilities from enforcement

    • What's new for developers in Red Hat Enterprise Linux 10.3 and 9.9

    Red Hat Developers logo

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    Red Hat Developer

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility
    Ask AI