Skip to content

Commit 1c01727

Browse files
authored
Update Control Flow Guard documentation
1 parent 8c9489e commit 1c01727

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

docs/build/reference/guard-enable-control-flow-guard.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
---
22
description: "Learn more about: /guard (Enable Control Flow Guard)"
33
title: "/guard (Enable Control Flow Guard)"
4-
ms.date: 09/19/2022
4+
ms.date: 2/24/2025
55
f1_keywords: ["/guard", "VC.Project.VCCLCompilerTool.ControlFlowGuard"]
6-
ms.assetid: be495323-f59f-4cf3-a6b6-8ee69e6a19dd
76
---
87
# `/guard` (Enable Control Flow Guard)
98

@@ -16,17 +15,21 @@ Enable compiler generation of Control Flow Guard security checks.
1615
1716
## Remarks
1817

19-
The **`/guard:cf`** option causes the compiler to analyze control flow for indirect call targets at compile time, and then to insert code to verify the targets at runtime. By default, **`/guard:cf`** is off and must be explicitly enabled. To explicitly disable this option, use **`/guard:cf-`**.
18+
The **`/guard:cf`** option causes the compiler to analyze control flow for indirect call targets at compile time, and inserts code at runtime to verify the targets. By default, **`/guard:cf`** is off and must be explicitly enabled. To explicitly disable this option, use **`/guard:cf-`**.
2019

2120
**Visual Studio 2017 and later**: This option adds guards for **`switch`** statements that generate jump tables.
2221

2322
When the **`/guard:cf`** Control Flow Guard (CFG) option is specified, the compiler and linker insert extra runtime security checks to detect attempts to compromise your code. During compiling and linking, all indirect calls in your code are analyzed to find every location that the code can reach when it runs correctly. This information is stored in extra structures in the headers of your binaries. The compiler also injects a check before every indirect call in your code that ensures the target is one of the verified locations. If the check fails at runtime on a CFG-aware operating system, the operating system closes the program.
2423

2524
A common attack on software takes advantage of bugs in handling extreme or unexpected inputs. Carefully crafted input to the application may overwrite a location that contains a pointer to executable code. This technique can be used to redirect control flow to code controlled by the attacker. The CFG runtime checks don't fix the data corruption bugs in your executable. They instead make it more difficult for an attacker to use them to execute arbitrary code. CFG is a mitigation tool that prevents calls to locations other than function entry points in your code. It's similar to how Data Execution Prevention (DEP), [/GS](gs-buffer-security-check.md) stack checks, and [`/DYNAMICBASE`](dynamicbase-use-address-space-layout-randomization.md) and [/HIGHENTROPYVA](highentropyva-support-64-bit-aslr.md) address space layout randomization (ASLR) lower the chances that your code becomes an exploit vector.
2625

27-
To use CFG exploit mitigation technique the **`/guard:cf`** option must be passed to the compiler and correspondigly the option **`/GUARD:CF`** must be passed to the linker. To disable CFG exploit mitigation technique the **`/guard:cf-`** option must be passed to the compiler and correspondingly the option **`/GUARD:NO`** must be passed to the linker.
26+
To use the CFG exploit mitigation technique, pass **`/guard:cf`** to the compiler and **`/GUARD:CF`** to the linker.
2827

29-
If your binary is built by using a single `cl` command, the compiler passes the option to the linker. If you compile and link separately, the option must be set on both the compiler and linker commands. The /DYNAMICBASE linker option is also required. To verify that your binary has CFG data, use the `dumpbin /headers /loadconfig` command. CFG-enabled binaries have `Guard` in the list of EXE or DLL characteristics, and Guard Flags include `CF Instrumented` and `FID table present`.
28+
To disable the CFG exploit mitigation technique, pass **`/guard:cf-`** to the compiler **`/GUARD:NO`** to the linker.
29+
30+
If you build using a single `cl` command, the compiler passes the option to the linker. If you compile and link separately, set the option for both the compiler and linker commands. The `/DYNAMICBASE` linker option is also required.
31+
32+
To verify that your binary has CFG data, use the `dumpbin /headers /loadconfig` command. CFG-enabled binaries have `Guard` in the list of EXE or DLL characteristics, and Guard Flags include `CF Instrumented` and `FID table present`.
3033

3134
The **`/guard:cf`** option is incompatible with [`/ZI`](z7-zi-zi-debug-information-format.md) (Edit and Continue debug information) or [`/clr`](clr-common-language-runtime-compilation.md) (Common Language Runtime Compilation).
3235

@@ -35,11 +38,8 @@ Code compiled by using **`/guard:cf`** can be linked to libraries and object fil
3538
### To set this compiler option in the Visual Studio development environment
3639

3740
1. Open the **Property Pages** dialog box for the project. For more information, see [Set compiler and build properties](../working-with-project-properties.md).
38-
3941
1. Select the **Configuration Properties** > **C/C++** > **Code Generation** property page.
40-
4142
1. Select the **Control Flow Guard** property.
42-
4343
1. In the dropdown control, choose **Yes** to enable Control Flow Guard, or **No** to disable it.
4444

4545
## See also

0 commit comments

Comments
 (0)