Skip to content

multiprocessing "forkserver"/"spawn": untrusted search path #157916

Description

@jwilk

With the multiprocessing start methods forkserver and spawn, the -c option is passed to the interpreter;
but that puts the current working directory (which may be untrusted) in sys.path[0].

To reproduce:

  1. Put the following test script outside of cwd:
import multiprocessing
import sys

if __name__ == '__main__':
    mp = multiprocessing.get_context(*sys.argv[1:])
    proc = mp.Process(target=print, args=['yay'])
    proc.start()
    proc.join()
  1. Plant shady multiprocessing.py in cwd:
import os, signal
print('pwned')
os.kill(-os.getpgid(0), signal.SIGKILL)
  1. Observe that with forkserver and spawn methods, code from the planted multiprocessing is executed:
$ python3.15 --version
Python 3.15.0rc2

$ python3.15 /path/to/test-mp.py fork
yay

$ python3.15 /path/to/test-mp.py forkserver
pwned
Killed

$ python3.15 /path/to/test-mp.py spawn
pwned
Killed

Probably the easiest way to fix this is to use -P ("Don’t automatically prepend a potentially unsafe path to sys.path").

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-multiprocessingtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions