Commit Graph

214 Commits

Author SHA1 Message Date
psycho c99f6182b4 libfuse升级
Signed-off-by: psycho <wangmingxuan6@h-partners.com>
2024-01-09 09:19:42 +08:00
lixiaokeng cb1157bc0d Fix: fd and memory leak in mount.fuse.c (#614)
The command isn't freed and the fuse_fd isn't
closed if execl failed. Fix it.

Signed-off-by: Lixiaokeng <lixiaokeng@huawei.com>
2021-09-06 13:37:45 +01:00
a1346054 1f0df336d9 use same hashbang as in rest of repository 2021-08-25 14:46:25 +02:00
Stephen Kitt ce22e48a8c Ignore "-o nonempty" (#582)
Commit 0bef21e854 removed "-o nonempty" since mounting over
non-empty directories is always allowed. But this broke tools which
specify "-o nonempty". Since the expected behaviour is the same
anyway, ignoring the "nonempty" option seems safe, and allows programs
specifying "-o nonempty" to continue working with fusermount3.

This would fix https://bugs.debian.org/939767

Signed-off-by: Stephen Kitt <steve@sk2.org>
2021-01-28 21:51:10 +00:00
richardweinberger c041da9d41 fusermount: Check for argv[0] being present (#577)
It is perfectly legal to execute a program with argc == 0 and therefore
no argv.
fusermount needs to check for this case, otherwise it will pass a NULL
poiunter to strdup() and cause undefined behavior.
Especially since fusermount is setuid root, we need to extra be careful.

Signed-off-by: Richard Weinberger <richard@nod.at>
2021-01-08 10:07:02 +00:00
Sargun Dhillon 7819d2f04c util/fusermount.c: Assume the kernel supports UMOUNT_NOFOLLOW (#574)
UMOUNT_NOFOLLOW was added in Kernel 2.6.34. It's been 10 years since it's been added
Kernel 5.9, and 5.10 break this check mechanism[1]. Let's deprecate it.

[1]: https://lore.kernel.org/linux-fsdevel/20201223102604.2078-1-sargun@sargun.me/

Signed-off-by: Sargun Dhillon <sargun@sargun.me>
2020-12-27 11:17:46 +00:00
Kangjing "Chaser" Huang 20abadd1ce Add exfat to whitelist (#573) 2020-12-19 10:43:19 +00:00
Zhiqiang Liu 4c4153c3a7 mount.fuse.c: fix potential memory leak in main func
In mount.fuse.c, there are several memory leak problems in
main func. For example, setuid_name is allocated by calling
xstrdup func, however it is not freed before calling execl func.

Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Signed-off-by: Haotian Li <lihaotian9@huawei.com>
2020-11-06 19:26:03 +00:00
Zhiqiang Liu ad923849da mount.fuse.c: fix potential accessing NULL pointer
In mount.fuse.c, pwd is set by calling getpwnam func.
If the matching entry is not found or an error occurs in
getpwnam func, pwd will be NULL. So we need to check
whether pwd is NULL before accessing it.

Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Signed-off-by: Haotian Li <lihaotian9@huawei.com>
2020-11-06 19:26:03 +00:00
Andrew Gaul 2f49f1bc0a Align help options (#500) 2020-03-13 16:48:09 +00:00
Dr. David Alan Gilbert 4e719a9745 State GPL version in comment (#485)
IN a bunch of comments we say 'under the terms of the GNU GPL', make
it clear this is GPLv2 (as LICENSE says).

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
2020-03-13 16:46:44 +00:00
Bill Zissimopoulos f340eb3d5d Make ioctl prototype conditional on FUSE_USE_VERSION. (#482)
Define FUSE_USE_VERSION < 35 to get old ioctl prototype
with int commands; define FUSE_USE_VERSION >= 35 to get
new ioctl prototype with unsigned int commands.

Fixes #463.
2019-12-31 09:58:57 +00:00
tenzap 6762e02dae Whitelist UFSD (#451) 2019-09-15 08:56:56 -07:00
Nikolaus Rath bd12e87931 Install init script in /etc/ instead of $sysconfdir
sysconfdir defaults to /usr/local/etc which is almost always the wrong
choice.

Fixes: #427
2019-07-09 05:15:09 -07:00
DrDaveD be8db96603 Add build option to skip steps requiring root permissions 2019-07-04 09:02:30 +01:00
Michael Forney f0c52798b7 Fix build with IGNORE_MTAB (#425)
chdir_to_parent and check_is_mount are used by should_auto_mount, added
in fuse-3.3.0, regardless of whether IGNORE_MTAB is defined.
2019-06-15 11:16:45 +01:00
DrDaveD 625ed81b82 add defines for missing SECBITs on older kernels (#409) 2019-05-05 14:15:13 -04:00
Peter Lemenkov 4ebf27a4e8 Whitelist smb2 (#392)
See also https://bugzilla.redhat.com/1694552#c7
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
2019-04-03 21:43:48 +01:00
1c7718e7 9e6cdc2c0c Add HFS+ to filesystem whitelist (#347) 2019-03-09 10:39:32 +00:00
Nikolaus Rath 1c70c870fe Correctly include config.h ("" vs <>)
This isn't a system header.

Fixes: #349
2019-03-09 10:31:18 +00:00
Sam Huffman 774eb66fc1 fusermount: drop privileges for chdir()
cd to mountpoint's parent directory using unprivileged rather than 
privileged access. This is to ensure that unmount works on mountpoints
where root may not have privileged access.

Fixes: #376
2019-03-08 21:26:31 +00:00
Nikolaus Rath e7909ad648 Added OpenAFS to type whitelist
Fixes: #336.
2019-01-04 13:33:01 +00:00
Niels de Vos 2548c4b83a examples: add copy_file_range() support to passthrough(_fh)
The passthrough example filesystem can be used for validating the API
and the implementation in the FUSE kernel module.
2018-11-19 12:33:56 +00:00
Kevin Vigor b73fd61344 Avoid double unmount on normal unmount in auto_unmount mode.
If a fuse filesystem was mounted in auto_unmount mode on top of an
already mounted filesystem, we would end up doing a double-unmount
when the fuse filesystem was unmounted properly.

Make the auto_unmount code less eager: unmount only if the mounted
filesystem has proper type and is returning 'Transport endpoint not
connected'.
2018-11-06 18:50:07 +00:00
Valentin Plugaru c779a4ee2b Add SpectrumScale/GPFS and Lustre to FS whitelist
Fixes: #304 
Signed-off-by: Valentin Plugaru <valentin.plugaru@uni.lu>
2018-10-19 14:19:28 -07:00
Mattias Nissler da7c9b228a Add unprivileged option in mount.fuse3
The unprivileged option allows to run the FUSE file system process
without privileges by dropping capabilities and preventing them from
being re-acquired via setuid / fscaps etc. To accomplish this,
mount.fuse sets up the `/dev/fuse` file descriptor and mount itself
and passes the file descriptor via the `/dev/fd/%u` mountpoint syntax
to the FUSE file system.
2018-10-09 20:36:22 +01:00
Nikolaus Rath d9bef3c6e4 Don't special-case bulid of mount_util.c.
We already support out of source builds without this.
2018-09-17 10:35:50 +01:00
Nikolaus Rath d709f31923 Do not hardcode /etc/fuse.conf path. 2018-08-31 13:46:13 +02:00
Daniel Fullmer 20aef732d4 Add bcachefs to mountpoint file system whitelist 2018-08-09 19:15:45 +01:00
Benjamin Barenblat 9b28737734 Add FAT to mountpoint file system whitelist 2018-08-05 10:33:27 +01:00
Benjamin Barenblat 0490aef161 Realphabetize and re-document mountpoint file system whitelist 2018-08-05 10:33:27 +01:00
Robo Shimmer 0ef031bfc0 Add autofs to mountpoint file system whitelist 2018-07-31 15:20:56 +01:00
Rostislav Skudnov efa3032bc9 fusermount: Fix memory leaks 2018-07-23 11:02:57 +01:00
Jann Horn 795ad5d774 fusermount: whitelist known-good filesystems for mountpoints
Before:

$ _FUSE_COMMFD=1 priv_strace -s8000 -e trace=mount util/fusermount3 /proc/self/fd
mount("/dev/fuse", ".", "fuse", MS_NOSUID|MS_NODEV, "fd=3,rootmode=40000,user_id=379777,group_id=5001") = 0
sending file descriptor: Socket operation on non-socket
+++ exited with 1 +++

After:

$ _FUSE_COMMFD=1 priv_strace -s8000 -e trace=mount util/fusermount3 /proc/self/fd
util/fusermount3: mounting over filesystem type 0x009fa0 is forbidden
+++ exited with 1 +++

This patch could potentially have security
impact on some systems that are configured with allow_other;
see https://launchpad.net/bugs/1530566 for an example of how a similar
issue in the ecryptfs mount helper was exploitable. However, the FUSE
mount helper performs slightly different security checks, so that exact
attack doesn't work with fusermount; I don't know of any specific attack
you could perform using this, apart from faking the SELinux context of your
process when someone's looking at a process listing. Potential targets for
overwrite are (looking on a system with a 4.9 kernel):

writable only for the current process:
/proc/self/{fd,map_files}
(Yes, "ls -l" claims that you don't have write access, but that's not true;
"find -writable" will show you what access you really have.)

writable also for other owned processes:
/proc/$pid/{sched,autogroup,comm,mem,clear_refs,attr/*,oom_adj,
oom_score_adj,loginuid,coredump_filter,uid_map,gid_map,projid_map,
setgroups,timerslack_ns}
2018-07-18 20:32:28 +01:00
Jann Horn 5018a0c016 fusermount: refuse unknown options
Blacklists are notoriously fragile; especially if the kernel wishes to add
some security-critical mount option at a later date, all existing systems
with older versions of fusermount installed will suddenly have a security
problem.
Additionally, if the kernel's option parsing became a tiny bit laxer, the
blacklist could probably be bypassed.

Whitelist known-harmless flags instead, even if it's slightly more
inconvenient.
2018-07-18 20:32:28 +01:00
Jann Horn cc315f5aa7 fusermount: bail out on transient config read failure
If an attacker wishes to use the default configuration instead of the
system's actual configuration, they can attempt to trigger a failure in
read_conf(). This only permits increasing mount_max if it is lower than the
default, so it's not particularly interesting. Still, this should probably
be prevented robustly; bail out if funny stuff happens when we're trying to
read the config.

Note that the classic attack trick of opening so many files that the
system-wide limit is reached won't work here - because fusermount only
drops the fsuid, not the euid, the process is running with euid=0 and
CAP_SYS_ADMIN, so it bypasses the number-of-globally-open-files check in
get_empty_filp() (unless you're inside a user namespace).
2018-07-18 20:32:28 +01:00
Jann Horn 28bdae3d11 fusermount: don't feed "escaped commas" into mount options
The old code permits the following behavior:

$ _FUSE_COMMFD=10000 priv_strace -etrace=mount -s200 fusermount -o 'foobar=\,allow_other' mount
mount("/dev/fuse", ".", "fuse", MS_NOSUID|MS_NODEV, "foobar=\\,allow_other,fd=3,rootmode=40000,user_id=1000,group_id=1000") = -1 EINVAL (Invalid argument)

However, backslashes do not have any special meaning for the kernel here.

As it happens, you can't abuse this because there is no FUSE mount option
that takes a string value that can contain backslashes; but this is very
brittle. Don't interpret "escape characters" in places where they don't
work.
2018-07-18 20:32:28 +01:00
Jann Horn 34c62ee90c fusermount: prevent silent truncation of mount options
Currently, in the kernel, copy_mount_options() copies in one page of
userspace memory (or less if some of that memory area is not mapped).
do_mount() then writes a null byte to the last byte of the copied page.
This means that mount option strings longer than PAGE_SIZE-1 bytes get
truncated silently.

Therefore, this can happen:

user@d9-ut:~$ _FUSE_COMMFD=10000 fusermount -o "$(perl -e 'print ","x4000')" mount
sending file descriptor: Bad file descriptor
user@d9-ut:~$ grep /mount /proc/mounts
/dev/fuse /home/user/mount fuse rw,nosuid,nodev,relatime,user_id=1000,group_id=1000 0 0
user@d9-ut:~$ fusermount -u mount
user@d9-ut:~$ _FUSE_COMMFD=10000 fusermount -o "$(perl -e 'print ","x4050')" mount
sending file descriptor: Bad file descriptor
user@d9-ut:~$ grep /mount /proc/mounts
/dev/fuse /home/user/mount fuse rw,nosuid,nodev,relatime,user_id=1000,group_id=100 0 0
user@d9-ut:~$ fusermount -u mount
user@d9-ut:~$ _FUSE_COMMFD=10000 fusermount -o "$(perl -e 'print ","x4051')" mount
sending file descriptor: Bad file descriptor
user@d9-ut:~$ grep /mount /proc/mounts
/dev/fuse /home/user/mount fuse rw,nosuid,nodev,relatime,user_id=1000,group_id=10 0 0
user@d9-ut:~$ fusermount -u mount
user@d9-ut:~$ _FUSE_COMMFD=10000 fusermount -o "$(perl -e 'print ","x4052')" mount
sending file descriptor: Bad file descriptor
user@d9-ut:~$ grep /mount /proc/mounts
/dev/fuse /home/user/mount fuse rw,nosuid,nodev,relatime,user_id=1000,group_id=1 0 0
user@d9-ut:~$ fusermount -u mount

I'm not aware of any context in which this is actually exploitable - you'd
still need the UIDs to fit, and you can't do it if the three GIDs of the
process don't match (in the case of a typical setgid binary), but it does
look like something that should be fixed.

I also plan to try to get this fixed on the kernel side.
2018-07-18 20:32:28 +01:00
Laszlo Boszormenyi (GCS) edb0c09bbe Source LSB init functions 2018-07-04 19:52:32 +01:00
Nikolaus Rath 44deb68ce1 add_arg(): check for overflow
Fixes: #222.
2018-05-11 15:01:04 +01:00
Tomohiro Kusumi 27a112e86d Fix compile-time warnings on IGNORE_MTAB
Silence below warnings which appear if IGNORE_MTAB is defined.

[59/64] Compiling C object 'util/fusermount3@exe/fusermount.c.o'.
../util/fusermount.c:493:12: warning: function declaration isn't a prototype [-Wstrict-prototypes]
 static int count_fuse_fs()
            ^~~~~~~~~~~~~
../util/fusermount.c: In function 'unmount_fuse':
../util/fusermount.c:508:46: warning: unused parameter 'quiet' [-Wunused-parameter]
 static int unmount_fuse(const char *mnt, int quiet, int lazy)
                                              ^~~~~
2018-05-08 19:36:52 +01:00
admorgan 14a20f9f1d Add example configuration file (#216)
Add a configuration file with all options disabled that includes
all valid options and their description.
2018-03-28 20:38:26 +01:00
Josh Soref a83cd72f64 Handle mount ... -o nofail (#221)
Accept (and ignore) nofail mount option
2017-12-01 19:18:49 +00:00
Joerg Thalheim 2a3929bbe0 make udevrulesdir configurable
on nixos we install fuse in its own hierarchy independent from systemd.
2017-10-20 08:42:30 +01:00
Nikolaus Rath 30ead3a5cf Dropped support for building with autotools
It's just too much pain to keep it working.
2017-08-24 20:50:44 +02:00
Nikolaus Rath a42e548d76 Fixed udev rules directory. 2017-08-14 10:26:51 +02:00
Heiko Becker f0ecf0c3e7 Ask pkgconfig where we should install udev rules 2017-08-02 20:36:11 +02:00
Nikolaus Rath 31ebb7b975 Don't use emacs' python-mode for meson files
There is a proper meson-mode now.
2017-07-07 15:48:50 +02:00
Nikolaus Rath b400c4f95b Install init script in $DESTDIR/etc, not $prefix/$sysconfdir
Fixes: #178.
2017-06-21 15:42:38 -07:00
Nikolaus Rath 9f96db7125 Added experimental support for building with Meson+Ninja 2017-01-12 15:19:04 -08:00