Skip to content

Commit b32301b

Browse files
Copilotanupriya13
andcommitted
Implement SDL /GS crash detection and analysis tooling
Co-authored-by: anupriya13 <54227869+anupriya13@users.noreply.github.com>
1 parent cf26005 commit b32301b

2 files changed

Lines changed: 256 additions & 3 deletions

File tree

docs/sdl-gs-crash-monitoring.md

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
# SDL Policy: /GS Stack Buffer Overrun Crash Monitoring
2+
3+
## Overview
4+
5+
This document describes the process for monitoring, analyzing, and fixing /GS (stack buffer overrun) crashes in React Native Windows, in accordance with Microsoft's Security Development Lifecycle (SDL) policy requirements.
6+
7+
## What is a /GS Crash?
8+
9+
A /GS crash occurs when the `/GS` compiler flag detects stack buffer corruption. The `/GS` flag adds security checks (stack cookies) to detect buffer overruns. When a mismatch is detected, the application is terminated with exception code **0xc0000409** (`STATUS_STACK_BUFFER_OVERRUN`).
10+
11+
## SDL Policy Requirements
12+
13+
Per Microsoft SDL policy:
14+
15+
1. **All high-confidence /GS crashes must be analyzed and fixed when appropriate**
16+
2. **A monitoring plan must be in place to analyze future /GS failures within 60 days** of being reported to Watson
17+
3. **Teams must investigate all crashes that are not false-positives** (`GS_FALSE_POSITIVE_*`)
18+
4. **Fix identified stack buffer overruns** to prevent potential security vulnerabilities
19+
20+
## /GS Crash Classifications
21+
22+
Watson automatically classifies /GS crashes using the `!gs` debugger extension:
23+
24+
- **GS_POSITIVE**: High-confidence stack buffer overrun. **MUST be fixed immediately.**
25+
- **GS_SUSPECT**: Suspected stack buffer overrun. Should be investigated.
26+
- **GS_FALSE_POSITIVE**: False positive due to process corruption. Can be safely ignored.
27+
28+
## Monitoring Process
29+
30+
### 1. Finding /GS Crashes in Watson
31+
32+
1. Go to [Watson](https://aka.ms/watson)
33+
2. Select "Buffer Overruns" under "Enter ANY of the following to see matching BUCKET(s)"
34+
3. Enter the application name (szAppName) or DLL name (szModName)
35+
4. Click "Show Crash/Hang Buckets"
36+
5. Filter for crashes with exception code `0xc0000409`
37+
38+
### 2. Analyzing /GS Crashes
39+
40+
Use the provided `Analyze-Crash.ps1` script to analyze crash dumps:
41+
42+
```powershell
43+
# Analyze a specific dump file
44+
.\vnext\Scripts\Analyze-Crash.ps1 -DumpFilePath "path\to\crash.dmp"
45+
46+
# Or configure automatic dump collection for an exe
47+
.\vnext\Scripts\Analyze-Crash.ps1 -ExeName "YourApp"
48+
```
49+
50+
The script will:
51+
- Detect if the crash is a /GS crash (0xc0000409)
52+
- Run the `!gs` debugger extension for detailed analysis
53+
- Classify the crash (GS_POSITIVE, GS_SUSPECT, or GS_FALSE_POSITIVE)
54+
- Provide actionable guidance based on the classification
55+
56+
### 3. Triage and Response Timeline
57+
58+
| Classification | Priority | Action Required | Timeline |
59+
|---------------|----------|----------------|----------|
60+
| GS_POSITIVE | Critical | Analyze, fix, and test | Within 60 days of Watson report |
61+
| GS_SUSPECT | High | Investigate and determine if real | Within 90 days |
62+
| GS_FALSE_POSITIVE | Low | No action required | N/A |
63+
64+
### 4. Fixing /GS Crashes
65+
66+
When a real stack buffer overrun is identified:
67+
68+
1. **Review the crash analysis**
69+
- Check the `!gs` output in the analysis log
70+
- Identify the function with the buffer overrun
71+
- Locate the source of the overrun (strcpy, sprintf, etc.)
72+
73+
2. **Implement the fix**
74+
- Replace unsafe functions with safe alternatives:
75+
- `strcpy``strcpy_s`
76+
- `strcat``strcat_s`
77+
- `sprintf``sprintf_s` or `snprintf`
78+
- `gets``fgets` or `gets_s`
79+
- Add bounds checking to array operations
80+
- Validate input sizes before copying
81+
82+
3. **Test the fix**
83+
- Reproduce the original crash scenario
84+
- Verify the crash no longer occurs
85+
- Run existing tests to ensure no regressions
86+
87+
4. **Document the fix**
88+
- Include CVE information if applicable
89+
- Document the root cause and fix in commit message
90+
- Update security documentation if needed
91+
92+
## Common Vulnerable Patterns
93+
94+
Watch out for these common patterns that can lead to stack buffer overruns:
95+
96+
```cpp
97+
// UNSAFE: No bounds checking
98+
char buffer[100];
99+
strcpy(buffer, userInput); // ❌
100+
101+
// SAFE: Use safe alternative with size
102+
char buffer[100];
103+
strcpy_s(buffer, sizeof(buffer), userInput); // ✅
104+
105+
// UNSAFE: sprintf without size limit
106+
char buffer[50];
107+
sprintf(buffer, "Value: %s", userInput); // ❌
108+
109+
// SAFE: Use snprintf with size limit
110+
char buffer[50];
111+
snprintf(buffer, sizeof(buffer), "Value: %s", userInput); // ✅
112+
113+
// UNSAFE: Array access without bounds check
114+
void ProcessArray(int* data, int count) {
115+
int localArray[10];
116+
for (int i = 0; i < count; i++) { // ❌ count could be > 10
117+
localArray[i] = data[i];
118+
}
119+
}
120+
121+
// SAFE: Add bounds checking
122+
void ProcessArray(int* data, int count) {
123+
int localArray[10];
124+
int safeCount = std::min(count, 10);
125+
for (int i = 0; i < safeCount; i++) { // ✅
126+
localArray[i] = data[i];
127+
}
128+
}
129+
```
130+
131+
## Reporting Security Issues
132+
133+
If a /GS crash is determined to be a security vulnerability:
134+
135+
1. **Do NOT create a public GitHub issue**
136+
2. Report to Microsoft Security Response Center (MSRC):
137+
- Online: https://msrc.microsoft.com/create-report
138+
- Email: secure@microsoft.com
139+
3. Include:
140+
- Type of issue (stack buffer overrun)
141+
- Full paths of affected source files
142+
- Steps to reproduce
143+
- Crash dump and analysis (if safe to share)
144+
- Potential security impact
145+
146+
See [.github/security.md](../.github/security.md) for full security reporting guidelines.
147+
148+
## Tools and Resources
149+
150+
- **Analyze-Crash.ps1**: Automated crash analysis script with /GS detection
151+
- **Watson**: https://aka.ms/watson - Microsoft crash reporting system
152+
- **!gs debugger extension**: Built into Windows debuggers, analyzes /GS crashes
153+
- **!analyze -v**: Verbose crash analysis including !gs output
154+
155+
## Regular Monitoring Schedule
156+
157+
To comply with SDL requirements:
158+
159+
1. **Weekly**: Check Watson for new /GS crashes
160+
2. **Monthly**: Review and triage all open /GS issues
161+
3. **Quarterly**: Audit codebase for unsafe string/buffer operations
162+
4. **Before Release**: Ensure no open GS_POSITIVE crashes remain
163+
164+
## Questions?
165+
166+
For questions about /GS crashes or SDL policy:
167+
- Internal: Contact your team's security champion
168+
- External: File an issue in the repository (for non-security questions)
169+
- Security issues: Follow the reporting process in [.github/security.md](../.github/security.md)

vnext/Scripts/Analyze-Crash.ps1

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,28 @@ if ($ExeName) {
6767
}
6868

6969
Write-Host Analyzing crash dump $DumpFilePath
70-
& $cdb -z "$DumpFilePath" -c ".lines; !analyze -v; .ecxr; kP; q" > $logfile
70+
71+
# First, do a quick check to see if this is a /GS crash (STATUS_STACK_BUFFER_OVERRUN, 0xc0000409)
72+
$gsCheckLogfile = "$env:TEMP\gs_check.log"
73+
& $cdb -z "$DumpFilePath" -c ".lastevent; q" > $gsCheckLogfile 2>&1
74+
$isGSCrash = $false
75+
if (Test-Path $gsCheckLogfile) {
76+
$content = Get-Content $gsCheckLogfile -Raw
77+
if ($content -match "c0000409|STATUS_STACK_BUFFER_OVERRUN") {
78+
$isGSCrash = $true
79+
Write-Host -ForegroundColor Yellow "`n*** DETECTED /GS STACK BUFFER OVERRUN CRASH (0xc0000409) ***"
80+
Write-Host -ForegroundColor Yellow "This is a security-related crash that requires immediate attention.`n"
81+
}
82+
Remove-Item $gsCheckLogfile -ErrorAction SilentlyContinue
83+
}
84+
85+
# Run analysis with !gs extension for /GS crashes
86+
if ($isGSCrash) {
87+
Write-Host "Running detailed /GS crash analysis..."
88+
& $cdb -z "$DumpFilePath" -c ".lines; !analyze -v; !gs; .ecxr; kP; q" > $logfile
89+
} else {
90+
& $cdb -z "$DumpFilePath" -c ".lines; !analyze -v; .ecxr; kP; q" > $logfile
91+
}
7192

7293
if ($LASTEXITCODE -ne 0) {
7394
Write-Output "Failed to analyze the crash dump. Exiting"
@@ -82,26 +103,89 @@ if (!(Test-Path $logfile)) {
82103
exit 4
83104
}
84105

106+
# Check for /GS crash indicators in the analysis
107+
$analysisContent = Get-Content $logfile -Raw
108+
$gsClassification = "Unknown"
109+
110+
if ($analysisContent -match "GS_POSITIVE") {
111+
$gsClassification = "GS_POSITIVE (High-confidence stack buffer overrun)"
112+
Write-Host -ForegroundColor Red "`n*** HIGH-CONFIDENCE /GS CRASH DETECTED ***"
113+
Write-Host -ForegroundColor Red "Problem Class: GS_POSITIVE"
114+
Write-Host -ForegroundColor Red "This is a confirmed stack buffer overrun that MUST be fixed immediately."
115+
Write-Host -ForegroundColor Red "Per SDL policy, this must be analyzed and fixed within 60 days.`n"
116+
} elseif ($analysisContent -match "GS_SUSPECT") {
117+
$gsClassification = "GS_SUSPECT (Suspected stack buffer overrun)"
118+
Write-Host -ForegroundColor Yellow "`n*** SUSPECTED /GS CRASH DETECTED ***"
119+
Write-Host -ForegroundColor Yellow "Problem Class: GS_SUSPECT"
120+
Write-Host -ForegroundColor Yellow "This is a suspected stack buffer overrun that should be investigated.`n"
121+
} elseif ($analysisContent -match "GS_FALSE_POSITIVE") {
122+
$gsClassification = "GS_FALSE_POSITIVE (Can be safely ignored)"
123+
Write-Host -ForegroundColor Green "`n/GS False Positive Detected"
124+
Write-Host -ForegroundColor Green "Problem Class: GS_FALSE_POSITIVE - This can be safely ignored.`n"
125+
} elseif ($isGSCrash) {
126+
Write-Host -ForegroundColor Yellow "`n/GS crash detected but classification not determined."
127+
Write-Host -ForegroundColor Yellow "Manual review of the crash dump is recommended.`n"
128+
}
129+
85130
Get-Content $logfile | & "${env:SystemRoot}\System32\clip.exe"
86131

87132
Write-Host "
88133
Written analysis to $PWD\$logfile
134+
/GS Classification: $gsClassification
89135
90136
The contents have been copied to the clipboard.
91137
If you wish to file a bug, please paste its contents in inside of a <details>...</details> tag.
92138
You may also upload the file $DumpFilePath and associated .pdb symbol files to your OneDrive or other cloud provider and share a link in the bug description.
93139
94140
"
95141

142+
if ($gsClassification -eq "GS_POSITIVE (High-confidence stack buffer overrun)") {
143+
Write-Host -ForegroundColor Red @"
144+
145+
===============================================================================
146+
SDL POLICY REQUIREMENT: HIGH-CONFIDENCE /GS CRASH
147+
===============================================================================
148+
Per Microsoft SDL policy, this crash MUST be:
149+
1. Analyzed and triaged immediately
150+
2. Fixed within 60 days of being reported to Watson
151+
3. Reported as a security vulnerability if exploitable
152+
153+
Action Items:
154+
- Review the !gs analysis output in $logfile
155+
- Identify the buffer overrun location and root cause
156+
- File a security bug if this is exploitable
157+
- Implement and test a fix
158+
159+
For more information, see: https://aka.ms/watson
160+
===============================================================================
161+
162+
"@
163+
}
164+
165+
96166
Write-Warning "Note: the contents of $logfile, crash dump, and symbol files, might contain personally identifiable information. Please carefully review these contents before sharing them."
97167

98168
start notepad.exe $logfile
99169

100170
function FileIssue {
101171
# We can't populate the !analyze output because the URL ends up being too long and GitHub rejects it. Following up internally but at least we can prepopulate the <details> tags etc.
102-
$title = [uri]::EscapeUriString("[Crash] ENTER TITLE HERE")
172+
173+
$issueTitle = "[Crash] ENTER TITLE HERE"
174+
$labels = "bug"
175+
176+
if ($gsClassification -eq "GS_POSITIVE (High-confidence stack buffer overrun)") {
177+
$issueTitle = "[Security] /GS High-Confidence Stack Buffer Overrun"
178+
$labels = "bug,security"
179+
} elseif ($gsClassification -eq "GS_SUSPECT (Suspected stack buffer overrun)") {
180+
$issueTitle = "[Security] /GS Suspected Stack Buffer Overrun"
181+
$labels = "bug,security"
182+
}
183+
184+
$title = [uri]::EscapeUriString($issueTitle)
103185
$body = [uri]::EscapeUriString("ENTER YOUR ISSUE DESCRIPTION HERE
104186
187+
/GS Classification: $gsClassification
188+
105189
<details>
106190
107191
``````
@@ -110,7 +194,7 @@ function FileIssue {
110194
</details>
111195
")
112196

113-
start "https://github.com/$Repo/issues/new?title=$title&body=$body&labels=bug"
197+
start "https://github.com/$Repo/issues/new?title=$title&body=$body&labels=$labels"
114198
}
115199

116200
FileIssue

0 commit comments

Comments
 (0)