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

Stop specifying /BASE option to mozc_tip32.dll and mozc_tip64.dll #834

Closed
yukawa opened this issue Oct 24, 2023 · 0 comments
Closed

Stop specifying /BASE option to mozc_tip32.dll and mozc_tip64.dll #834

yukawa opened this issue Oct 24, 2023 · 0 comments

Comments

@yukawa
Copy link
Collaborator

yukawa commented Oct 24, 2023

Description

Currently mozc_tip32.dll and mozc_tip64.dll are built with /BASE option.

mozc/src/win32/tip/tip.gyp

Lines 155 to 157 in af20906

'VCLinkerTool': {
'BaseAddress': '0x06000000',
},

mozc/src/win32/tip/tip.gyp

Lines 174 to 176 in af20906

'VCLinkerTool': {
'BaseAddress': '0x06000000',
},

This is however now discouraged as follows.

Note

For security reasons, Microsoft recommends you use the /DYNAMICBASE option instead of specifying base addresses for your executables. /DYNAMICBASE generates an executable image that can be randomly rebased at load time by using the address space layout randomization (ASLR) feature of Windows. The /DYNAMICBASE option is on by default.

You can also find the following warning while building Mozc for Windows (e.g. from build #186)

[456/457] LINK_EMBED(DLL) mozc_tip64.dll
LINK : warning LNK4281: undesirable base address 0x6000000 for x64 image; set base address above 4GB for best ASLR optimization

Also from Does ASLR relocate all DLLs by the same offset? - The Old New Thing

ASLR chooses the base address pseudo-randomly, though it does take some of the original base addresses into account. For example, if the original base address was below the 4GB boundary, then the new pseudo-random base address will also be below the 4GB boundary.

Steps to reproduce

  1. Build and install Mozc for Windows
  2. dumpbin /HEADERS .\out_win\Release\mozc_tip32.dll
  3. dumpbin /HEADERS .\out_win\Release_x64\mozc_tip64.dll
  4. Launch Notepad (64-bit)
  5. Select Mozc as the current IME

Expected behavior

  • At the step 5, mozc_tip64.dll is loaded into somewhere above 0x100000000

Expected result in the step 2

OPTIONAL HEADER VALUES
             10B magic # (PE32)

  (snip)

         6000000 image base (06000000 to 064D0FFF)

  (snip)

               2 subsystem (Windows GUI)
             140 DLL characteristics
                   Dynamic base
                   NX compatible

Expected result in the step 3

OPTIONAL HEADER VALUES
             20B magic # (PE32+)

  (snip)

         6000000 image base (0000000006000000 to 000000000650CFFF)

  (snip)

               2 subsystem (Windows GUI)
             160 DLL characteristics
                   High Entropy Virtual Addresses
                   Dynamic base
                   NX compatible

Actual behavior

  • At the step 5, mozc_tip64.dll is loaded into somewhere below 0x100000000 (not as expected).

Actual result in the step 2

OPTIONAL HEADER VALUES
             10B magic # (PE32)

  (snip)

        10000000 image base (10000000 to 104D0FFF)
            1000 section alignment

  (snip)

               2 subsystem (Windows GUI)
             140 DLL characteristics
                   Dynamic base
                   NX compatible

Actual result in the step 3

OPTIONAL HEADER VALUES
             20B magic # (PE32+)

  (snip)

       180000000 image base (0000000180000000 to 000000018050CFFF)

  (snip)

               2 subsystem (Windows GUI)
             160 DLL characteristics
                   High Entropy Virtual Addresses
                   Dynamic base
                   NX compatible

Screenshots

mozc_tip64.dll address

Version or commit-id

82ff093

Environment

  • OS: Windows 11 22H2
hiroyuki-komatsu added a commit that referenced this issue Oct 26, 2023
Typing quality
* Added  鵼(ぬえ) and 喃(のう) to the word dictionary.

Linux
* Fixed the crash issue of the candidate window UI (#820)

Windows
* Enabled the candidate window to respect the vertical writing mode (#362)
* Updated InputScope mapping to be compatible with MS-IME as of Windows 11 22H2 (#818, #826)
* Addressed the issue of no response on MS-Word (#819)
* Enabled the candidate window to consider per-monitor DPI settings (#832)

Build
* Enabled C++20 (#783)
* Switched to Qt 6.6.0 for Windows and macOS (#833)
* Reduced Qt6 binary size (#822)
* macOS: Fixed the non executable error of GUI tools with GYP
* Windows: Stopped specifying /BASE option (#834)
* Windows: Enabled Hardware Enforced Stack Protection (#835)
* Windows: Set default dependent load flags to Mozc executables for Windows (#836)
* Windows: Removed the dependency on CoCreateInpustance from mozc_tip dlls (#837)

PiperOrigin-RevId: 576830216
coooooooozy pushed a commit to coooooooozy/mozc that referenced this issue Nov 26, 2023
With Address Space Layout Randomization (ASLR), specifying unique base
address to DLLs at the link time is no longer recommended [1].

Actually we are currently seeing in the following warning when building
Mozc for Windows.

  [456/457] LINK_EMBED(DLL) mozc_tip64.dll
  LINK : warning LNK4281: undesirable base address 0x6000000 for x64
  image; set base address above 4GB for best ASLR optimization

Let's drop our custom 'BaseAddress' settings from 'mozc_tip{32,64}.dll'
to let the linker set the recommended value.

There must be no user observable behavior change anyway.

Closes google#834.

 [1]: https://learn.microsoft.com/en-us/cpp/build/reference/base-base-address#remarks

PiperOrigin-RevId: 576203953
coooooooozy pushed a commit to coooooooozy/mozc that referenced this issue Nov 26, 2023
Typing quality
* Added  鵼(ぬえ) and 喃(のう) to the word dictionary.

Linux
* Fixed the crash issue of the candidate window UI (google#820)

Windows
* Enabled the candidate window to respect the vertical writing mode (google#362)
* Updated InputScope mapping to be compatible with MS-IME as of Windows 11 22H2 (google#818, google#826)
* Addressed the issue of no response on MS-Word (google#819)
* Enabled the candidate window to consider per-monitor DPI settings (google#832)

Build
* Enabled C++20 (google#783)
* Switched to Qt 6.6.0 for Windows and macOS (google#833)
* Reduced Qt6 binary size (google#822)
* macOS: Fixed the non executable error of GUI tools with GYP
* Windows: Stopped specifying /BASE option (google#834)
* Windows: Enabled Hardware Enforced Stack Protection (google#835)
* Windows: Set default dependent load flags to Mozc executables for Windows (google#836)
* Windows: Removed the dependency on CoCreateInpustance from mozc_tip dlls (google#837)

PiperOrigin-RevId: 576830216
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

No branches or pull requests

1 participant