protocolbuffers / protocolbuffers/protobuf

_message.pyd for Windows Python is missing NX and ASLR

Open Beginner friendly
#28,688 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

38.x bug feature request python
Dominant language
C++
Stars
72k
Forks
16.3k
Avg merge
1d 17h
Merged PRs (30d)
140

Description

What version of protobuf and what language are you using?

Version: v36-dev
Language: Python

What supported operating system version are you using (e.g. Linux, Windows) ?

Linux

What supported runtime / compiler version are you using (e.g. python version, gcc version)

Python 3.10.11
MinGW-w64 GCC

What did you do?

Steps to reproduce the behavior:

  1. Build the Windows extension: bazel build --config=cross_config //python/dist
  2. Extract google/_upb/_message.pyd from the wheel zip.
  3. (On Windows) run dumpbin.exe /headers _message.pyd to check the DLL headers.

or

  1. Run pip install protobuf (currently installs protobuf-7.35.1)
  2. Run dumpbin.exe /headers <python directory>Lib\site-packages\google\_upb\_message.pyd

What did you expect to see

For the NX and ASLR security features to be enabled, under OPTIONAL HEADER VALUES these values should be enabled:

             160 DLL characteristics
                   High Entropy Virtual Addresses
                   Dynamic base
                   NX compatible

What did you see instead?

               0 DLL characteristics

Anything else we should know about your project / environment

I would've sent a PR, but I could not find an Google Contributor License Agreement with my employer nor reach our person in charge of those. However fixing this should be quite simple by adding something like below to python\py_extension.bzl.

def py_extension(name, srcs, copts, deps = [], **kwargs):
    """Creates a C++ library to extend python

    Args:
      name: Name of the target
      srcs: List of source files to create the target
      copts: List of C++ compile options to use
      deps: Libraries that the target depends on
    """
    cc_binary(
        name = name + "_binary",
        srcs = srcs,
        copts = copts + ["-fvisibility=hidden"],
        linkopts = selects.with_or({
            (
                "//python/dist:osx_x86_64",
                "//python/dist:osx_aarch64",
            ): ["-Wl,-undefined,dynamic_lookup"],
+           "//python/dist:windows_x86_32": [
+               "-static-libgcc",
+               "-Wl,--nxcompat",
+               "-Wl,--dynamicbase",
+            ],
+            "//python/dist:windows_x86_64": [
+                "-Wl,--nxcompat",
+                "-Wl,--dynamicbase",
+                "-Wl,--high-entropy-va",
+            ],
            "//conditions:default": [],
        }),

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in python/py_extension.bzl and inspect the Windows linker options used by py_extension. Build the Windows extension with bazel build --config=cross_config //python/dist, extract google/_upb/_message.pyd, and inspect it with dumpbin.exe /headers. Done means the DLL characteristics include High Entropy Virtual Addresses, Dynamic base, and NX compatible.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
build-system, security
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.