-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
gh-143309: fix UAF in os.execve when the environment is concurrently mutated
#143314
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
base: main
Are you sure you want to change the base?
Conversation
…rrently mutated
|
Mmh. This is tricky for Windows. I don't have a Windows machine to know what happened there. |
|
@chris-eibl I know you're on Windows, so could you help me there please? |
|
Will have a closer look tomorrow |
17b706f to
be3bd3d
Compare
Ups, really tricky on Windows. I've found two different issues: Edit: Created #143327 Details
The test case boils down to this smallest reproducer I can get: import os, sys
import subprocess
code = """
import os, sys
args = [sys.executable, '-c', 'print(4711)']
os.execve(args[0], args, {})
"""
cmd_line = [sys.executable, '-X', 'faulthandler', '-c', code]
env_1 = os.environ.copy()
env_2 = {}
env_2['SYSTEMROOT'] = os.environ['SYSTEMROOT']
proc = subprocess.Popen(
cmd_line, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
env=env_1)
with proc:
try:
out, err = proc.communicate()
finally:
proc.kill()
subprocess._cleanup()
print("rc", proc.returncode)
print("out", out)
print("err", err)Using |
|
Oh, so the problem is |
|
Secondly, the Edit: created #143328 Details
import os
import sys
args = [sys.executable, '-c', 'print("hello from execve")']
os.execve(args[0], args, {})This results in And using Both work like expected in WSL. The only thing that somewhat works is omitting the spaces |
|
I haven't found these two things reported as issues, yet, I think I should create two new issues? With the above in mind, changing your test slightly to: args = [sys.executable, '-c', "print('hellofromexecve')"]
os.execve(args[0], args, MyEnv())
"""
env = {}
env['__cleanenv'] = True # signal to assert_python not to do a copy
# of os.environ on its own
rc, out, _ = assert_python_ok('-c', code, **env)
self.assertEqual(rc, 0)
self.assertIn(b"hellofromexecve", out)let's it pass for me. Without your fix applied, it will fail with an access violation, due to the UAF 🚀 |
Please do so and thank you for all this investigation! |
|
Oh, Win x64 now almost green in CI like for me. Unfortunately, arm64 and Win32 still crash. I will look at Win32, do not have an Arm machine ... |
|
Sorry, didn't want to also apply my suggestion - just suggest. Misclicked, hangover from yesterday ... |
|
You're hijacking my code! 😨 |
|
Could the issue on Windows and general be caused by this: |
And already apologized. Misclicked. Sorry again.
Win32 is green for me. I've run 5 times sucessfully ... |
Don't worry! I was overreacting but I wasn't offended :) |
... and crashed after trying a 6th time. But I could not crash x64 after 20 invocations ...
IDKN. Looks ok at a first glance? |
|
I actually wonder whether the issue is because of execve in general or the environment we build. |
|
Could it be actually because we're not forwarding |
|
It get's autofilled here cpython/Lib/test/support/script_helper.py Lines 131 to 134 in 422ca07
|
|
Yes, but not when calling execve. The environment I'm passing to execve is an environment that gets mutated. |
194fa14 to
73e3f79
Compare
73e3f79 to
5bd7d39
Compare
a7d9e74 to
7b6e2db
Compare
|
Ok I give up, I have no idea why this crashes but I'm pretty sure the issue is after we call |
Yes, definitely. Was always the case when I was debugging it, but cannot crash it anymore in x64 when the env is "lightweight" ... |
|
I think we should debug what the environment passed to |
|
Considering #137934, I think we will, for now, just skip the test on Windows. If even |
parse_envlistvia re-entrantenv.keys()orenv.values()#143309