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: os.mkdir() and os.mkdirat() don't apply SUID/SGID permissions
Type: Stage:
Components: Versions: Python 3.1, Python 3.2, Python 3.3, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, giampaolo.rodola, r.david.murray, terry.reedy
Priority: normal Keywords: patch

Created on 2011-02-28 19:40 by Arfrever, last changed 2022-04-11 14:57 by admin.

Files
File name Uploaded Description Edit
python-mkdir.patch Arfrever, 2011-02-28 21:24 review
Messages (4)
msg129720 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * (Python triager) Date: 2011-02-28 19:40
os.mkdir() and os.mkdirat() use libc's mkdir() and mkdirat(), which can ignore SUID/SGID permissions. This problem occurs at least on systems using glibc. The solution is to call chmod() / fchmodat() to ensure that given directory has been created with requested permissions. I'm attaching the patch.
msg129721 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * (Python triager) Date: 2011-02-28 21:24
The new patch restores respecting of umask.
msg129722 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * (Python triager) Date: 2011-02-28 21:43
A side effect of this patch is that it fixes failure of test_exist_ok_existing_directory() from test_os.py in situation when top-level directory of Python sources has SGID bit set. (test_exist_ok_existing_directory() exists only in Python >=3.2.)

$ chmod g+s .
$ LD_LIBRARY_PATH=$(pwd) ./python Lib/test/test_os.py
...
======================================================================
ERROR: test_exist_ok_existing_directory (__main__.MakedirTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Lib/test/test_os.py", line 653, in test_exist_ok_existing_directory
    os.makedirs(path, mode=mode, exist_ok=True)
  File "/var/tmp/portage/dev-lang/python-3.3_pre20110227/work/python-3.3_pre20110227/Lib/os.py", line 152, in makedirs
    mkdir(name, mode)
OSError: [Errno 17] File exists: '@test_32218_tmp/dir1'

----------------------------------------------------------------------
msg130080 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2011-03-04 22:03
os.makedir (and, I presume, makedirat) are intentionally thin wrapperws around the libc system calls

From #9299, msg111014 (Guido)
"I wonder if os.mkdir() should not be left alone (so as to continue
to match the system call most exactly, as is our convention) and the
extra functionality added to os.makedirs() only."

Deviation from this would require pydev discussion. I otherwise have no opinion.
History
Date User Action Args
2022-04-11 14:57:13adminsetgithub: 55564
2011-03-05 18:32:39giampaolo.rodolasetnosy: + giampaolo.rodola
2011-03-04 22:03:46terry.reedysetnosy: + terry.reedy
messages: + msg130080
2011-02-28 21:43:35Arfreversetmessages: + msg129722
2011-02-28 21:25:45Arfreversetfiles: - python-mkdir.patch
2011-02-28 21:24:50Arfreversetfiles: + python-mkdir.patch

messages: + msg129721
2011-02-28 20:13:05r.david.murraysetnosy: + r.david.murray
2011-02-28 19:40:37Arfrevercreate