diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2010-06-06 23:49:18 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2010-08-09 16:48:15 -0400 |
commit | f8ad850f11e11d10e7de1a16ca53cb193afc9313 (patch) | |
tree | 4812193c6be29f41d3de3ae74705e95a9566546c /fs/hostfs/hostfs_user.c | |
parent | f8d7e1877e5121841bc9a4d284a04dbc13f45bea (diff) |
try to get rid of races in hostfs open()
In case of mode mismatch, do *not* blindly close the descriptor
another openers might be using right now. Open the underlying
file with currently sufficient mode, then
* if current mode has grown so that it's sufficient for
us now, just close our new fd
* if current mode has grown and our fd is *not* enough
to cover it, close and repeat.
* otherwise, install our fd if the file hadn't been
opened at all or dup2() our fd over the current one (and close
our fd).
Critical section is protected by mutex; yes, system-wide. All
we do under it is a bunch of comparison and maybe an overwriting
dup2() on host.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/hostfs/hostfs_user.c')
-rw-r--r-- | fs/hostfs/hostfs_user.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/fs/hostfs/hostfs_user.c b/fs/hostfs/hostfs_user.c index 91ebfcefa409..6777aa06ce2c 100644 --- a/fs/hostfs/hostfs_user.c +++ b/fs/hostfs/hostfs_user.c | |||
@@ -160,6 +160,11 @@ int fsync_file(int fd, int datasync) | |||
160 | return 0; | 160 | return 0; |
161 | } | 161 | } |
162 | 162 | ||
163 | int replace_file(int oldfd, int fd) | ||
164 | { | ||
165 | return dup2(oldfd, fd); | ||
166 | } | ||
167 | |||
163 | void close_file(void *stream) | 168 | void close_file(void *stream) |
164 | { | 169 | { |
165 | close(*((int *) stream)); | 170 | close(*((int *) stream)); |