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

Hash reporting. #929

Merged
merged 4 commits into from
Jun 27, 2023
Merged

Hash reporting. #929

merged 4 commits into from
Jun 27, 2023

Conversation

michaelcfanning
Copy link
Member

This change breaks apart all evidence of no hash data in modules as a specific, separate warning. This condition may indicate a problem that can't be resolved by the user/compiler in its current form.

A second change is that we emit the hash algorithm in use in the reporting and separate module lists by algorithm, e.g. 👍

Working on a small unit test to confirm the addition of an arbitrary comment in the module output helper.

D:\src\binskim\bld\bin\x64_Release\net6.0\BaselineTestData\Uwp_x86_VS2017_Cpp_DirectX11.exe: warning BA2004: 'Uwp_x86_VS2017_Cpp_DirectX11.exe' is a native binary that links one or more static libraries that include object files which were hashed using an insecure checksum algorithm. Insecure checksum algorithms are subject to collision attacks and its use can compromise supply chain integrity. Pass '/ZH:SHA_256' on the cl.exe command-line to enable secure source code hashing. The following modules are out of policy:
Microsoft (R) Macro Assembler : masm : 14.15.26706.0 : MSVCRT.lib [MD5] (atlssup.obj,ftol3.obj,lldiv.obj,sehprolg4.obj,ulldiv.obj,ullrem.obj)
Microsoft (R) Optimizing Compiler : cxx : 19.15.26706.0 : vccorlib.lib [MD5] (activation.obj,climain.obj,compiler.obj,init.obj,tmmta.obj,winmain.obj)

D:\src\binskim\bld\bin\x64_Release\net6.0\BaselineTestData\Uwp_x86_VS2017_Cpp_DirectX11.exe: error BA2004: 'Uwp_x86_VS2017_Cpp_DirectX11.exe' is a native binary that directly compiles and links one or more object files which were hashed using an insecure checksum algorithm. Insecure checksum algorithms are subject to collision attacks and its use can compromise supply chain integrity. Pass '/ZH:SHA_256' on the cl.exe command-line to enable secure source code hashing. The following modules are out of policy:
Microsoft (R) Optimizing Compiler : cxx : 19.16.27034.0 : [directly linked] [MD5] (App.obj,DeviceResources.obj,pch.obj,Sample3DSceneRenderer.obj,SampleFpsTextRenderer.obj,Uwp_x86_VS2017_Cpp_DirectX11_exeMain.obj)

@@ -33,8 +33,8 @@ function Build-Baselines($sourceExtension)

# Actually run the tool
Remove-Item $outputTemp -ErrorAction SilentlyContinue
Write-Host "$utility analyze "$input" --output "$outputTemp" --kind "Fail;Pass" --level "Error;Warning;Note" --insert Hashes --remove NondeterministicProperties --config default --quiet true"
& $utility analyze "$input" --output "$outputTemp" --kind "Fail;Pass" --level "Error;Warning;Note" --insert Hashes --remove NondeterministicProperties --config default --quiet true
Write-Host "$utility analyze "$input" --output "$outputTemp" --kind "Fail`;Pass" --level "Error`;Warning`;Note" --insert Hashes --remove NondeterministicProperties --config default --quiet true"
Copy link
Member Author

Choose a reason for hiding this comment

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

Write

Our update command wasn't working for me without escaping the semicolons in these lines.

"id": "Warning_NativeWithInsecureStaticLibraryCompilands",
"arguments": [
"MixedMode_x64_VS2015_Default.exe",
"Microsoft (R) Optimizing Compiler : cxx : 19.0.24215.1 : [directly linked] [No hash value present] (.NETFramework,Version=v4.5.2.AssemblyAttributes.obj)\r\n"
Copy link
Member Author

Choose a reason for hiding this comment

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

AssemblyAttributes

Well! How do you like this? This is exactly the condition reported by a customer. It may be we could/should simply exclude missing hash data for this obj, which looks autogenerated for mixed mode binaries.

Copy link
Collaborator

@shaopeng-gh shaopeng-gh Jun 26, 2023

Choose a reason for hiding this comment

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

looks nice.
for a same file we had:
error for direct;
warning;
question is if for the new one added "no hash"
do we want to use note, or same warning

]
},
{
"ruleId": "BA2004",
Copy link
Member Author

Choose a reason for hiding this comment

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

ruleId

this looks like a bug, I can't see why this new result has popped up, will debug.

Copy link
Collaborator

Choose a reason for hiding this comment

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

saw this file was checked in by me so I get the branch and debugged,
found the small issue and fixed and pushed, please see my last commit if correct.

Copy link
Member Author

Choose a reason for hiding this comment

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

YES. Thanks for fixing this! I really appreciate it.

@@ -55,7 +55,28 @@
"id": "Warning_NativeWithInsecureStaticLibraryCompilands",
"arguments": [
"Uwp_ARM64_VS2019_Cpp.dll",
"Microsoft (R) ARM Macro Assembler : masm : 14.22.26504.99 : MSVCRT.lib (arm64secgs.obj)\r\nMicrosoft (R) Optimizing Compiler : c : 19.22.26504.99 : MSVCRT.lib (cpu_disp.obj,dyn_tls_init.obj,gs_cookie.obj,gs_report.obj,gs_support.obj,guard_support.obj,loadcfg.obj,ucrt_detection.obj)\r\nMicrosoft (R) Optimizing Compiler : cxx : 19.22.26504.99 : MSVCRT.lib (app_appinit.obj,argv_mode.obj,default_local_stdio_options.obj,dll_dllmain.obj,initializers.obj,tncleanup.obj,ucrt_stubs.obj,utility.obj,utility_app.obj)\r\n"
"Microsoft (R) ARM Macro Assembler : masm : 14.22.26504.99 : MSVCRT.lib [SHA1] (arm64secgs.obj)\r\n\r\n"
Copy link
Member Author

Choose a reason for hiding this comment

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

SHA1

Same issue, it appears, some data is getting duplicated.

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:

@michaelcfanning michaelcfanning merged commit 5a58c1f into main Jun 27, 2023
@michaelcfanning michaelcfanning deleted the hash-reporting branch June 27, 2023 14:29
@shaopeng-gh shaopeng-gh mentioned this pull request Aug 2, 2023
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.

2 participants