hcsshim: The hcsshim on Windows 10 1903 always fails to build Docker image

After I have updated my machine from Windows 10 1809 to 1903, I always experiencing errors when doing image build.

The error always shows that the problem is caused by hcsshim:

F:\dockerimages>docker build --rm -f Dockerfile -t dev/testimage .
Sending build context to Docker daemon  330.6MB
Step 1/11 : FROM mcr.microsoft.com/dotnet/framework/runtime:4.7.2-windowsservercore-ltsc2016
 ---> d529d6d68c79
Step 2/11 : SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
 ---> Running in 3a7c4fcc808c
hcsshim::PrepareLayer failed in Win32: Incorrect function. (0x1) path=C:\ProgramData\Docker\windowsfilter\3a7c4fcc808c8794606111ba9fb67342560aa5bfa40a888d564e52871fbd8840

image

This issue is always reproducible on Windows 10 1903, and on previous version of Windows 10 it doesn’t happen. I have tested on other machines that have WIndows 10 1803 and Windows 10 1809, and using the same Docker for Windows Desktop (2.0.0.3), the image build is always finished/done successfully.

This has been reported before on Docker for Windows: docker/for-win#3884 especially this comment and the next comments after: https://github.com/docker/for-win/issues/3884#issuecomment-498939672

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 12
  • Comments: 47 (5 by maintainers)

Most upvoted comments

After debugging for a few hours I stumbled upon a call to AttachVirtualDisk which is used to mount the images.
Some undocumented flags were passed to the function during one of the calls and I found out that removing the undocumented flags resolves the issue for some reason.
I have created a simple program to patch the running dockerd daemon in memory and remove the undocumented flags. It has been tested on 10.0.18362.175, however, I cannot guarantee that it would work on other builds.
USE AT YOUR OWN RISK

Looks like regression is also tracked in https://github.com/microsoft/hcsshim/issues/708, and a workaround has been merged in https://github.com/microsoft/hcsshim/pull/718

Work is in progress to get that workaround merged into the Docker codebase (see https://github.com/moby/moby/pull/40128)

After debugging for a few hours I stumbled upon a call to AttachVirtualDisk which is used to mount the images. Some undocumented flags were passed to the function during one of the calls and I found out that removing the undocumented flags resolves the issue for some reason. I have created a simple program to patch the running dockerd daemon in memory and remove the undocumented flags. It has been tested on 10.0.18362.175, however, I cannot guarantee that it would work on other builds. USE AT YOUR OWN RISK

how to use it?

First you should compile the program. I created a c++ console application on Visual Studio 2015 but generally any c compiler that targets Win32 should work.
After that, you can use an elevated powershell to run the following command:
\path\to\generated\executable.exe p (ps dockerd).id. You can also revert the changes by running \path\to\generated\executable.exe u (ps dockerd).id.

0x57 is well documented in: https://github.com/microsoft/hcsshim/issues/708 has been patched in hcsshim with a work around already for windows 1903. The work around being merged into docker can be found in terms of progress at: https://github.com/moby/moby/pull/40128 once merged in a new release will have to be made. 0x01 error has also already been patched and merged: https://github.com/moby/moby/pull/39679 you will just need a binary newer than that for that fix (or wait for the backport release https://github.com/docker/engine/pull/314 binaries).

This is not an hcsshim issue. I’m closing this. See https://github.com/docker/for-win/issues/3884#issuecomment-510973455

@jhowardmsft @jterry75 @jstarks

Is this repo active? This issue has been 6 days without any reply. Please confirm…

Hi, The patch works fine for Windows 11 with a new version of vmcompute.dll. Obviously you need to correctly find the new edx position. Be careful the check_integrity_bytes changed too.

I don’t know why that doesn’t work with the 376 value and that must be replace by another one but great job

Running on Windows Version 10.0.18362, patch provided by @giniyat202 worked perfectly. Thanks a lot ! Also thanks to @imphasing for putting in a VS solution

@bplasmeijer I don’t use Box or DropBox but I found that uninstalling OneDrive (which comes preinstalled with Windows 10) fixed the 0x57 error when using docker-compose.

@giniyat202 thanks for your help, I managed to figure it out now. It turns out that the check_integrity_bytes and check_integrity_offset for 18363.449 is identical to 18362.418. Just to expand on your instructions for those of us who are not x64dbg experts,

2 - If vmcompute.dll doesn’t appear in the modules list then keep pressing F9 until vmcompute.dll appears.

5 - In the References tab, double click on each reference to jump to the call in the CPU tab, then scroll up 3 lines and check if the preceding 3 instructions are “xor r8d,r8d”, “mov edx,376” and “mov rcx,qword ptr ss:[rbp-58]”

@giniyat202 Any insight on how I can migrate this patch to work for 18362.449? I’ve noticed that you updated the check_integrity_bytes in your previous update.

I use x64dbg for that. The exact steps required to update this patch are as follows:

  1. Load vmcompute.dll inside x64dbg. You can find this file under %systemroot%\system32.
  2. Select Symbols tab, right click vmcompute.dll module and select Download symbols for this module . You also need to make note of Base address next to the module.
  3. Type ?MountVhd in the search bar below the right pane then double click the only result
  4. Hit Ctrl-r
  5. At this point it is required to find the call that passes 376 on edx, In my case it was the 4th reference.
  6. Assuming nothing has changed in the function body, check_integrity_offset should be calculated as by subtracting Base obtained in step 2 from the address of xor r8d, r8d instruction and check_integrity_bytes are the bytes starting from this instruction all the way to the ja instuction slightly below the call

I will update my code once I receive the update (Windows update didn’t offer it for some reason)

After debugging for a few hours I stumbled upon a call to AttachVirtualDisk which is used to mount the images. Some undocumented flags were passed to the function during one of the calls and I found out that removing the undocumented flags resolves the issue for some reason. I have created a simple program to patch the running dockerd daemon in memory and remove the undocumented flags. It has been tested on 10.0.18362.175, however, I cannot guarantee that it would work on other builds. USE AT YOUR OWN RISK

how to use it?

First you should compile the program. I created a c++ console application on Visual Studio 2015 but generally any c compiler that targets Win32 should work. After that, you can use an elevated powershell to run the following command: \path\to\generated\executable.exe p (ps dockerd).id. You can also revert the changes by running \path\to\generated\executable.exe u (ps dockerd).id.

@giniyat202 It cant work again. it works follow your workaround a few days ago. but after i do some reset docker desktop, update windows. i found i cant work. and i can`t track what different.

should i compile it again after windows update ? now it is windows 10 1903(18362.418)

@lyling I have just updated it for version 10.0.18362.175 and it should work as usual once you recompile it

Oh, I see a comment in https://github.com/moby/moby/issues/36831#issuecomment-498612392

If you have a different storage location configured, could you try if things work if you disable Windows defender, or exclude the location? https://support.microsoft.com/en-us/help/4028485/windows-10-add-an-exclusion-to-windows-security