Gregory P. Smith <g...@krypto.org> added the comment:

Can you provide a reproducable way to demonstrate evidence of a problem in 
CPython's use of the Linux libc vfork() implementation?  A test case that 
causes a CPython parent or child process on Linux when built with HAVE_VFORK 
failing to function properly would help prioritize this because in practice 
nobody has reported problems in 3.10.

(we've deployed the subprocess vfork code into thousands production Python 
programs at work in the past year w/o issues being reported - though we have a 
constrained environment with use on only a couple of libc versions and limited 
set of kernels on a few very common architectures)

General thinking (possible dated and incorrect - against what 
https://man7.org/linux/man-pages/man2/vfork.2.html wording claims with its "or 
calls any other function" text):

Pushing additional data onto the stack in the child process _should_ not a 
problem.  That by definition lands in previously unused pre-allocated stack 
space.  If that page faults, that could map a new page into the process state 
shared by both the paused parent and running child. But this page mapping 
should be fine - the child exec that resumes the parent means the parent is the 
only one who sees it.

When the parent process resumes, sure, that data will be in that memory on the 
unallocated portion of stack, but critically the *stack pointer* in the parent 
process (a register) never changes.  As far as I understand things, registers 
are not shared between vfork()ed processes.  So the parent only sees some 
temporary data having been written to the unused region of the stack by the 
since-replaced by exec() child process.  No big deal.

**Untrue wishful thinking**: If a new stack were needed on a given platform for 
use in the vfork()ed child, I'd like it to be the job of libc to take care of 
that for us.  glibc sources do no such thing (every vfork supporting 
architecture has a vfork.S code that appears to make the syscall and jump back 
to the caller without stack manipulation).

----------
assignee:  -> gregory.p.smith
nosy: +gregory.p.smith
stage:  -> test needed
title: Subprocess with vfork() is broken -> potential undefined behavior with 
subprocess using vfork() on Linux
type:  -> behavior

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue47245>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to