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

Thanks!  I agree with you that this is probably not an actual problem on Linux.

_I did look at the various glibc architecture vfork.s implementations: Cute 
tricks used on some where they need to avoid a stack modifying traditional 
return from vfork()._

As for glibc specifics, I'm mostly thinking of the calls we do in the child.

According to the "Standard Description (POSIX.1)" calls to anything other than 
`_exit()` or `exec*()` are not allowed.  But the longer "Linux Description" in 
that vfork(2) man page does not say that.  Which implies merely by omission 
that calls to other things are okay so long as you understand everything they 
do to the process heap/stack/state.  (I wish it were *explicit* about that)

Some of the calls we do from our child_exec() code... many are likely "just" 
syscall shims and thus fine - but that is technically up to libc.

A few others are Py functions that go elsewhere in CPython and while they may 
be fine for practical reasons today with dangerous bits on conditional branches 
that technically should not be possible to hit given the state by the time 
we're at this point in _posixsubprocess, pose a future risk - anyone touching 
implementations of those is likely unaware of vfork'ed child limitations that 
must be met.

For example if one of the potential code paths that trigger an indirect 
Py_FatalError() is hit... that fatal exit code is definitely not 
post-vfork-child safe.  The pre-exec child dying via that could screw up the 
vfork parent process's state.

----------
title: potential undefined behavior with subprocess using vfork() on Linux -> 
potential undefined behavior with subprocess using vfork() on Linux?

_______________________________________
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