From ddfd2d44a6eab79c722f4b5785efdbcccb9c4d35 Mon Sep 17 00:00:00 2001 From: Miklos Szeredi Date: Thu, 20 Jun 2013 11:43:02 +0200 Subject: libfuse: fix multiple close of device fd - fuse_kern_unmount closes handle (e.g. 19) - a thread in my process opens a file - the OS assigns newly freed handle (i.e. 19) - fuse_kern_chan_destroy closes the same handle (i.e. 19) - a thread in my process opens another file - the OS assigns newly freed handle (i.e. 19) - * MAYHEM * Reported by Dan Greenfield --- ChangeLog | 5 +++++ lib/fuse_i.h | 2 ++ lib/fuse_session.c | 7 +++++++ lib/helper.c | 10 ++++++---- lib/mount.c | 12 ++++++++---- lib/mount_bsd.c | 9 ++++++--- 6 files changed, 34 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3afa404..2e902f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-06-20 Miklos Szeredi + + * libfuse: fix multiple close of device fd. Reported by Dan + Greenfield + 2013-03-19 Miklos Szeredi * libfuse: fix thread cancel race. Exiting a worker my race with diff --git a/lib/fuse_i.h b/lib/fuse_i.h index 78f1467..fa37156 100644 --- a/lib/fuse_i.h +++ b/lib/fuse_i.h @@ -106,6 +106,8 @@ struct fuse_session *fuse_lowlevel_new_common(struct fuse_args *args, size_t op_size, void *userdata); void fuse_kern_unmount_compat22(const char *mountpoint); +int fuse_chan_clearfd(struct fuse_chan *ch); + void fuse_kern_unmount(const char *mountpoint, int fd); int fuse_kern_mount(const char *mountpoint, struct fuse_args *args); diff --git a/lib/fuse_session.c b/lib/fuse_session.c index c55f250..6e11068 100644 --- a/lib/fuse_session.c +++ b/lib/fuse_session.c @@ -182,6 +182,13 @@ int fuse_chan_fd(struct fuse_chan *ch) return ch->fd; } +int fuse_chan_clearfd(struct fuse_chan *ch) +{ + int fd = ch->fd; + ch->fd = -1; + return fd; +} + size_t fuse_chan_bufsize(struct fuse_chan *ch) { return ch->bufsize; diff --git a/lib/helper.c b/lib/helper.c index ace19dd..b644012 100644 --- a/lib/helper.c +++ b/lib/helper.c @@ -249,10 +249,12 @@ struct fuse_chan *fuse_mount(const char *mountpoint, struct fuse_args *args) static void fuse_unmount_common(const char *mountpoint, struct fuse_chan *ch) { - int fd = ch ? fuse_chan_fd(ch) : -1; - fuse_kern_unmount(mountpoint, fd); - if (ch) - fuse_chan_destroy(ch); + if (mountpoint) { + int fd = ch ? fuse_chan_clearfd(ch) : -1; + fuse_kern_unmount(mountpoint, fd); + if (ch) + fuse_chan_destroy(ch); + } } void fuse_unmount(const char *mountpoint, struct fuse_chan *ch) diff --git a/lib/mount.c b/lib/mount.c index 6a9da9e..0f767c8 100644 --- a/lib/mount.c +++ b/lib/mount.c @@ -300,14 +300,18 @@ void fuse_kern_unmount(const char *mountpoint, int fd) pfd.fd = fd; pfd.events = 0; res = poll(&pfd, 1, 0); + + /* Need to close file descriptor, otherwise synchronous umount + would recurse into filesystem, and deadlock. + + Caller expects fuse_kern_unmount to close the fd, so close it + anyway. */ + close(fd); + /* If file poll returns POLLERR on the device file descriptor, then the filesystem is already unmounted */ if (res == 1 && (pfd.revents & POLLERR)) return; - - /* Need to close file descriptor, otherwise synchronous umount - would recurse into filesystem, and deadlock */ - close(fd); } if (geteuid() == 0) { diff --git a/lib/mount_bsd.c b/lib/mount_bsd.c index 62443ac..3aec3e3 100644 --- a/lib/mount_bsd.c +++ b/lib/mount_bsd.c @@ -228,18 +228,21 @@ void fuse_kern_unmount(const char *mountpoint, int fd) (void)mountpoint; if (fstat(fd, &sbuf) == -1) - return; + goto out; devname_r(sbuf.st_rdev, S_IFCHR, dev, 128); if (strncmp(dev, "fuse", 4)) - return; + goto out; strtol(dev + 4, &ep, 10); if (*ep != '\0') - return; + goto out; do_unmount(dev, fd); + +out: + close(fd); } /* Check if kernel is doing init in background */ -- cgit v1.2.3 From 014d950de766e1642de071d0a1d0b3e3de23b4f3 Mon Sep 17 00:00:00 2001 From: Miklos Szeredi Date: Mon, 1 Jul 2013 10:18:49 +0200 Subject: libfuse: don't close fd if it's -1 This prevents a valgrind warning. --- lib/fuse_kern_chan.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/fuse_kern_chan.c b/lib/fuse_kern_chan.c index 5f77bbf..4a9beb8 100644 --- a/lib/fuse_kern_chan.c +++ b/lib/fuse_kern_chan.c @@ -77,7 +77,10 @@ static int fuse_kern_chan_send(struct fuse_chan *ch, const struct iovec iov[], static void fuse_kern_chan_destroy(struct fuse_chan *ch) { - close(fuse_chan_fd(ch)); + int fd = fuse_chan_fd(ch); + + if (fd != -1) + close(fd); } #define MIN_BUFSIZE 0x21000 -- cgit v1.2.3 From d44bf3a4ac1ce1b56672ac9ae4a5caa3a8ee6844 Mon Sep 17 00:00:00 2001 From: Miklos Szeredi Date: Mon, 1 Jul 2013 10:48:51 +0200 Subject: Released 2.9.3 --- ChangeLog | 4 ++++ configure.ac | 2 +- lib/Makefile.am | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2e902f5..0da1bf7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2013-07-01 Miklos Szeredi + + * Released 2.9.3 + 2013-06-20 Miklos Szeredi * libfuse: fix multiple close of device fd. Reported by Dan diff --git a/configure.ac b/configure.ac index 0737bad..8963f2a 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT(fuse, 2.9.2) +AC_INIT(fuse, 2.9.3) AC_PREREQ(2.59d) AC_CONFIG_MACRO_DIR([m4]) diff --git a/lib/Makefile.am b/lib/Makefile.am index 3ec2401..87c0522 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -36,7 +36,7 @@ libfuse_la_SOURCES = \ $(iconv_source) \ $(mount_source) -libfuse_la_LDFLAGS = -pthread @libfuse_libs@ -version-number 2:9:2 \ +libfuse_la_LDFLAGS = -pthread @libfuse_libs@ -version-number 2:9:3 \ -Wl,--version-script,$(srcdir)/fuse_versionscript if NETBSD -- cgit v1.2.3 From 78bc1108d5537400f7df7f79f1dc27084b53323c Mon Sep 17 00:00:00 2001 From: Daniel Thau Date: Mon, 26 Aug 2013 11:57:16 +0200 Subject: Add missing includes This allows compiling fuse with musl. --- ChangeLog | 5 +++++ lib/fuse.c | 1 + lib/fuse_lowlevel.c | 1 + lib/mount_util.c | 1 + util/fusermount.c | 1 + 5 files changed, 9 insertions(+) diff --git a/ChangeLog b/ChangeLog index 0da1bf7..1b71fd4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-08-26 Miklos Szeredi + + * libfuse: Add missing includes. This allows compiling fuse with + musl. Patch by Daniel Thau + 2013-07-01 Miklos Szeredi * Released 2.9.3 diff --git a/lib/fuse.c b/lib/fuse.c index 067d0dc..cfac238 100644 --- a/lib/fuse.c +++ b/lib/fuse.c @@ -37,6 +37,7 @@ #include #include #include +#include #define FUSE_NODE_SLAB 1 diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c index 01efc6a..8853346 100644 --- a/lib/fuse_lowlevel.c +++ b/lib/fuse_lowlevel.c @@ -24,6 +24,7 @@ #include #include #include +#include #ifndef F_LINUX_SPECIFIC_BASE #define F_LINUX_SPECIFIC_BASE 1024 diff --git a/lib/mount_util.c b/lib/mount_util.c index 3d2f4cd..3cad2e6 100644 --- a/lib/mount_util.c +++ b/lib/mount_util.c @@ -16,6 +16,7 @@ #include #include #include +#include #ifndef __NetBSD__ #include #endif diff --git a/util/fusermount.c b/util/fusermount.c index b2e87d9..4fc72ed 100644 --- a/util/fusermount.c +++ b/util/fusermount.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include -- cgit v1.2.3