Граф коммитов

115 Коммитов

Автор SHA1 Сообщение Дата
Toshihito Kikuchi 7545ed9378 Bug 1684532 - Detect injected dependent modules in NtMapViewOfSection. r=mhowell
This patch is to improve the way to detect an injected dependent module for
automatic DLL blocking (bug 1659438).

In the previous version, we created a list of dependent modules in the launcher
process and shared it with other processes via the shared section.  However, it
was not compatible with third-party applications who tamper the Import Table and
revert it in the injected module's DllMain (bug 1682834) because we parsed the
Import Table in the launcher process after it was reverted.

With this patch, we check the Import Table in `patched_NtMapViewOfSection`,
so we can see tampering before it's reverted.  More specifically, we create
a list of dependent modules in the browser process as below.

1. The launcher process creates a section object and initializes
   the kernel32.dll's functions in it.

2. The launcher process transfers a writable handle of the shared
   section to the browser process.

3. In the browser process, if an injected dependent module is being
   mapped by `NtMapViewOfSection`, we add its NT path to the shared
   section and block it with `REDIRECT_TO_NOOP_ENTRYPOINT`.

4. The `main` function of the browser process converts the writable
   handle of the shared section into a readonly handle.

5. The browser process transfers a readonly handle of the shared
   section to a sandbox process.

Since automatic DLL blocking may still cause a compat issue like bug 1682304,
we activate it only in Nightly for now.

Differential Revision: https://phabricator.services.mozilla.com/D101460
2021-01-13 15:13:18 +00:00
smolnar 0b57365558 Backed out changeset 48a0fcaf46b8 (bug 1684532) for causing gtest perma failure. CLOSED TREE 2021-01-13 11:49:37 +02:00
Toshihito Kikuchi b27dd298e9 Bug 1684532 - Detect injected dependent modules in NtMapViewOfSection. r=mhowell
This patch is to improve the way to detect an injected dependent module for
automatic DLL blocking (bug 1659438).

In the previous version, we created a list of dependent modules in the launcher
process and shared it with other processes via the shared section.  However, it
was not compatible with third-party applications who tamper the Import Table and
revert it in the injected module's DllMain (bug 1682834) because we parsed the
Import Table in the launcher process after it was reverted.

With this patch, we check the Import Table in `patched_NtMapViewOfSection`,
so we can see tampering before it's reverted.  More specifically, we create
a list of dependent modules in the browser process as below.

1. The launcher process creates a section object and initializes
   the kernel32.dll's functions in it.

2. The launcher process transfers a writable handle of the shared
   section to the browser process.

3. In the browser process, if an injected dependent module is being
   mapped by `NtMapViewOfSection`, we add its NT path to the shared
   section and block it with `REDIRECT_TO_NOOP_ENTRYPOINT`.

4. The `main` function of the browser process converts the writable
   handle of the shared section into a readonly handle.

5. The browser process transfers a readonly handle of the shared
   section to a sandbox process.

Since automatic DLL blocking may still cause a compat issue like bug 1682304,
we activate it only in Nightly for now.

Differential Revision: https://phabricator.services.mozilla.com/D101460
2021-01-13 08:38:16 +00:00
Masatoshi Kimura 05b71dcf6e Bug 1684110 - Stop using some 'A'-functions in mozglue/. r=mhowell
Depends on D100465

Differential Revision: https://phabricator.services.mozilla.com/D100466
2020-12-26 00:46:34 +00:00
Simon Giesecke 8fc9b0ee7c Bug 1677284 - Fix Windows AARch64 bustage. a=bustage-fix
CLOSED TREE

Differential Revision: https://phabricator.services.mozilla.com/D97884
2020-11-23 16:54:12 +00:00
Ricky Stewart 02a7b4ebdf Bug 1654103: Standardize on Black for Python code in `mozilla-central`.
Allow-list all Python code in tree for use with the black linter, and re-format all code in-tree accordingly.

To produce this patch I did all of the following:

1. Make changes to tools/lint/black.yml to remove include: stanza and update list of source extensions.

2. Run ./mach lint --linter black --fix

3. Make some ad-hoc manual updates to python/mozbuild/mozbuild/test/configure/test_configure.py -- it has some hard-coded line numbers that the reformat breaks.

4. Make some ad-hoc manual updates to `testing/marionette/client/setup.py`, `testing/marionette/harness/setup.py`, and `testing/firefox-ui/harness/setup.py`, which have hard-coded regexes that break after the reformat.

5. Add a set of exclusions to black.yml. These will be deleted in a follow-up bug (1672023).

# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D94045
2020-10-26 18:34:53 +00:00
Bogdan Tara da1098d4aa Backed out 10 changesets (bug 1654103, bug 1672023, bug 1518999) for PanZoomControllerTest.touchEventForResult gv-junit failures CLOSED TREE
Backed out changeset ff3fb0b4a512 (bug 1672023)
Backed out changeset e7834b600201 (bug 1654103)
Backed out changeset 807893ca8069 (bug 1518999)
Backed out changeset 13e6b92440e9 (bug 1518999)
Backed out changeset 8b2ac5a6c98a (bug 1518999)
Backed out changeset 575748295752 (bug 1518999)
Backed out changeset 65f07ce7b39b (bug 1518999)
Backed out changeset 4bb80556158d (bug 1518999)
Backed out changeset 8ac8461d7bd7 (bug 1518999)
Backed out changeset e8ba13ee17f5 (bug 1518999)
2020-10-24 03:36:18 +03:00
Ricky Stewart c0cea3b0fa Bug 1654103: Standardize on Black for Python code in `mozilla-central`. r=remote-protocol-reviewers,marionette-reviewers,webdriver-reviewers,perftest-reviewers,devtools-backward-compat-reviewers,jgilbert,preferences-reviewers,sylvestre,maja_zf,webcompat-reviewers,denschub,ntim,whimboo,sparky
Allow-list all Python code in tree for use with the black linter, and re-format all code in-tree accordingly.

To produce this patch I did all of the following:

1. Make changes to tools/lint/black.yml to remove include: stanza and update list of source extensions.

2. Run ./mach lint --linter black --fix

3. Make some ad-hoc manual updates to python/mozbuild/mozbuild/test/configure/test_configure.py -- it has some hard-coded line numbers that the reformat breaks.

4. Make some ad-hoc manual updates to `testing/marionette/client/setup.py`, `testing/marionette/harness/setup.py`, and `testing/firefox-ui/harness/setup.py`, which have hard-coded regexes that break after the reformat.

5. Add a set of exclusions to black.yml. These will be deleted in a follow-up bug (1672023).

# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D94045
2020-10-23 20:40:42 +00:00
sanketh 35cd8eb504 Bug 1655482 - Bump MinGW to fix the STATUS_HEAP_CORRUPTION define r=tjr
- Bump MinGW version
- Add patch to workaround MinGW's dwrite_3.h
- Remove MinGW workaround for STATUS_HEAP_CORRUPTION define
- Remove MinGW workaround in MMPolicies.h.

Differential Revision: https://phabricator.services.mozilla.com/D91157
2020-10-22 15:58:54 +00:00
Dorel Luca 1ff59cb7a3 Backed out changeset 7558c8821a07 (bug 1654103) for multiple failures. CLOSED TREE 2020-10-22 03:51:06 +03:00
Ricky Stewart 50762dacab Bug 1654103: Standardize on Black for Python code in `mozilla-central`. r=remote-protocol-reviewers,marionette-reviewers,webdriver-reviewers,perftest-reviewers,devtools-backward-compat-reviewers,jgilbert,preferences-reviewers,sylvestre,maja_zf,webcompat-reviewers,denschub,ntim,whimboo,sparky
Allow-list all Python code in tree for use with the black linter, and re-format all code in-tree accordingly.

To produce this patch I did all of the following:

1. Make changes to tools/lint/black.yml to remove include: stanza and update list of source extensions.

2. Run ./mach lint --linter black --fix

3. Make some ad-hoc manual updates to python/mozbuild/mozbuild/test/configure/test_configure.py -- it has some hard-coded line numbers that the reformat breaks.

4. Add a set of exclusions to black.yml. These will be deleted in a follow-up bug (1672023).

# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D94045
2020-10-21 21:27:27 +00:00
Toshihito Kikuchi e61c0c2555 Bug 1671314 - Expand the region to be scanned for a trampoline. r=mhowell
The latest launcher process ping showed one of the reasons why we failed to
detour `NtMapViewOfSection` is that `MMPolicyBase::FindRegion` failed to find
a free region.  Inspecting the function carefully, there were three problems.

Firstly, `FindRegion` did not fully scan the given range.  To randomize
the address of a free region we use, we start scanning from a random address
within the given range.  The problem is we scan only addresses bigger than
that random address, without scanning smaller addresses.  Probably this is
the reason why `FindRegion` fails.

Secondly, `FindRegion` may return an address not aligned with the allocation
granularity because `VirtualQueryEx` returns such an address.  If that happens,
the subsequent mapping API fails with the alignment error.

Lastly, when we randomize an address to start scanning from, we divide a random
number by `maxOffset`, but with that, we never start scanning from the last
region.  It does not affect the product's behavior, but to have fair randomization,
a divisor should be `maxOffset + 1`.

This patch fixes all of these three problems along with a new test program.

Differential Revision: https://phabricator.services.mozilla.com/D94110
2020-10-20 22:51:00 +00:00
Toshihito Kikuchi 8b206d0aad Bug 1588245 - More values to DetourResultCode. r=mhowell
This is the third attempt to investigate the launcher failure of our detour.
The previous commits d8315e4ed18d and 1b81ea85c43d added the assembly bytes
of a detour target and a special error code `DetourResultCode` to the launcher
failure ping.

In the latest telemetry data, however, the most common value of `hresult`
is still `ERROR_UNIDENTIFIED_ERROR`, meaning the previous commit missed to
set an error code in the common fallible codepath we wanted to know.
Besides `ERROR_UNIDENTIFIED_ERROR`, we're seeing `DETOUR_PATCHER_DO_RESERVE_ERROR`
in the telemetry, but having that code is not enough to pinpoint a falling
operation.

For further investigation, this patch adds ten more values to `DetourResultCode`.
`FUNCHOOKCROSSPROCESS_COPYSTUB_ERROR` is the last codepath we forgot to cover
in the previous commit.  The values of `MMPOLICY_RESERVE_*` are to investigate
`DETOUR_PATCHER_DO_RESERVE_ERROR` in the MMPolicy level.  In both cases, we add
the last Windows error code to `DetourError::mOrigBytes`.

Differential Revision: https://phabricator.services.mozilla.com/D92974
2020-10-12 18:25:47 +00:00
Andreea Pavel e921b46c56 Backed out changeset 0a114b5e07eb (bug 1588245) on suspicion of crashing Firefox on startup (bug 1670546 etc.) a=backout 2020-10-12 14:31:40 +03:00
Toshihito Kikuchi 481aa7905b Bug 1588245 - More values to DetourResultCode. r=mhowell
This is the third attempt to investigate the launcher failure of our detour.
The previous commits d8315e4ed18d and 1b81ea85c43d added the assembly bytes
of a detour target and a special error code `DetourResultCode` to the launcher
failure ping.

In the latest telemetry data, however, the most common value of `hresult`
is still `ERROR_UNIDENTIFIED_ERROR`, meaning the previous commit missed to
set an error code in the common fallible codepath we wanted to know.
Besides `ERROR_UNIDENTIFIED_ERROR`, we're seeing `DETOUR_PATCHER_DO_RESERVE_ERROR`
in the telemetry, but having that code is not enough to pinpoint a falling
operation.

For further investigation, this patch adds ten more values to `DetourResultCode`.
`FUNCHOOKCROSSPROCESS_COPYSTUB_ERROR` is the last codepath we forgot to cover
in the previous commit.  The values of `MMPOLICY_RESERVE_*` are to investigate
`DETOUR_PATCHER_DO_RESERVE_ERROR` in the MMPolicy level.  In both cases, we add
the last Windows error code to `DetourError::mOrigBytes`.

Differential Revision: https://phabricator.services.mozilla.com/D92974
2020-10-08 19:00:22 +00:00
David Parks c6ffb4b0a9 Bug 1668057: Allow DLL interceptor to patch 64-bit immediate MOVs r=tkikuchi
The latest Windows Insider Preview (version 20226.1000) changes the machine code for BaseThreadInitThunk to have a preamble like the following:

00007FFDBF244C40 48 83 EC 28          sub         rsp,28h
00007FFDBF244C44 85 C9                test        ecx,ecx
00007FFDBF244C46 75 25                jne         00007FFDBF244C6D
00007FFDBF244C48 49 BA 70 A2 DC 12 6A 97 99 B0 mov         r10,0B099976A12DCA270h

This patch adds "MOV r64, imm64" capability to the DLL interceptor so that we can hook this.

Differential Revision: https://phabricator.services.mozilla.com/D92146
2020-10-05 22:25:44 +00:00
Toshihito Kikuchi 7034355c29 Bug 1588245 - Introduce an extra errorcode inside WindowsDllInterceptor. r=mhowell
The previous commit d8315e4ed18d introduced a new telemetry field
in the launcher process ping to collect the assembly pattern of
a target function on detour failure, but most of the crash instances
do not have a value in the field.  This means the failure happens
before or after `CreateTrampoline`.

To narrow down the root cause, this patch puts a fine-grained error value
in the "hresult" field instead of the hardcoded ERROR_UNIDENTIFIED_ERROR.

This patch also adds `IsPageAccessible` check before fetching data from
a different process because fetching data from an invalid address hits
`MOZ_RELEASE_ASSERT` in `EnsureLimit`, resulting in crash without sending
the launcher process failure.

Differential Revision: https://phabricator.services.mozilla.com/D91881
2020-09-30 20:09:22 +00:00
Toshihito Kikuchi abfd030f16 Bug 1666571 - Part 2. Support CALL [disp32] for Avast. r=handyman
The last Avast Antivirus's hook function contains `CALL [disp32]` instruction.
Our detour needs to be able to handle that pattern.

Differential Revision: https://phabricator.services.mozilla.com/D91155
2020-09-25 23:18:02 +00:00
Toshihito Kikuchi 05e886ea80 Bug 1666571 - Part 1. Support more patterns of OpCode 0xFF. r=handyman
This patch optimizes our detour's code handling Opcode 0xFF, expanding
its coverage to INC and DEC reg64 as well as PUSH and CALL.
Testcases for these scenarios are of course included.

Differential Revision: https://phabricator.services.mozilla.com/D91154
2020-09-25 23:18:15 +00:00
Toshihito Kikuchi 7ff1c84dc1 Bug 1665734 - Fix -Wunused-lambda-capture warnings in non-Nightly build. r=mhowell
This patch bypasses `-Wunused-lambda-capture` warnings by using `Unused` as
Bug 1375386 did.  Having two definitions with `#ifdef` confuses clang-format.
Using `Unused` seems like the easiest approach.

Differential Revision: https://phabricator.services.mozilla.com/D90610
2020-09-18 16:47:41 +00:00
Toshihito Kikuchi 4c58dba463 Bug 1588245 - Collect the assembly pattern of a target function on detour failure. r=mhowell
Many instances of the launcher failure ping indicate hooking NtMapViewOfSection
or LdrLoadDll failed.  This is most likely caused by a third-party application
applying a hook onto the same target earlier than we do.

This patch is to add a new field "detour_orig_bytes" in the laucnher failure ping
to collect the first sixteen bytes of a detour target function.  With this,
we can know whether those detour failures were caused by a third-party hook or not,
and if yes, what was the actual binary pattern.

Differential Revision: https://phabricator.services.mozilla.com/D89836
2020-09-17 01:42:26 +00:00
Dorel Luca aadcb9bfbc Backed out changeset d5725a81ffd7 (bug 1588245) for Windows build bustages. CLOSED TREE 2020-09-17 00:56:25 +03:00
Toshihito Kikuchi b45fd9fde1 Bug 1588245 - Collect the assembly pattern of a target function on detour failure. r=mhowell
Many instances of the launcher failure ping indicate hooking NtMapViewOfSection
or LdrLoadDll failed.  This is most likely caused by a third-party application
applying a hook onto the same target earlier than we do.

This patch is to add a new field "detour_orig_bytes" in the laucnher failure ping
to collect the first sixteen bytes of a detour target function.  With this,
we can know whether those detour failures were caused by a third-party hook or not,
and if yes, what was the actual binary pattern.

Differential Revision: https://phabricator.services.mozilla.com/D89836
2020-09-16 20:12:08 +00:00
Toshihito Kikuchi 65642af4cd Bug 1659398 - Don't resolve redirecion of JMP for DuplicateHandle. r=handyman
In Win7 and later, some exported functions in kernel32.dll are just a stub
jumping to a function in kernelbase.dll.  After the fix for Bug 1642626,
our detour resolves such a stub in kernel32.dll and detours a corresponding function in
kernelbase.dll.  This new behavior caused a problem in Win8 when we detour
`DuplicateHandle` because our detour cannot handle the assembly pattern of
`KERNELBASE!DuplicateHandle`.

Win8's `KERNELBASE!DuplicateHandle` has jump instructions whose destination is
within the region where we move instructions to a trampoline.

In the example below, the address `000007f954ad271c` is a destination of the
`JMP` instructions, but when we detour `KERNELBASE!DuplicateHandle`, we move
the original instructions to a trampoline, and that address will point to
an invalid instruction, jumping to which address causes a crash.

A proposed fix is to detour `KERNEL32!DuplicateHandle` without resolving redirection,
that is the behavior before bug 1642626.

```
KERNEL32!DuplicateHandle:
000007f9`54cd2d5c ff2556b61100    jmp     qword ptr [KERNEL32!_imp_DuplicateHandle] --> KERNELBASE!DuplicateHandle
```

```
KERNELBASE!DuplicateHandle:
000007f9`54ad2710 4883ec48        sub     rsp,48h
000007f9`54ad2714 4c8bd1          mov     r10,rcx
000007f9`54ad2717 83faf4          cmp     edx,0FFFFFFF4h
000007f9`54ad271a 733b            jae     KERNELBASE!DuplicateHandle+0x43 (000007f9`54ad2757)
000007f9`54ad271c 8b842480000000  mov     eax,dword ptr [rsp+80h]
...
000007f9`54b8f0de 65488b042560000000 mov   rax,qword ptr gs:[60h]
000007f9`54b8f0e7 488b5020        mov     rdx,qword ptr [rax+20h]
000007f9`54b8f0eb 488b5220        mov     rdx,qword ptr [rdx+20h]
000007f9`54b8f0ef e92836f4ff      jmp     KERNELBASE!DuplicateHandle+0xc (000007f9`54ad271c)
000007f9`54b8f0f4 65488b042560000000 mov   rax,qword ptr gs:[60h]
000007f9`54b8f0fd 488b5020        mov     rdx,qword ptr [rax+20h]
000007f9`54b8f101 488b5228        mov     rdx,qword ptr [rdx+28h]
000007f9`54b8f105 e91236f4ff      jmp     KERNELBASE!DuplicateHandle+0xc (000007f9`54ad271c)
000007f9`54b8f10a 65488b042560000000 mov   rax,qword ptr gs:[60h]
000007f9`54b8f113 488b5020        mov     rdx,qword ptr [rax+20h]
000007f9`54b8f117 488b5230        mov     rdx,qword ptr [rdx+30h]
000007f9`54b8f11b e9fc35f4ff      jmp     KERNELBASE!DuplicateHandle+0xc (000007f9`54ad271c)
```

Differential Revision: https://phabricator.services.mozilla.com/D88136
2020-08-26 20:26:36 +00:00
Simon Giesecke 1e02318b49 Bug 1653335 - Replace MakeSpan uses by constructor calls. r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D83817
2020-08-07 07:49:47 +00:00
Toshihito Kikuchi ae04ca7814 Bug 1655680 - Support JAE rel32 in our detour. r=handyman
After the fix for bug 1642626, we need to detour `KERNELBASE!CloseHandle`
instead of K32's stub, which contains `JAE rel32`.

I also found a mistake in the fix for bug 1642626.  When we put a conditional
jump in a trampoline, we need to reverse a condition, but the JAE case mistakenly
filled JAE straight.  This patch corrects it to filling JB.

Differential Revision: https://phabricator.services.mozilla.com/D85477
2020-08-05 07:21:00 +00:00
Aaron Klotz 010f090320 Bug 1601792: Remove VMSharingPolicyShared's template parameters and use inline variables instead; r=handyman
Differential Revision: https://phabricator.services.mozilla.com/D83573
2020-07-15 17:43:30 +00:00
Toshihito Kikuchi b80c6d24b1 Bug 1642626 - Part3: Handle a detour pattern of multple jumps. r=handyman
AVG AntiVirus hooks ntdll!NtMapViewOfSection by planting two JMP instructions,
jumping to a trampoline area first, then jumping to aswhook.dll.

```
ntdll!NtMapViewOfSection:
00007ffa`6d77c560 e9d33cfebf      jmp     00007ffa`2d760238

00007ffa`2d760238 ff25f2ffffff    jmp     qword ptr [00007ffa`2d760230] --> 00007ffa`541e2ad0

aswhook+0x2ad0:
00007ffa`541e2ad0 4055            push    rbp
00007ffa`541e2ad2 53              push    rbx
00007ffa`541e2ad3 56              push    rsi
```

With this patch, our detour can detour on top of that pattern.  The first part is
to remove the MEM_IMAGE check from IsPageAccessible.  The second part is to introduce
a loop in ResolveRedirectedAddress to resolve a chain of jumps.

Differential Revision: https://phabricator.services.mozilla.com/D81582
2020-07-02 16:43:14 +00:00
Toshihito Kikuchi fd9eb542c9 Bug 1642626 - Part2: Handle JAE and Opcode83 on x64 without REX Prefix. r=handyman
Depends on D81580

Differential Revision: https://phabricator.services.mozilla.com/D81581
2020-07-02 16:43:01 +00:00
Toshihito Kikuchi 31a3cc0614 Bug 1642626 - Part1: Take out jump detection from ReadOnlyTargetFunction. r=handyman
This patch moves the logics of jump detection from ResolveRedirectedAddress to
ReadOnlyTargetFunction to simplify ReadOnlyTargetFunction.

Differential Revision: https://phabricator.services.mozilla.com/D81580
2020-07-02 16:42:54 +00:00
Toshihito Kikuchi c0c91e1726 Bug 1603974 - Part 5: Introduce WindowsDllEntryPointInterceptor. r=mhowell
This patch introduces a new DLL interceptor `WindowsDllEntryPointInterceptor`
which applies a hook to a target function without backing up the original
function code.

Depends on D68345

Differential Revision: https://phabricator.services.mozilla.com/D68346

--HG--
extra : moz-landing-system : lando
2020-04-08 14:27:02 +00:00
Toshihito Kikuchi b01c4ba875 Bug 1603974 - Part 4: Introduce MMPolicyInProcessEarlyStage. r=mhowell
This patch introduces a new policy `MMPolicyInProcessEarlyStage` which does
not consume any functions imported from kernel32.dll so that we can use it
in a process's early stage i.e. before IAT is resolved.

Depends on D68344

Differential Revision: https://phabricator.services.mozilla.com/D68345

--HG--
extra : moz-landing-system : lando
2020-04-08 14:27:02 +00:00
Toshihito Kikuchi 2337ab0265 Bug 1603974 - Part 3: Extract a patching operation from CreateTrampoline. r=mhowell
`WindowsDllDetourPatcher::CreateTrampoline` does not only create a trampoline
region but also applies a patch on an original function.  This patch extracts
the patching part as separate functions.

Differential Revision: https://phabricator.services.mozilla.com/D68344

--HG--
extra : moz-landing-system : lando
2020-04-08 14:27:02 +00:00
Toshihito Kikuchi 8bb38652d4 Bug 1603974 - Part 1: Implement nt::VirtualQuery consuming only ntdll.dll. r=mhowell
This patch introduces `nt::VirtualQuery` which consumes only ntdll's functions
to reduce dependency in `MMPolicy` on kernel32.dll.  With this, `MMPolicy` still
depends on kernel32.dll, that will be solved by a coming patch.

Differential Revision: https://phabricator.services.mozilla.com/D68342

--HG--
extra : moz-landing-system : lando
2020-04-08 14:27:01 +00:00
Daniel Varga 2617f15d0c Backed out 8 changesets (bug 1603974) for causing build bustage
CLOSED TREE

Backed out changeset ee3fb8271709 (bug 1603974)
Backed out changeset 28ef741f8f65 (bug 1603974)
Backed out changeset 631725404fb8 (bug 1603974)
Backed out changeset 484a45d16149 (bug 1603974)
Backed out changeset 5d4cd3237ec0 (bug 1603974)
Backed out changeset c2601b5bdd3e (bug 1603974)
Backed out changeset fe96d48d5b14 (bug 1603974)
Backed out changeset 9467dffe8d04 (bug 1603974)
2020-04-07 18:35:04 +03:00
Toshihito Kikuchi 9fe11cf59a Bug 1603974 - Part 5: Introduce WindowsDllEntryPointInterceptor. r=mhowell
This patch introduces a new DLL interceptor `WindowsDllEntryPointInterceptor`
which applies a hook to a target function without backing up the original
function code.

Depends on D68345

Differential Revision: https://phabricator.services.mozilla.com/D68346

--HG--
extra : moz-landing-system : lando
2020-04-07 14:39:54 +00:00
Toshihito Kikuchi 8219a28c40 Bug 1603974 - Part 4: Introduce MMPolicyInProcessEarlyStage. r=mhowell
This patch introduces a new policy `MMPolicyInProcessEarlyStage` which does
not consume any functions imported from kernel32.dll so that we can use it
in a process's early stage i.e. before IAT is resolved.

Depends on D68344

Differential Revision: https://phabricator.services.mozilla.com/D68345

--HG--
extra : moz-landing-system : lando
2020-04-07 14:39:56 +00:00
Toshihito Kikuchi 55af68b7d2 Bug 1603974 - Part 3: Extract a patching operation from CreateTrampoline. r=mhowell
`WindowsDllDetourPatcher::CreateTrampoline` does not only create a trampoline
region but also applies a patch on an original function.  This patch extracts
the patching part as separate functions.

Depends on D68343

Differential Revision: https://phabricator.services.mozilla.com/D68344

--HG--
extra : moz-landing-system : lando
2020-04-07 14:40:04 +00:00
Toshihito Kikuchi 18f97f01b8 Bug 1603974 - Part 1: Implement nt::VirtualQuery consuming only ntdll.dll. r=mhowell
This patch introduces `nt::VirtualQuery` which consumes only ntdll's functions
to reduce dependency in `MMPolicy` on kernel32.dll.  With this, `MMPolicy` still
depends on kernel32.dll, that will be solved by a coming patch.

Differential Revision: https://phabricator.services.mozilla.com/D68342

--HG--
extra : moz-landing-system : lando
2020-04-07 14:40:14 +00:00
Toshihito Kikuchi b7dfd23416 Bug 1625452 - No need to pass an offset to CountPrefixBytes. r=handyman
When our detour processes instructions, we pass `ReadOnlyTargetFunction` to
`CountPrefixBytes` to determine whether a lock prefix exists or not.
In that case, we don't need to pass both `ReadOnlyTargetFunction` and an offset
as a parameter because `ReadOnlyTargetFunction` has an offset as a member.

Differential Revision: https://phabricator.services.mozilla.com/D69360

--HG--
extra : moz-landing-system : lando
2020-04-04 10:31:32 +00:00
André Bargull 14ca007916 Bug 1625138 - Part 41: Remove no longer needed includes for mozilla/TypeTraits. r=froydnj
Also adds missing includes in some files, these were previously only transivitely
included through mozilla/TypeTraits.h.

Differential Revision: https://phabricator.services.mozilla.com/D68561

--HG--
extra : moz-landing-system : lando
2020-03-28 16:00:09 +00:00
André Bargull cf0b1e89e9 Bug 1625138 - Part 30: Replace mozilla::RemoveCV with std::remove_cv. r=froydnj,jgilbert
Differential Revision: https://phabricator.services.mozilla.com/D68547

--HG--
extra : moz-landing-system : lando
2020-03-28 13:57:18 +00:00
André Bargull a08be4177e Bug 1625138 - Part 17: Replace mozilla::Decay with std::decay. r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D68372

--HG--
extra : moz-landing-system : lando
2020-03-28 13:57:15 +00:00
André Bargull ebec34a898 Bug 1625138 - Part 16: Replace mozilla::IsIntegral with std::is_integral. r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D68371

--HG--
extra : moz-landing-system : lando
2020-03-28 13:57:15 +00:00
André Bargull 13e9ad3137 Bug 1625138 - Part 14: Replace mozilla::IsSigned with std::is_signed. r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D68369

--HG--
extra : moz-landing-system : lando
2020-03-28 13:57:15 +00:00
André Bargull 1e4d8b891e Bug 1625138 - Part 4: Replace mozilla::MakeUnsigned with std::make_unsigned. r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D68358

--HG--
extra : moz-landing-system : lando
2020-03-28 13:57:12 +00:00
Toshihito Kikuchi cd995fd09d Bug 1617935 - Support opcode83 [r+disp8],imm8 in x86 detour. r=handyman
In x86, our detour handles opcode 83 only when the Mod bits is 3.
When working on another project, I hit the instruction `cmp [ebp+0Ch],1`
where the Mod bits is 1, and it can be easily handled by a small fix.
It turned out my project does not need it, but it'd be good to have this.

Differential Revision: https://phabricator.services.mozilla.com/D64196

--HG--
extra : moz-landing-system : lando
2020-02-27 21:11:55 +00:00
Toshihito Kikuchi f6a7430688 Bug 1610790: Part 2 - Implement GetProcAddress for a remote process. r=handyman
This patch adds a function to get an exported function in a remote process.
We need this implementation to address Bug 1604008, Bug 1608645, and Bug 1610790.

When `WindowsDllInterceptor` detours a function in a remote process, we used the
native `GetProcAddress` locally, and then detours the returned address in the
target process.  The problem is if the caller's export table was modified, the
address returned from `GetProcAddress` might be invalid in the target process,
which is Bug 1604008.

I implemented `GetProcAddress` depending on both local and remote process image,
but it caused two regressions Bug 1608645 and Bug 1610790 because multiple
applications modify firefox's export table in multiple ways, such as replacing
an entry of EAT, replacing an RVA to Export section, or etc.

With this patch, we can use `PEExportSection<MMPolicy>::GetProcAddress` to get
an exported function in a remote process without relying on any local data so
that it's not impacted by modification of the local export table.

Differential Revision: https://phabricator.services.mozilla.com//D62315

Depends on D62314
2020-02-11 22:21:10 +02:00
Cosmin Sabou aa2a505209 Backed out 2 changesets (bug 1610790) for causing build bustages about ShowSSEConfig.
CLOSED TREE
2020-02-12 01:10:38 +02:00
Toshihito Kikuchi 23b368208e Bug 1610790: Part 2 - Implement GetProcAddress for a remote process. r=handyman
This patch adds a function to get an exported function in a remote process.
We need this implementation to address Bug 1604008, Bug 1608645, and Bug 1610790.

When `WindowsDllInterceptor` detours a function in a remote process, we used the
native `GetProcAddress` locally, and then detours the returned address in the
target process.  The problem is if the caller's export table was modified, the
address returned from `GetProcAddress` might be invalid in the target process,
which is Bug 1604008.

I implemented `GetProcAddress` depending on both local and remote process image,
but it caused two regressions Bug 1608645 and Bug 1610790 because multiple
applications modify firefox's export table in multiple ways, such as replacing
an entry of EAT, replacing an RVA to Export section, or etc.

With this patch, we can use `PEExportSection<MMPolicy>::GetProcAddress` to get
an exported function in a remote process without relying on any local data so
that it's not impacted by modification of the local export table.

Differential Revision: https://phabricator.services.mozilla.com/D62315

Depends on D62314

--HG--
extra : rebase_source : 3088f5997a2097ef22ce8567783375e5f7866ab2
2020-02-11 22:21:10 +02:00