Bug 5027 - Perms in do_mkstemp are not always valid
Summary: Perms in do_mkstemp are not always valid
Alias: None
Product: rsync
Classification: Unclassified
Component: core (show other bugs)
Version: 2.6.9
Hardware: x86 Linux
: P3 normal (vote)
Target Milestone: ---
Assignee: Wayne Davison
QA Contact: Rsync QA Contact
Depends on:
Reported: 2007-10-19 21:00 UTC by Chris Adams
Modified: 2007-11-03 14:30 UTC (History)
0 users

See Also:

Make sure the user has write permission to the temp file (413 bytes, patch)
2007-10-19 21:01 UTC, Chris Adams
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Adams 2007-10-19 21:00:34 UTC
I'm trying to rsync (with -a to preserve permissions) to a mount point on an NFS server, and it fails when copying a file that is read-only.  The problem is that do_mkstemp creates the temp file with the desired user permissions (either with open() or with fchmod().

SUSv3 says that the affect of chmod()/fchmod() on existing open file descriptors is implemtation defined; it also says:

    Any file descriptors currently open by any process on the file could
    possibly become invalid if the mode of the file is changed to a value which
    would deny access to that process. One situation where this could occur is
    on a stateless file system. This behavior will not occur in a conforming

I guess I have a non-conforming environment (I'm talking to a unfs3 server).

If I remove HAVE_FCHMOD, it still doesn't work, because the call to open() includes the read-only permissions as well (a case I don't really see referenced in SUSv3 right off).

The following patch makes sure that the user always has write permission to the temp file:

diff -urN rsync-2.6.9-dist/syscall.c rsync-2.6.9/syscall.c
--- rsync-2.6.9-dist/syscall.c  2007-10-19 20:49:29.000000000 -0500
+++ rsync-2.6.9/syscall.c       2007-10-19 20:53:02.000000000 -0500
@@ -190,6 +190,7 @@
        RETURN_ERROR_IF(dry_run, 0);
        RETURN_ERROR_IF(read_only, EROFS);
+       perms |= S_IWUSR;
 #if defined HAVE_SECURE_MKSTEMP && defined HAVE_FCHMOD && (!defined HAVE_OPEN64 || defined HAVE_MKSTEMP64)
Comment 1 Chris Adams 2007-10-19 21:01:05 UTC
Created attachment 2947 [details]
Make sure the user has write permission to the temp file
Comment 2 Wayne Davison 2007-11-03 14:30:44 UTC
I checked that the callers of do_mkstemp() will all fix the permissions if the user-write permission is not supposed to be on final file, and it looks good.  I've checked your patch into CVS.  Thanks!