Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: Fix incorrect analysis for non-Microsoft compiler on BA2006.BuildWithSecureTools #545

Merged
merged 11 commits into from
Jan 10, 2022
59 changes: 39 additions & 20 deletions src/BinSkim.Rules/PERules/BA2006.BuildWithSecureTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ public override void AnalyzePortableExecutableAndPdb(BinaryAnalyzerContext conte
Symbol om = omView.Value;
ObjectModuleDetails omDetails = om.GetObjectModuleDetails();

if (omDetails.WellKnownCompiler != WellKnownCompilers.MicrosoftC &&
omDetails.WellKnownCompiler != WellKnownCompilers.MicrosoftCxx)
{
// TODO: MikeFan (1/6/2022)
// We need to take a step back and comprehensively review our compiler/language support.
// https://github.com/Microsoft/binskim/issues/114
continue;
}

switch (omDetails.Language)
{
case Language.LINK:
Expand All @@ -132,33 +141,43 @@ public override void AnalyzePortableExecutableAndPdb(BinaryAnalyzerContext conte
break;
}

//case Language.MASM:
//{
// minCompilerVersion =
// context.Policy.GetProperty(MinimumToolVersions)[nameof(Language.MASM)];
// break;
//}

//case Language.CVTRES:
//{
// minCompilerVersion =
// context.Policy.GetProperty(MinimumToolVersions)[nameof(Language.CVTRES)];
// break;
//}

//case Language.CSharp:
//{
// minCompilerVersion =
// context.Policy.GetProperty(MinimumToolVersions)[nameof(Language.CSharp)];
// break;
//}
/*
TODO: MikeFan (1/6/2022)
We need to take a step back and comprehensively review our compiler/language support.
https://github.com/Microsoft/binskim/issues/114

case Language.MASM:
{
minCompilerVersion =
context.Policy.GetProperty(MinimumToolVersions)[nameof(Language.MASM)];
break;
}

case Language.CVTRES:
{
minCompilerVersion =
context.Policy.GetProperty(MinimumToolVersions)[nameof(Language.CVTRES)];
break;
}

case Language.CSharp:
{
minCompilerVersion =
context.Policy.GetProperty(MinimumToolVersions)[nameof(Language.CSharp)];
break;
}

Language data is not always included if it is only compiled with SymTagCompiland without SymTagCompilandDetails
https://docs.microsoft.com/en-us/visualstudio/debugger/debug-interface-access/compilanddetails?view=vs-2022
Compiland information is split between symbols with a SymTagCompiland tag (low detail)
and a SymTagCompilandDetails tag (high detail).
case Language.Unknown:
{
minCompilerVersion =
context.Policy.GetProperty(MinimumToolVersions)[nameof(Language.Unknown)];
break;
}
*/

default:
{
Expand Down
1 change: 1 addition & 0 deletions src/ReleaseHistory.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

* BUGFIX: Fix incorrect analysis for non-Microsoft compiler on BA2006.BuildWithSecureTools [545](https://github.com/microsoft/binskim/pull/545)
* BUGFIX: Fix `JsonSerializationException` that occurs when saving SARIF v1 with telemetry enabled. [#535](https://github.com/microsoft/binskim/pull/535)
* BUGFIX: Fix `NullReferenceException` when `--Hashes` and telemetry rules are enabled. [#531](https://github.com/microsoft/binskim/pull/531)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,13 +428,13 @@
{
"ruleId": "BA2006",
"ruleIndex": 17,
"level": "error",
"kind": "pass",
"level": "none",
"message": {
"id": "Error",
"id": "Pass",
"arguments": [
"clangcl.pe.cpp.codeview.exe",
"",
"clang version 13.0.0 : cxx : 13000.0.0.0 : [directly linked] (hello-d24821.obj)\r\n"
"Microsoft (R) Optimizing Compiler:C:19.26.28900.8, Microsoft (R) Optimizing Compiler:C:19.29.30034.2, Microsoft (R) Optimizing Compiler:Cxx:19.26.28900.8, Microsoft (R) Optimizing Compiler:Cxx:19.29.30034.2"
]
},
"locations": [
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.