Kyle Evans <kev...@freebsd.org> added the comment:

On Wed, Jan 16, 2019 at 5:47 PM Alexey Izbyshev <rep...@bugs.python.org> wrote:
> > Hi,
>
> > As a disclaimer, I'm a FreeBSD developer interested in making sure we're 
> > doing the right thing here. =)
>
> > May I ask what the above assessment is based on, and specifically what we 
> > need to address?
>
> Hello, Kyle! That assessment is based on my quick and incorrect reading of 
> posix_spawn source code. I didn't notice that "error" is visible in the 
> parent due to address space sharing. Sorry for that, and thank you for the 
> correction. A proper error notification is required for posix_spawn to be 
> used in subprocess as a replacement for fork/exec, and FreeBSD does it right.

Oh, good to hear. =) koobs had pointed this thread out in hopes that we can try 
to reconcile and figure out what work needs to be done here. =)

> While we're here, would you be kind to answer several questions about 
> posix_spawn on FreeBSD?

Most definitely, if I can!

> 1) On Linux, without taking additional precautions, signals may be delivered 
> to a child process created via vfork(). If a signal handler runs in such a 
> child, it can leave traces of its work in the (shared) memory, potentially 
> surprising the parent process. To avoid this, glibc[1] and musl[2] disable 
> all signals (even signals used internally for thread cancellation) before 
> creating a child, but FreeBSD calls vfork() right away. Is this not 
> considered a problem, or is something hidden in vfork() implementation?
>

Right, after glancing over our implementation details- this is indeed a problem 
here. Our manpage indicates that we only block SIGTTOU for SIGTTIN for children 
in vfork(), and some light testing seems to indicate that's the case. Signal 
handlers are inherited from the parent, so that's less than stellar.

> 2) Another problem with vfork() is potential sharing of address space between 
> processes with different privileges (see Rich Felker's post[3] about this and 
> the previous problem). Is this a valid concern on FreeBSD?

My initial read-through of the relevant bits seem to indicate that image 
activation will cause the child process to be allocated a new process space, so 
it's looking kind of like a 'no' -- I'm outsourcing the answer to this one to 
someone more familiar with those bits, though, so I'll get back to you.


> 3) Does FreeBSD kernel guarantee that when waitpid(WNOHANG) is called at [4], 
> the child is ready for reaping? On Linux, it's not always the case[5].

I want to say vfork semantics guarantee it- we got to this point, so the child 
hit an error and _exit(127). I'm double-checking this one, though, to verify 
the child's properly marked a zombie before we could possibly reschedule the 
parent.

----------

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

Reply via email to