-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
mktemp: Prevent race condition when setting permissions for tempdir #7617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mktemp: Prevent race condition when setting permissions for tempdir #7617
Conversation
GNU testsuite comparison:
|
b08c611
to
2464ae1
Compare
GNU testsuite comparison:
|
2464ae1
to
7bf478f
Compare
GNU testsuite comparison:
|
please add a comment in the code, thanks |
7bf478f
to
ebb17cb
Compare
I Have tried to add what I think could be a relevant comment, any feedback is welcomed 😃. |
ebb17cb
to
c9e75bc
Compare
GNU testsuite comparison:
|
Sorry but please also add a test to verify that the permissions are correctly set |
c9e75bc
to
fdc17c1
Compare
GNU testsuite comparison:
|
fdc17c1
to
df1bd54
Compare
I believe that this test already covers this |
GNU testsuite comparison:
|
df1bd54
to
46c93d8
Compare
GNU testsuite comparison:
|
This prevents a race conditions vulnerability in the tempdir implementation, where an attacker potentially could modify the created temporary directory, before the restrictive permissions are set. The race conditions occurs in the moment between the temporary directory is created, and the proper permissions are set. # The fix This patch changes the `make_temp_dir` to create the temporary directory with the proper permissions creation time. Rather than first create, then set permissions. This is done by giving the permissions to the builder. See [tempfile doc](https://github.com/Stebalien/tempfile/blob/95540ed3fcb9ca74845c02aee058726b2dca58b7/src/lib.rs#L449-L450). # Severity Low The attack is only possible if the umask is configured to allow writes by group or other for created file/directories. # Related Resources See: https://cwe.mitre.org/data/definitions/377.html
46c93d8
to
32fed17
Compare
GNU testsuite comparison:
|
This prevents a race conditions vulnerability in the
make_temp_dir
implementation, where an attacker potentially could modify the created temporary directory, before the restrictive permissions are set.The race conditions occurs in the moment between the temporary directory is created, and the proper permissions are set.
The fix
This patch changes the
make_temp_dir
to create the temporary directory with the proper permissions creation time. Rather than first create, then set permissions. This is done by giving the permissions to the builder. See tempfile doc.Severity Low
The attack is only possible if the umask is configured to allow writes by group or other for newly created files/directories.
Related Resources
See: https://cwe.mitre.org/data/definitions/377.html