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

Workaround certain anti-malware programs #37

Merged
merged 1 commit into from
May 13, 2022

Conversation

chirpnot
Copy link

@chirpnot chirpnot commented Jan 4, 2022

This might break things, but it turns out several Windows libraries like to be loaded at 0x180000000.

This causes a problem, because msys-2.0.dll loads at 0x180040000 and expects 0x180000000-0x180040000 to be available.
A problem arises when Antiviruses (or other DLL hooking mechanisms) load a dll whose preferred load address is 0x180000000 and fits in size before 0x180010000:

  1. msys-2.0.dll loads and fills 0x180010000-0x180040000 assuming no shared console structure is going to be needed.
  2. Another dll loads and fills 0x180000000-0x18000xxxx
  3. msys-2.0.dll tries to load 0x180000000-0x180010000 but it's not available. It falls back to another address, but down the line something else fails.

This bug triggers when using subshells (e.g.: git clone --recursive).

(I guess msys should be able to work around the address conflict, but the code is failing in some way and I'm having a hard time figuring it out, so...)

This addresses git-for-windows/git#3539

@dscho dscho force-pushed the main branch 3 times, most recently from 8d105b8 to d3507f2 Compare January 5, 2022 14:40
@dscho
Copy link
Member

dscho commented Jan 5, 2022

A couple of comments:

  • Could I ask you to use your real name and email address in your user.name and user.email configuration and then call git commit --amend --reset-author -s, then force-push?
  • How did you come up with 0x210347000?
  • I cherry-picked two fixes to allow the CI build to start.
  • Since the build now succeeds, and since I have no way to reproduce the original issue, could I ask you to test the build artifact?

@chirpnot
Copy link
Author

  • Could I ask you to use your real name and email address in your user.name and user.email configuration and then call git commit --amend --reset-author -s, then force-push?

Will do.

  • How did you come up with 0x210347000?

You mean 0x210040000? Random choice. If you have any scientific-like idea to get a new base address, my ears are wide open.

The only semi-feasible approach imho would be to take a windows install and query all the base addresses of all the exe/dll's and then choose something that's not there, but still...

  • I cherry-picked two fixes to allow the CI build to start.
  • Since the build now succeeds, and since I have no way to reproduce the original issue, could I ask you to test the build artifact?

I confirm it seems to work. I managed to get .\strace.exe .\cmd.exe => .\lsattr.exe to crash in git-for-windows but not in your CI build.

.\strace.exe .\ldd.exe crashes both, but I think it's unrelated. Could you please try it on your machine?

@chirpnot
Copy link
Author

chirpnot commented Mar 10, 2022

Ok, even rebasing msys-2.0.dll in the broken version, strace lsattr still crashes :/ so I guess it's unrelated. Will do some more differential testing.

EDIT: since the CI build doesn't come with many complex programs, I simply dropped msys-2.0.dll from the CI into git-for-windows and cloned a repo with --recursive. No crash. This increases my gut feeling that the strace thing is another problem.

This might break things, but it turns out several Windows libraries like
to be loaded at 0x180000000.

This causes a problem, because `msys-2.0.dll` loads at `0x180040000` and
expects `0x180000000-0x180040000` to be available. A problem arises when
Antiviruses (or other DLL hooking mechanisms) load a DLL whose preferred
load address is `0x180000000` and fits in size before `0x180010000`:

1. `msys-2.0.dll` loads and fills `0x180010000-0x180040000` assuming no
   shared console structure is going to be needed.

2. Another DLL loads and fills `0x180000000-0x18000xxxx`

3. `msys-2.0.dll` tries to load `0x180000000-0x180010000` but it's not
   available. It falls back to another address, but down the line
   something else fails.

This bug triggers when using subshells (e.g.: `git clone --recursive`).

The MSYS2 runtime should be able to work around the address conflict,
but the code is failing in some way or other...

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Mikael Larsson <95430516+chirpnot@users.noreply.github.com>
@dscho
Copy link
Member

dscho commented May 10, 2022

@orgads since you have access to Windows 7, could I trouble you to test this?

@orgads
Copy link

orgads commented May 10, 2022

Sure, I'll test it tomorrow.

@orgads
Copy link

orgads commented May 11, 2022

Works for me on Win7. No crash on git clone --recursive (I didn't try to reproduce with the official version).

@dscho dscho changed the title Workaround for #3539 Workaround certain anti-malware programs May 13, 2022
@dscho dscho merged commit d92c46b into git-for-windows:main May 13, 2022
dscho added a commit to dscho/msys2-runtime that referenced this pull request May 13, 2022
Workaround certain anti-malware programs

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@dscho
Copy link
Member

dscho commented May 13, 2022

Thank you @chirpnot!

dscho added a commit to git-for-windows/build-extra that referenced this pull request May 14, 2022
Many anti-malware products seem to have problems with our MSYS2
runtime, leading to problems running e.g. `git subtree`. We [added a
workaround](git-for-windows/msys2-runtime#37)
that hopefully helps in most of these scenarios.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Copy link

@Stmgme Stmgme left a comment

Choose a reason for hiding this comment

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

K

dscho added a commit to dscho/msys2-runtime that referenced this pull request Sep 5, 2022
Workaround certain anti-malware programs

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho added a commit to dscho/msys2-runtime that referenced this pull request May 12, 2023
Workaround certain anti-malware programs

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho added a commit to dscho/msys2-runtime that referenced this pull request Jun 16, 2023
Workaround certain anti-malware programs

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho added a commit to dscho/msys2-runtime that referenced this pull request Jun 19, 2023
Workaround certain anti-malware programs

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho added a commit to dscho/msys2-runtime that referenced this pull request Sep 6, 2023
Workaround certain anti-malware programs

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho added a commit to dscho/msys2-runtime that referenced this pull request Nov 29, 2023
Workaround certain anti-malware programs

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho added a commit to dscho/msys2-runtime that referenced this pull request Aug 30, 2024
Workaround certain anti-malware programs

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho added a commit to dscho/msys2-runtime that referenced this pull request Sep 5, 2024
Workaround certain anti-malware programs

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho added a commit to dscho/msys2-runtime that referenced this pull request Sep 18, 2024
Workaround certain anti-malware programs

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
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.

4 participants