This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: File inheritance across exec/spawn
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: nascheme Nosy List: nascheme, tim.peters
Priority: normal Keywords:

Created on 2002-01-30 21:26 by tim.peters, last changed 2022-04-10 16:04 by admin. This issue is now closed.

Messages (5)
msg9056 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2002-01-30 21:26
For 2.3, I added a new tempfile.TemporaryFile 
implementation for Windows that (among other good 
things) arranges that spawned processes will no longer 
inherit the temp files' underlying open file 
descriptors.  There are multiple reasons for doing so 
on Windows, and one that's "an issue" across all 
platforms is security.

Temp files may (will, AFAICT) still get inherited on 
other platforms.  And inheriting open files of other 
kinds may still be an issue on all platforms.

Guido sez (from email):

"""
This is exactly what happens on Unix, I'm afraid.  Is
there a way around that?  Across fork(), I think it's 
fair (might be intentional).  Across exec(), I think 
there's no point.  We should use fcntl() with F_SETFD 
to set the FD_CLOEXEC bit.
"""

There is no fork on Windows, so life is simpler there; 
OTOH, there's no FD_CLOEXEC bit on Windows either, so 
life is harder there if we want to extend this to 
other files.  I'm inclined to think we should stick to 
setting policy only for temp files;  *we* create them, 
and the user has no control over how we create them.  
For files the user opens themself, they can get at 
FD_CLOEXEC (on platforms supporting it) from Python.  
They can also get at O_NOINHERIT on Windows in 2.3 
(when using os.open()).
msg9057 - (view) Author: Neil Schemenauer (nascheme) * (Python committer) Date: 2002-03-22 22:35
Logged In: YES 
user_id=35752

What's the bug here?  I'm guessing that Guido is suggesting
that TemporaryFile set the FD_CLOEXEC.  Is that right?
msg9058 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2002-03-22 22:49
Logged In: YES 
user_id=31435

I expect Guido is suggesting at least that, and since it's 
my bug report <wink> I'd be happy to close it if that much 
is done.  Security Geeks may or may not wish to argue that 
all files opened by Python do likewise, but, if so, they 
can open their bug report.
msg9059 - (view) Author: Neil Schemenauer (nascheme) * (Python committer) Date: 2002-03-22 23:16
Logged In: YES 
user_id=35752

Okay.  I'll take it since I'm a wannabe security geek.
msg9060 - (view) Author: Neil Schemenauer (nascheme) * (Python committer) Date: 2002-03-24 22:23
Logged In: YES 
user_id=35752

Fixed in tempfile.py 1.38.
History
Date User Action Args
2022-04-10 16:04:56adminsetgithub: 36003
2002-01-30 21:26:11tim.peterscreate