Compiler Hardening logo

Compiler Hardening

Organization
RedHatProductSecurity
compiler-hardening

Apply compiler hardening flags and sanitizers to C/C++ builds. Use when reviewing build configurations, CI pipelines, or Makefiles/CMakeLists for native code projects.

Overview

PublisherRedHatProductSecurity
Repositoryprodsec-skills
Skill namecompiler-hardening
Stars
56
Forks
9
Bundled files
Instructions only
LicenseApache-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by RedHatProductSecurity on GitHub. Read the source before you install it.

Installation

Install the Compiler Hardening AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/RedHatProductSecurity/prodsec-skills/tree/main/module/skills/compiler-hardening
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/RedHatProductSecurity/prodsec-skills.git /tmp/prodsec-skills
mkdir -p .claude/skills
cp -r /tmp/prodsec-skills/module/skills/compiler-hardening .claude/skills/compiler-hardening
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Compiler Hardening in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Compiler Hardening on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Compiler Hardening is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Compiler Hardening

Common Vulnerability Classes

CategoryExamples
Memory errorsBuffer overflow, use-after-free (UAF), buffer over-read
Dependency attacksLibrary hijacking, library sideloading, supply chain compromise

Hardening Flags

When building with Fedora/RPM toolchains, hardened flags are often applied automatically. For other build systems, explicitly add hardening options.

The OpenSSF Compiler Hardening Guide is the canonical reference. Key flags include:

FlagPurpose
-fstack-protector-strongStack buffer overflow detection
-D_FORTIFY_SOURCE=2Runtime buffer overflow checks for standard library functions
-fPIE / -piePosition-independent executable for ASLR
-Wl,-z,relro,-z,nowFull RELRO -- makes GOT read-only after relocation
-Wl,-z,noexecstackNon-executable stack
-fno-strict-overflowPrevent undefined behavior optimizations on signed overflow

GCC 14+ provides -fhardened as a convenience flag that enables a recommended set of hardening options.

The Fedora Security Features Matrix provides an overview of security features available in a modern Linux system.

Sanitizers

Sanitizers add runtime instrumentation that catches errors during testing that would otherwise go undetected. They increase binary size and resource consumption but provide significantly better error detection and debug information than traditional tooling.

SanitizerFlagDetects
AddressSanitizer-fsanitize=addressMemory access violations (buffer overflow, UAF, stack overflow)
ThreadSanitizer-fsanitize=threadData races and race conditions
LeakSanitizer-fsanitize=leakMemory leaks
UndefinedBehaviorSanitizer-fsanitize=undefinedUndefined behavior at runtime

Run sanitizer-enabled builds in CI. ASan and UBSan are the highest-value sanitizers for most projects.

Security Considerations

W^X and JIT Compilers

JIT compilers inherently conflict with W^X (write XOR execute) because they must generate executable code at runtime. W^X protections apply at page granularity and cannot be meaningfully enforced on JIT buffers. Other memory areas (thread stacks, heap) should still have NX (non-executable) protection.

Sandboxing

User-space sandboxing alone is insufficient; prefer OS and process-level isolation (namespaces, seccomp, SELinux) as the primary security boundary. User-space sandboxes can serve as defense-in-depth but have historically introduced their own security bugs and should not be the sole barrier, especially post-Spectre.

Dynamic Linking

Dynamic linking relies on well-known search paths and filesystem permissions. The compilation environment may differ from the runtime environment with different (but compatible) library versions. Review and mitigate:

  • Library search path attacks (LD_LIBRARY_PATH, RPATH manipulation)
  • Symbol interposition risks
  • Version mismatches between build and runtime

Implementation Checklist

  • Hardening flags are applied in the build system (or -fhardened with GCC 14+)
  • -fstack-protector-strong is enabled
  • _FORTIFY_SOURCE=2 is defined
  • PIE is enabled (-fPIE -pie)
  • Full RELRO is enabled (-Wl,-z,relro,-z,now)
  • At least ASan and UBSan run in CI
  • Sanitizer failures block the CI pipeline
  • JIT compiler memory regions are isolated from general-purpose allocations
  • User-space sandboxing is not the sole security boundary; OS-level isolation is the primary layer
  • Library search paths are reviewed for safety

References

Frequently asked questions

What does the Compiler Hardening AI skill do?

Apply compiler hardening flags and sanitizers to C/C++ builds. Use when reviewing build configurations, CI pipelines, or Makefiles/CMakeLists for native code projects.

Why use Compiler Hardening on TypingMind?

Because you install it once and use it with any model. Compiler Hardening is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Compiler Hardening in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/RedHatProductSecurity/prodsec-skills/tree/main/module/skills/compiler-hardening. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Compiler Hardening?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Compiler Hardening?

As many as you like. As long as a model supports skills, you can use Compiler Hardening with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Compiler Hardening AI skill free?

Yes. It is published on GitHub by RedHatProductSecurity under the Apache-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇