protocolbuffers / protocolbuffers/protobuf
_message.pyd for Windows Python is missing NX and ASLR
Nobody has claimed this yet.
- 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:
- Build the Windows extension:
bazel build --config=cross_config //python/dist - Extract
google/_upb/_message.pydfrom the wheel zip. - (On Windows) run
dumpbin.exe /headers _message.pydto check the DLL headers.
or
- Run
pip install protobuf(currently installsprotobuf-7.35.1) - 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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