Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/BinSkim.Rules/DwarfRules/BA3003.EnableStackProtector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,27 @@ public override void Analyze(BinaryAnalyzerContext context)
}
validGccCommandLineInfos.Add(info);
}

// If the binary's only DWARF producer is rustc, the GCC
// stack-protector heuristic does not apply: rustc enables stack
// protection via LLVM and does not emit __stack_chk_fail /
// __stack_chk_guard symbols, so the symbol-table fallback below
// would false-flag every Rust binary as missing stack-protector.
// Report NotApplicable in that case.
if (validGccCommandLineInfos.Count == 0
&& elf.Compilers != null
&& elf.Compilers.Any(c => c.Compiler == ElfCompilerType.Rust)
&& !elf.Compilers.Any(c => c.Compiler == ElfCompilerType.GCC))
{
context.Logger.Log(this,
RuleUtilities.BuildResult(ResultKind.NotApplicable, context, null,
nameof(RuleResources.NotApplicable_InvalidMetadata),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applicability should be solved in canAnalyze methods not in the analyze methods

context.CurrentTarget.Uri.GetFileName(),
this.Name,
"binary was produced by rustc; the GCC stack-protector heuristic does not apply"));
return;
}

if (validGccCommandLineInfos.Count > 0)
{
// Check using DWARF info
Expand Down
Loading