Skip to content

Add regression tests for MemoryDenyWriteExecute=true#1071

Merged
jjhelmus merged 1 commit intomainfrom
geofft/validate-noexecstack-threads
Apr 16, 2026
Merged

Add regression tests for MemoryDenyWriteExecute=true#1071
jjhelmus merged 1 commit intomainfrom
geofft/validate-noexecstack-threads

Conversation

@geofft
Copy link
Copy Markdown
Collaborator

@geofft geofft commented Mar 30, 2026

As reported in #956, executable stacks cause thread creation to fail under MemoryDenyWriteExecute=true. In kernel 6.3+ (which the GitHub Actions runners should have) this is implemented using prctl(PR_SET_MDWE). In older versions systemd uses a more complicated seccomp filter.

As reported in #956, executable stacks cause thread creation to fail
under MemoryDenyWriteExecute=true. In kernel 6.3+ (which the GitHub
Actions runners should have) this is implemented using
prctl(PR_SET_MDWE). In older versions systemd uses a more complicated
seccomp filter.
@geofft
Copy link
Copy Markdown
Collaborator Author

geofft commented Mar 30, 2026

Fails locally on an existing release, although unfortunately Python's error message is not great:

$ BUILD_OPTIONS= TARGET_TRIPLE=x86_64-linux-gnu uvx python3 -m unittest pythonbuild.disttests 
......E..Es.
======================================================================
ERROR: test_nx_thread_creation (pythonbuild.disttests.TestPythonInterpreter.test_nx_thread_creation)
Test that thread creation works under e.g. systemd's MemoryDenyWriteExecute.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/ubuntu/python-build-standalone/pythonbuild/disttests/__init__.py", line 350, in test_nx_thread_creation
    t.start()
    ~~~~~~~^^
  File "/home/ubuntu/.local/share/uv/python/cpython-3.14.3-linux-x86_64-gnu/lib/python3.14/threading.py", line 1005, in start
    _start_joinable_thread(self._bootstrap, handle=self._os_thread_handle,
    ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                           daemon=self.daemon)
                           ^^^^^^^^^^^^^^^^^^^
RuntimeError: can't start new thread

def test_nx_thread_creation(self):
"Test that thread creation works under e.g. systemd's MemoryDenyWriteExecute."
# Note that NX cannot be unset so this pollutes the current process,
# but if something else breaks under NX we probably want to know!
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it worth isolating this from other tests via subprocess? Not a blocker to merging.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Is that easy to do? My gut feeling was the implementation complexity of doing that outweighed the potential benefits (especially since other failures under W^X are probably legitimate bugs) but if there's an easy way to do it I'm fine with it.

@jjhelmus jjhelmus merged commit a186551 into main Apr 16, 2026
23 checks passed
@jjhelmus jjhelmus deleted the geofft/validate-noexecstack-threads branch April 16, 2026 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants