Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-97514: Authenticate the forkserver control socket. #99309

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

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
clear up some comments and an assert
  • Loading branch information
gpshead committed Nov 15, 2022
commit 6f8e22fb016810712d20f70013b718cef9c24a6f
8 changes: 3 additions & 5 deletions Lib/multiprocessing/forkserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ def ensure_running(self):
finally:
os.close(alive_r)
os.close(authkey_r)
# Prevent access from processes not in our process tree that
# have the same shared key for this forkserver.
# Authenticate our control socket to prevent access from
# processes we have not shared this key with.
try:
self._forkserver_authkey = os.urandom(_authkey_len)
os.write(authkey_w, self._forkserver_authkey)
Expand All @@ -196,10 +196,8 @@ def main(listener_fd, alive_r, preload, main_path=None, sys_path=None,
*, authkey_r=None):
"""Run forkserver."""
if authkey_r is not None:
# If there is no authkey, the parent closes the pipe without writing
# anything resulting in an empty authkey of b'' here.
authkey = os.read(authkey_r, _authkey_len)
assert len(authkey) == _authkey_len or not authkey
assert len(authkey) == _authkey_len, f'{len(authkey)} < {_authkey_len}'
os.close(authkey_r)
else:
authkey = b''
Expand Down