Skip to contentSkip to conversation

try to get rid of races in hostfs open()

PATCH In review Al Viro 1 participant 1 message Jun 8, 2010

Subsystems (2)
lore
Share & tools
lore

Al Viro

author
#0 lore raw

PATCH 36/58 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.

---
 fs/hostfs/hostfs.h      |    1 +
 fs/hostfs/hostfs_kern.c |   43 +++++++++++++++++++++++++++++++------------
 fs/hostfs/hostfs_user.c |    5 +++++
 3 files changed, 37 insertions(+), 12 deletions(-)
fs/hostfs/hostfs.h +1 -0
index ea87e22..6bbd75c 100644
@@ -74,6 +74,7 @@ extern void *open_dir(char *path, int *err_out);
 extern char *read_dir(void *stream, unsigned long long *pos,
 		      unsigned long long *ino_out, int *len_out);
 extern void close_file(void *stream);
+extern int replace_file(int oldfd, int fd);
 extern void close_dir(void *stream);
 extern int read_file(int fd, unsigned long long *offset, char *buf, int len);
 extern int write_file(int fd, unsigned long long *offset, const char *buf,
fs/hostfs/hostfs_kern.c +31 -12

65 lines not on this page · raw message

fs/hostfs/hostfs_user.c +5 -0
index 91ebfce..6777aa0 100644
@@ -160,6 +160,11 @@ int fsync_file(int fd, int datasync)
 	return 0;
 }
 
+int replace_file(int oldfd, int fd)
+{
+	return dup2(oldfd, fd);
+}
+
 void close_file(void *stream)
 {
 	close(*((int *) stream));
Signature · 1 line
1.5.6.5