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

Exclude ARM Binaries from BA2025 analysis #650

Merged
merged 8 commits into from
Jun 13, 2022

Conversation

marmegh
Copy link
Contributor

@marmegh marmegh commented Jun 1, 2022

Addressing issue #627 by:

  • Exclude ARM binaries from BA2025 analysis
  • Added ARM not applicable test case (.exe and .pdb files)
  • Extended test functionality to confirm correct skip reason is present. This allows confirmation for the current BA2025 test cases and can be used to add granularity to existing/future test cases.

{
reasonForNotAnalyzing = MetadataConditions.ImageIsArmBinary;
return notApplicable;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the only logic update for this change. Specifically, excluding ARM binaries from BA2025 analysis in a similar fashion as ARM64 binaries.

Copy link
Member

Choose a reason for hiding this comment

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

Nice code comment! Absolutely the info I was looking for. :)

@@ -10,6 +10,7 @@ public static class MetadataConditions
public static readonly string ImageIsNotExe = SdkResources.MetadataCondition_ImageIsNotExe;
public static readonly string ImageIsNotMachO = SdkResources.MetadataCondition_ImageIsNotMachO;
public static readonly string CouldNotLoadPdb = SdkResources.MetadataCondition_CouldNotLoadPdb;
public static readonly string ImageIsArmBinary = SdkResources.MetadataCondition_ImageIsArmBinary;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

public static readonly string ImageIsArmBinary = SdkResources.MetadataCondition_ImageIsArmBinary;

Add a MetadataConditions entry for ARMBinaries. This is separate as changing the previous user facing string could confuse customers by changing details in the results.

AnalysisApplicability expectedApplicability,
string ruleName,
string expectedReasonForNotAnalyzing)
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created method for shared code.

@@ -460,6 +498,17 @@ private HashSet<string> GetTestFilesMatchingConditions(HashSet<string> metadataC
result.Add(Path.Combine(testFilesDirectory, "DotnetNative_x86_VS2019_UniversalApp.exe"));
}

if (metadataConditions.Contains(MetadataConditions.ImageIsArmBinary))
{
result.Add(Path.Combine(testFilesDirectory, "ARM_CETShadowStack_NotApplicable.exe"));
Copy link
Collaborator

@shaopeng-gh shaopeng-gh Jun 10, 2022

Choose a reason for hiding this comment

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

ARM_CETShadowStack_NotApplicable.exe

nice, how did you generate this file, please add the step in md file
\docs\FunctionalTestBuildScripts.md #Closed

string expectedReasonForNotAnalyzing)
{

var context = new BinaryAnalyzerContext();
Copy link
Collaborator

@shaopeng-gh shaopeng-gh Jun 10, 2022

Choose a reason for hiding this comment

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

first line empty can be removed. #Closed

Copy link
Collaborator

@shaopeng-gh shaopeng-gh left a comment

Choose a reason for hiding this comment

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

🕐

@@ -7,6 +7,7 @@
* Bump ELFSharp from 2.14.0 to 2.15.0. [#631](https://github.com/microsoft/binskim/pull/631)
* FEATURE: Enable BinSkim for MacOS. [#576](https://github.com/microsoft/binskim/pull/576)
* Bump Sarif.Sdk by updating submodule from [4e9f606 to fc9a9df](https://github.com/microsoft/sarif-sdk/compare/4e9f606bb0e88428866e253352cdc70dc68f98cb...fc9a9dfb865096b5aaa9fa3651854670940f7459). [#638](https://github.com/microsoft/binskim/pull/638)
* BUGFIX: Fix `BA2025.EnableShadowStack` warning for ARM Binaries which cannot use `/CETCOMPAT`. [#650](https://github.com/microsoft/binskim/pull/650)
Copy link
Collaborator

@shaopeng-gh shaopeng-gh Jun 10, 2022

Choose a reason for hiding this comment

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

BUGFIX: Fix BA2025.EnableShadowStack warning for ARM Binaries which cannot use /CETCOMPAT.

I see a sample below:
FALSE POSITIVE FIX: Skip PDB-driven analysis for the generated .NET core native bootstrap exe (which is not user-controllable code).
See if we think this template is better for this change
FALSE POSITIVE FIX: Skip rule xxx for xxx (reason) #Closed

@@ -47,3 +47,40 @@ Also create two user functions `userfn_use_safebuffers_1()` and `userfn_use_safe
A simple `Windows Kernel Mode Driver` program, created with `Visual Studio 2019` that generates a .exe and associated .pdb file. Code to reproduce:
Use `NTSTATUS GsDriverEntry(_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath)` as entry point and do not decorated with `__declspec(safebuffers)`.
No user functions decorated with `__declspec(safebuffers)`.

## ARM64_CETShadowStack_NotApplicable.exe
Copy link
Collaborator

Choose a reason for hiding this comment

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

add a empty line consistent with others

Copy link
Collaborator

@shaopeng-gh shaopeng-gh left a comment

Choose a reason for hiding this comment

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

:shipit:

this.VerifyApplicability(
HashSet<string> notApplicableArm64 = new HashSet<string>() { MetadataConditions.ImageIsArm64BitBinary };

this.VerifyApplicabililtyByConditionsOnly(
Copy link
Member

Choose a reason for hiding this comment

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

VerifyApplicabililtyByConditionsOnly

You are getting solidly into our test infrastructure if you understand this pattern. nice work. :) I'm sure Shaopeng may have been helpful in gaining 'the knowledge'.

Copy link
Member

@michaelcfanning michaelcfanning left a comment

Choose a reason for hiding this comment

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

:shipit:

@marmegh marmegh merged commit dcafdde into main Jun 13, 2022
@marmegh marmegh deleted the users/marmegh/excludeArmBinariesForBA2025 branch June 13, 2022 19:15
@marmegh marmegh mentioned this pull request Jun 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants