-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
install: create destination file with safer modes before copy #6595
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
Conversation
Could you please add a test to make sure we don't regress? Thanks |
11830cd
to
2eb2c4c
Compare
There was indeed a regression: when the I added a test to make sure that no file will be created when I'm not sure how to use a test case to check whether the new file is created in mode 0600, since the creation is in the middle of an internal function, but the strace output confirms so If you have any suggestions please let me know. Thanks! |
c9ded01
to
5b9c0c6
Compare
GNU testsuite comparison:
|
dbe383a
to
051539c
Compare
051539c
to
43cca95
Compare
GNU testsuite comparison:
|
43cca95
to
bdbef46
Compare
GNU testsuite comparison:
|
bdbef46
to
9fc58f9
Compare
9fc58f9
to
cbca15a
Compare
cbca15a
to
a5867bd
Compare
thanks and sorry for the latency |
This did not fix the problem -- the magic fchmod to 644 is still there making the file temporarily accessible. Moreover this introduces a regression where the target file gets unlinked even if the source does not exist. I verified install from gnu coreutils just exits in such a case without messing with the target. below I'm annotating strace output from a setup as in the bug report, installing from /tmp/srcdir/foo to /tmp/dstdir/foo. there is tons of noise there which I elided for clarity.
This executes regardless if /tmp/srcdir/foo exists or can be copied, meaning by this point the content of the target is whacked. The new file does however have 600 perms. The file should remain unaltered if src can't be copied.
Note the target is accessible through fd 4. Rust code just chmoded it to 644, making it again readable by everyone who can access the directory and defeating the original open.
Only now the file goes back to the expected state. All in all the fs::copy API is probably fine for some cases, but is a total non-starter for serious programs. I failed to find a variant which accepts file handles instead, Rust needs to grow one. |
ok, thanks for the very quick reaction. I will revert it then. |
Ye makes sense. I'm going to prod the rust people about better fs::copy so that this can be properly fixed. |
@mjguzik Thanks a lot for the feedback. |
I found that rust has a variant accepting file handles: https://doc.rust-lang.org/beta/std/io/fn.copy.html this will do it |
Fix #6435.
As is suggested by the original issue, the creation of the destination file is delegated to
fs::copy
which creates the file with default mode0644
. This makes the file readable by other users before the finalchmod
is done, which is potentially unsafe and inconsistent with GNU install.Since the current implementation unconditionally removes the destination path before the copy, creating the file with a minimal
u=rw
permission would not hurt the copy. This patch implements this (for unix).