Current OCaml situation w.r.t Windows antiviruses

I have a custom enterprise antivirus software on Windows (Symantec Endpoint Protection) that just decided to quarantine my ocaml.exe (apparently a somewhat old 4.x version, in case that’s relevant).

I remember reading somewhere about the OCaml Windows team proactively trying to avoid such issues, but I don’t remember if it was related to Windows Defender only, and if that is still being done.

Some colleagues suggested that I submit the quarantined ocaml.exe to https://symsubmit.symantec.com as a false positive.

I’d like to know if:

  1. Is this already being done by someone?
  2. Do you know if that’s not a waste of time? For instance, if the executable is freshly compiled and with a unique hash, that’s going to be less helpful for the antivirus database.

It could also be that my computer’s signature database is out-of-date, and this does not happen for others.

Someone else also got a false-positive on the latest release of opam (ocaml/opam#7197). Maybe that’s related? This also uses 4.x (4.14.4)

It could be. Nim has been dealing with this issue in both their toolchain and binaries generated with it, since it got slightly popular among malware writers, and years later they keep getting falsely flagged by AV vendors. They even automated a VirusTotal scan during CI to catch false positives sooner.

However, there’s not much else one can do. Programs using unpopular toolchains are less represented in the datasets used to train classifiers, so one either submits them to improve their datasets or tweaks the codegen until it stops getting falsely flagged.

The irony of this is that malware writers could just as well do that… In fact, they’d be even more more motivated to do so to tweak their true positive into a false negative.

In general, the combination of:

  • source-based builds
  • non-relocatable OCaml (ie. hardcoded paths in executables)

means varying hashes; submitting your ocaml.exe will be fairly useless.

On the other hand, you can use relocatable OCaml (generally available in 5.5+) and fetch prebuilt OCaml distributions. I believe dune pkg does both, but unfortunately I don’t think it is available for Windows. But Announcing the first release of Alice, a radical OCaml build system should work on Windows and I suspect it has stable hashes even if I haven’t used it.

I also mentioned another solution last month at Dk builds with relocatable OCaml. Since that was addressed to package maintainers, here is how you would get OCaml binaries with stable hashes:

Click here if trying inside Windows Sandbox (recommended!)
#   Mitigate https://github.com/diskuv/dk/issues/106
curl.exe -L -o "vc_redist.x64.exe" "https://aka.ms/vs/17/release/vc_redist.x64.exe"
Start-Process -FilePath ".\\vc_redist.x64.exe" -ArgumentList "/install", "/passive", "/norestart" -Wait

#   Mitigate: Program 'ocaml.exe' failed to run: An Application Control policy has blocked this file
reg add "HKLM\System\CurrentControlSet\Control\CI\Policy" /v VerifiedAndReputablePolicyState /t REG_DWORD /d 0 /f
CiTool.exe -r
mkdir ~\testme; cd ~\testme
irm https://diskuv.com/dk/vendor.ps1 | iex
Set-Content -Path dk.u -Value "## workspace" -Encoding UTF8
./dk1 add github-l2 dkpkg/CommonsLang_OCaml

# get OCaml 4.14.3
./dk1 get-object CommonsLang_OCaml.DkML@4.14.3001 -s Release.target_abi -d ocaml4dir
.\ocaml4dir\bin\ocaml.exe

# get OCaml 5.5.0
./dk1 get-object CommonsLang_OCaml.Base@5.5.0 -s Release.target_abi -d ocaml5dir
.\ocaml5dir\bin\ocaml.exe

# get Dune
./dk1 get-object CommonsLang_OCaml.Dune@3.23.2 -s Release.target_abi -d dunedir
.\dunedir\bin\dune.exe --help

I haven’t had time to fix my OpamVenv tool which creates a binary-backed opam switch for normal development (ex. dune build --watch on your packages). More importantly, few people seem interested in binary builds. +1 to OpamVenv@1.1.22 broken · Issue #107 · diskuv/dk · GitHub if anyone is interested.

Have you considered signing the OPAM build? A file downloaded from the internet, without a code signature is likely to be treated as more suspicious than one that has a code signature that chains back to one of the CAs that Windows trusts for code signing.

(I don’t know about other anti-viruses, but ClamAV, which I worked on, will validate the code signing chain. It also has a revocation database, so signed malware can still be detected. More information here: ClamAV® blog: Authenticode Certificate Chain Verification Microsoft Authenticode Signature Verification - ClamAV Documentation )

There are open source tools for code signing, although you’ll need to get a certificate.

There is a Linux Foundation project with an apparently free to use CA Sigstore , but I don’t know whether it’ll chain back to (or is cross-signed by) a CA trusted by Windows (according to the above blogpost there are only 4 roots: 2 Microsoft, 1 Thawte, and 1 Verisign).

There is also a service by Microsoft in Azure, I don’t know the costs associated with it, but there are details in this blogpost: Code Signing for Windows as an Individual Developer | JD's Devlog

Although this approach won’t help for the ocaml.exe built by opam, that is built locally, and will have different contents each time, so can’t be signed ahead of time.

That can be useful if the result is clean. However if any of scanners finds a malware (in an otherwise clean sample, so a false positive), then virustotal will automatically submit the sample as malicious to the other AV vendors that didn’t catch it, and fairly soon more and more will start detecting it.

If most of the submissions are clean then maybe it’ll help, although if most of them turn up as malicious that’ll make it more likely that one AV vendor will begin recognizing (an otherwise non-malicious, but probably unique to your language) a pattern. So I wouldn’t fully automate VirusTotal submissions, or if you do, keep a close eye on the results.

I don’t know what other AV vendors would do, but if this happens on ClamAV, it might help there.

I think I added long ago some version of OCaml to its “known-clean” set that is used to test every new signature/pattern update before it is being pushed to users.

Even if your ocaml.exe is not identical, having it in the “false positive / known clean set” can help avoid matches from new heuristic signatures, and new generic pattern signatures (for ClamAV the publication process would automatically reject signatures that match the clean set).

Although you’ll first need the AV vendor(s) to trust that your FP submission is genuine, and if it is an executable you’ve built yourself in a non-reproducible way, and is not publicly downloadable from a reputable source then that’ll be difficult.

We have our own signing infrastructure (gpg, see our github release notes). I didn’t know how code signing work on Windows but reading your description i’m not exactly excited about it. I’m not sure it’s worth the hassle

On Windows (and I think Mac OS) code signing is built into the OS, so although GPG signatures can be useful for end users wanting to verify the code, the OS will still consider these unsigned, and not trust them.

More on the official website: Code signing options for Windows app developers - Windows apps | Microsoft Learn , in particular unsigned (from the OS’s point of view) binaries get:

Strong SmartScreen block; enterprises may block entirely

That page lists one option for open source projects: SignPath Software Integrity Platform - The free Code Signing & Software Integrity solution for Open Source Projects , which links to https://signpath.org/. They say Vim uses it, and that is confirmed by GitHub - vim/vim-win32-installer: Vim Win32 Installer · GitHub . They provide free code signing services using their own certificate for open source projects (they are not a CA), but you’ll have to meet their requirements, which includes using one of their Trusted Build Systems | SignPath . Github and Appveyor are on the list, so it might be possible to setup a workflow that meets that. Although the requirements can change:

We reserve the right to enforce the implementation of additional best practices in the future, such as the generation of SBOM files, as the industry adoption progresses

and they can

pause or terminate the subscription without prior notice

Still, it might be a solution in the short term.

I’m not a Windows developer or user, so I’d suggest to gather feedback on how important this would be from those who use it. Meanwhile maybe we could move the above list of “how to do code signing on Windows for an open source project for free” into an issue on opam, so that you’d have it easily available should you decide that you need it in the future.

sure, i opened the ticket as ocaml/opam#7217