fix
authorMiklos Szeredi <miklos@szeredi.hu>
Tue, 22 Nov 2005 19:20:18 +0000 (19:20 +0000)
committerMiklos Szeredi <miklos@szeredi.hu>
Tue, 22 Nov 2005 19:20:18 +0000 (19:20 +0000)
ChangeLog
configure.in
kernel/configure.ac
lib/Makefile.am
lib/fuse.c
lib/mount.c
util/fusermount.c

index 947ef87d62085701e9683a64e4da4ca83f58f535..e4379d66f3a600c80e34a14815f27eb5a2a8af3f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,30 @@
+2005-11-22  Miklos Szeredi <miklos@szeredi.hu>
+
+       * Released 2.4.2
+
+2005-11-22  Miklos Szeredi <miklos@szeredi.hu>
+
+       * Add detection of mainline FUSE code in running kernel
+
+2005-11-17  Miklos Szeredi <miklos@szeredi.hu>
+
+       * fusermount: don't allow mountpoints with '\n', '\t', or '\\' in
+       them, because it corrupts /etc/mtab.  Found by Thomas Biege
+       CVE-2005-3531
+
+       * libfuse: don't use system() to invoke 'fusermount -u ...'
+       because it breaks mountpoints with spaces in them into multiple
+       arguments
+
+2005-10-26  Miklos Szeredi <miklos@szeredi.hu>
+
+       * Fix kernel module compile if kernel source and build directories
+       differ.  Report and initial patch by John Eastman
+
+2005-10-18  Miklos Szeredi <miklos@szeredi.hu>
+
+       * lib: optimize buffer reallocation in fill_dir.
+
 2005-10-17  Miklos Szeredi <miklos@szeredi.hu>
 
        * Released 2.4.1
index 8cc5c659e7d850cbb4708f361e4761eeab0f6aff..34086155b16fd54519ea5a481a452d3028c3e145 100644 (file)
@@ -1,4 +1,4 @@
-AC_INIT(fuse, 2.4.1)
+AC_INIT(fuse, 2.4.2)
 AM_INIT_AUTOMAKE
 AM_CONFIG_HEADER(include/config.h)
 
index 5f31daa7a2e2b2be1026d0648b5b4ffad8955613..9800b3cfd8136022e92703a035ae229719ef7046 100644 (file)
-AC_INIT(fuse-kernel, 2.4.1)
+AC_INIT(fuse-kernel, 2.4.2)
 AC_CONFIG_HEADERS([config.h])
 
 AC_PROG_INSTALL
 
-AC_MSG_CHECKING([kernel source directory])
+runver=`uname -r`
+ENABLE_FUSE_MODULE=y
+
 kernelsrc=
+kernelbuild=
 AC_ARG_WITH(kernel,
        [  --with-kernel=PATH      Specify location of kernel source ],
-       [kernelsrc="$withval"])
+       [kernelsrc="$withval"; kernelbuild="$withval"])
+AC_ARG_WITH(kernel-build,
+       [  --with-kernel-build=PATH Specify location of kernel build ],
+       [kernelbuild="$withval"])
+AC_ARG_ENABLE(kernel-module,
+       [  --enable-kernel-module  Compile kernel module ])
 
-if test -z "$kernelsrc"; then
-       buildlink=/lib/modules/`uname -r`/build
-       if test -e $buildlink; then
-               kernelsrc=`(cd $buildlink; /bin/pwd)`
+if test -z "$enable_kernel_module" -a -z "$kernelbuild" && echo "$runver" | grep -q "^2.6"; then
+       checkmodule=no
+       AC_MSG_CHECKING([if FUSE is loaded as a module])
+       if cat /proc/modules | grep -q "^fuse "; then
+               AC_MSG_RESULT([yes])
+               checkmodule=yes
        else
-               AC_MSG_RESULT([Not found])
-               AC_MSG_ERROR([
-*** Please specify the location of the kernel source with
-*** the '--with-kernel=SRCDIR' option])
+               AC_MSG_RESULT([no])
+               AC_MSG_CHECKING([if FUSE module is built into the kernel])
+               if test -e /sys/class/misc/fuse; then
+                       AC_MSG_RESULT([yes])
+                       ENABLE_FUSE_MODULE=n
+               else
+                       AC_MSG_RESULT([no])
+                       checkmodule=yes
+               fi
+       fi
+       if test "$checkmodule" = yes; then
+               AC_MSG_CHECKING([if FUSE module is from official kernel])
+                       if fgrep -q "fuse distribution version: " /lib/modules/${runver}/kernel/fs/fuse/fuse.ko 2> /dev/null; then
+                       AC_MSG_RESULT([no])
+               else
+                       AC_MSG_RESULT([yes])
+                       ENABLE_FUSE_MODULE=n
+               fi
        fi
 fi
-AC_MSG_RESULT([$kernelsrc])
 
-AC_ARG_ENABLE(kernel-module,
-       [  --enable-kernel-module  Compile kernel module ])
-
-AC_MSG_CHECKING([kernel source version])
-if test -r $kernelsrc/include/linux/version.h; then
-       kernsrcver=`(echo "#include <linux/version.h>"; echo "kernsrcver=UTS_RELEASE") | cpp -I $kernelsrc/include | grep "^kernsrcver=" | cut -d \" -f 2`
-fi
-if test -z "$kernsrcver"; then
-       AC_MSG_RESULT([Not found])
-       AC_MSG_ERROR([
-*** Cannot determine the version of the linux kernel source. Please
-*** configure the kernel before running this script])
-fi
-AC_MSG_RESULT([$kernsrcver])
-majver=`echo "$kernsrcver" | cut -f-2 -d.`
-kmoduledir=${INSTALL_MOD_PATH}/lib/modules/$kernsrcver
-AC_SUBST(kernelsrc)
-AC_SUBST(majver)
-AC_SUBST(kmoduledir)
+if test "$ENABLE_FUSE_MODULE" = y; then
+       AC_MSG_CHECKING([kernel source directory])
+       if test -z "$kernelsrc"; then
+               kernelbuild=
+               sourcelink=/lib/modules/${runver}/source
+               buildlink=/lib/modules/${runver}/build
 
-ENABLE_FUSE_MODULE=y
-if echo "$kernsrcver" | grep -q "^2.4"; then
-               old_cflags="$CFLAGS"
-               CFLAGS="-I${kernelsrc}/include -Wall -O2 -fno-strict-aliasing -D__KERNEL__"
-       AC_CHECK_DECL(i_size_read,
-               AC_DEFINE(HAVE_I_SIZE_FUNC, 1,
-                       [Kernel has i_size_read() and i_size_write() functions]),,
-               [#include <linux/fs.h>])
-       AC_CHECK_DECL(recalc_sigpending_tsk,
-               AC_DEFINE(HAVE_RECALC_SIGPENDING_TSK, 1,
-                       [Kernel has recalc_sigpending_tsk() function]),,
-               [#include <linux/sched.h>])
-       CFLAGS="$old_cflags"
-else
-       fuse_configured=no
-       kernel_autoconf=$kernelsrc/include/linux/autoconf.h
-       AC_MSG_CHECKING([if FUSE is configured in the kernel])
-       if test -f $kernel_autoconf; then
-               if grep -q "^#define CONFIG_FUSE_FS 1" $kernel_autoconf || grep -q "^#define CONFIG_FUSE_FS_MODULE 1" $kernel_autoconf; then
-                       fuse_configured=yes
+               if test -e $sourcelink; then
+                       kernelsrc=`(cd $sourcelink; /bin/pwd)`
+               fi
+               if test -e $buildlink; then
+                       kernelbuild=`(cd $buildlink; /bin/pwd)`
+               fi
+               if test -z "$kernelsrc"; then
+                       kernelsrc=$kernelbuild
                fi
+               if test -z "$kernelsrc" -o -z "$kernelbuild"; then
+                       AC_MSG_RESULT([Not found])
+                       AC_MSG_ERROR([
+       *** Please specify the location of the kernel source with
+       *** the '--with-kernel=SRCDIR' option])
+               fi
+       fi
+       AC_MSG_RESULT([$kernelsrc])
+       AC_MSG_CHECKING([kernel build directory])
+       AC_MSG_RESULT([$kernelbuild])
+
+       AC_MSG_CHECKING([kernel source version])
+       if test -r $kernelbuild/include/linux/version.h; then
+               kernsrcver=`(echo "#include <linux/version.h>"; echo "kernsrcver=UTS_RELEASE") | cpp -I $kernelbuild/include | grep "^kernsrcver=" | cut -d \" -f 2`
+       fi
+       if test -z "$kernsrcver"; then
+               AC_MSG_RESULT([Not found])
+               AC_MSG_ERROR([
+       *** Cannot determine the version of the linux kernel source. Please
+       *** configure the kernel before running this script])
        fi
-       AC_MSG_RESULT([$fuse_configured])
-       if test -z "$enable_kernel_module" -a "$fuse_configured" = yes; then
-               ENABLE_FUSE_MODULE=n
-               AC_MSG_NOTICE([NOTE:     Detected that FUSE is already present in the kernel, so])
-               AC_MSG_NOTICE([NOTE:     building of kernel module is disabled.  To force building])
-               AC_MSG_NOTICE([NOTE:     of kernel module use the '--enable-kernel-module' option.])
+       AC_MSG_RESULT([$kernsrcver])
+       majver=`echo "$kernsrcver" | cut -f-2 -d.`
+       kmoduledir=${INSTALL_MOD_PATH}/lib/modules/$kernsrcver
+       AC_SUBST(kernelsrc)
+       AC_SUBST(majver)
+       AC_SUBST(kmoduledir)
+
+       if echo "$kernsrcver" | grep -q "^2.4"; then
+               old_cflags="$CFLAGS"
+               CFLAGS="-I${kernelsrc}/include -Wall -O2 -fno-strict-aliasing -D__KERNEL__"
+               AC_CHECK_DECL(i_size_read,
+                       AC_DEFINE(HAVE_I_SIZE_FUNC, 1,
+                               [Kernel has i_size_read() and i_size_write() functions]),,
+                       [#include <linux/fs.h>])
+               AC_CHECK_DECL(recalc_sigpending_tsk,
+                       AC_DEFINE(HAVE_RECALC_SIGPENDING_TSK, 1,
+                               [Kernel has recalc_sigpending_tsk() function]),,
+                       [#include <linux/sched.h>])
+               CFLAGS="$old_cflags"
+       else
+               fuse_configured=no
+               kernel_autoconf=$kernelbuild/include/linux/autoconf.h
+               AC_MSG_CHECKING([if FUSE is configured in the kernel])
+               if test -f $kernel_autoconf; then
+                       if grep -q "^#define CONFIG_FUSE_FS 1" $kernel_autoconf || grep -q "^#define CONFIG_FUSE_FS_MODULE 1" $kernel_autoconf; then
+                               fuse_configured=yes
+                       fi
+               fi
+               AC_MSG_RESULT([$fuse_configured])
+               if test -z "$enable_kernel_module" -a "$fuse_configured" = yes; then
+                       ENABLE_FUSE_MODULE=n
+               fi
        fi
 fi
+
+if test "$ENABLE_FUSE_MODULE" = n; then
+       AC_MSG_NOTICE([NOTE:     Detected that FUSE is already present in the kernel, so])
+       AC_MSG_NOTICE([NOTE:     building of kernel module is disabled.  To force building])
+       AC_MSG_NOTICE([NOTE:     of kernel module use the '--enable-kernel-module' option.])
+fi
+
 if test "$enable_kernel_module" = no; then
        ENABLE_FUSE_MODULE=n
 fi
@@ -87,16 +138,27 @@ if test "$ENABLE_FUSE_MODULE" = y; then
                AC_MSG_RESULT([no])
        fi
 
+       AC_MSG_CHECKING([whether lookup_instantiate_filp is defined])
+       if test -f $kernelsrc/include/linux/namei.h && egrep -q "lookup_instantiate_filp" $kernelsrc/include/linux/namei.h; then
+               AC_DEFINE(HAVE_LOOKUP_INSTANTIATE_FILP, 1, [lookup_instantiate_filp() is defined])
+               AC_MSG_RESULT([yes])
+       else
+               AC_MSG_RESULT([no])
+       fi
+
        isuml=no
        KERNELMAKE_PARAMS=
        KERNELCPPFLAGS=
        AC_MSG_CHECKING([if this is user mode linux])
-       if test -f $kernelsrc/include/linux/autoconf.h && egrep -q "^#define CONFIG_(USERMODE|UML) 1" $kernelsrc/include/linux/autoconf.h; then
+       if test -f $kernelbuild/include/linux/autoconf.h && egrep -q "^#define CONFIG_(USERMODE|UML) 1" $kernelbuild/include/linux/autoconf.h; then
                isuml=yes
                KERNELMAKE_PARAMS="ARCH=um"
                KERNELCPPFLAGS="-D__arch_um__ -DSUBARCH=\\\"i386\\\" -D_LARGEFILE64_SOURCE -I${kernelsrc}/arch/um/include -Derrno=kernel_errno -I${kernelsrc}/arch/um/kernel/tt/include -I${kernelsrc}/arch/um/kernel/skas/include"
        fi
        AC_MSG_RESULT([$isuml])
+       if test "$kernelbuild" != "$kernelsrc"; then
+               KERNELMAKE_PARAMS="$KERNELMAKE_PARAMS O=$kernelbuild"
+       fi
        AC_SUBST(KERNELMAKE_PARAMS)
        AC_SUBST(KERNELCPPFLAGS)
 fi
index 2d81fb00a894ed1235174fd37c1d4f08daeee2c9..5bb87d288bb0221e18539e0734238642cd7b784d 100644 (file)
@@ -14,7 +14,7 @@ libfuse_la_SOURCES =          \
        helper.c                \
        mount.c
 
-libfuse_la_LDFLAGS = -lpthread -version-number 2:4:1 \
+libfuse_la_LDFLAGS = -lpthread -version-number 2:4:2 \
        -Wl,--version-script,fuse_versionscript
 
 EXTRA_DIST = fuse_versionscript
index e44b9f2859926af2bd7240367660c26c0988c3c0..b0cf5530ad360c8ee3f69f0b6befaf3c8156bad4 100644 (file)
@@ -103,6 +103,7 @@ struct fuse_dirhandle {
     char *contents;
     int allocated;
     unsigned len;
+    unsigned size;
     unsigned needlen;
     int filled;
     unsigned long fh;
@@ -1261,7 +1262,6 @@ static int fill_dir_common(struct fuse_dirhandle *dh, const char *name,
     unsigned namelen = strlen(name);
     unsigned entsize;
     unsigned newlen;
-    char *newptr;
 
     if (statp)
         stbuf = *statp;
@@ -1291,12 +1291,21 @@ static int fill_dir_common(struct fuse_dirhandle *dh, const char *name,
             return 1;
     }
 
-    newptr = (char *) realloc(dh->contents, newlen);
-    if (!newptr) {
-        dh->error = -ENOMEM;
-        return 1;
+    if (newlen > dh->size) {
+        char *newptr;
+
+        if (!dh->size)
+            dh->size = 1024;
+        while (newlen > dh->size)
+            dh->size *= 2;
+
+        newptr = (char *) realloc(dh->contents, dh->size);
+        if (!newptr) {
+            dh->error = -ENOMEM;
+            return 1;
+        }
+        dh->contents = newptr;
     }
-    dh->contents = newptr;
     fuse_add_dirent(dh->contents + dh->len, name, &stbuf, off ? off : newlen);
     dh->len = newlen;
     return 0;
index f7a5299949639ab8cfaa349fe07ac7b9a58f8225..572aacad5ce67a859f27649779028c9f97f1abf8 100644 (file)
@@ -70,13 +70,32 @@ static int receive_fd(int fd)
 void fuse_unmount(const char *mountpoint)
 {
     const char *mountprog = FUSERMOUNT_PROG;
-    char umount_cmd[1024];
+    int pid;
 
-    snprintf(umount_cmd, sizeof(umount_cmd) - 1, "%s -u -q -z -- %s",
-             mountprog, mountpoint);
+#ifdef HAVE_FORK
+    pid = fork();
+#else
+    pid = vfork();
+#endif
+    if(pid == -1)
+        return;
+
+    if(pid == 0) {
+        const char *argv[32];
+        int a = 0;
 
-    umount_cmd[sizeof(umount_cmd) - 1] = '\0';
-    system(umount_cmd);
+        argv[a++] = mountprog;
+        argv[a++] = "-u";
+        argv[a++] = "-q";
+        argv[a++] = "-z";
+        argv[a++] = "--";
+        argv[a++] = mountpoint;
+        argv[a++] = NULL;
+
+        execvp(mountprog, (char **) argv);
+        exit(1);
+    }
+    waitpid(pid, NULL, 0);
 }
 
 int fuse_mount(const char *mountpoint, const char *opts)
index 742a25f1ef8fc3e442e44d17aee92755a768774c..8d5562e93a6ad08e12f68624de9e1850650169b6 100644 (file)
@@ -120,6 +120,23 @@ static void unlock_mtab(int mtablock)
     }
 }
 
+/* Glibc addmntent() doesn't encode '\n', misencodes '\t' as '\n'
+   (version 2.3.2), and encodes '\\' differently as mount(8).  So
+   let's not allow those characters, they are not all that usual in
+   filenames. */
+static int check_name(const char *name)
+{
+    char *s;
+    for (s = "\n\t\\"; *s; s++) {
+        if (strchr(name, *s)) {
+            fprintf(stderr, "%s: illegal character 0x%02x in mount entry\n",
+                    progname, *s);
+            return -1;
+        }
+    }
+    return 0;
+}
+
 static int add_mount(const char *fsname, const char *mnt, const char *type,
                      const char *opts)
 {
@@ -128,6 +145,10 @@ static int add_mount(const char *fsname, const char *mnt, const char *type,
     struct mntent ent;
     FILE *fp;
 
+    if (check_name(fsname) == -1 || check_name(mnt) == -1 || 
+        check_name(type) == -1 || check_name(opts) == -1)
+        return -1;
+
     fp = setmntent(mtab, "a");
     if (fp == NULL) {
        fprintf(stderr, "%s: failed to open %s: %s\n", progname, mtab,