* Fuse mount: make auto_unmount compatible with suid/dev mount options
> When you run as root, fuse normally does not call fusermount but uses
> the mount system call directly. When you specify auto_unmount, it goes
> through fusermount instead. However, fusermount is a setuid binary that
> is normally called by regular users, so it cannot in general accept suid
> or dev options.
In this patch, we split up how fuse mounts as root when `auto_unmount`
is specified.
First, we mount using system calls directly, then we reach out to
fusermount to set up auto_unmount only (with no actual mounting done in
fusermount).
Fixes: #148
Before:
```
=============================== warnings summary ===============================
test/test_ctests.py:12
/tmp/libfuse-build-mB50ZC/build-gcc-9/test/test_ctests.py:12: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
from distutils.version import LooseVersion
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
```
```
test_examples.py::test_printcap
/usr/local/lib/python3.9/dist-packages/_pytest/python.py:199: PytestReturnNotNoneWarning: Expected None, but test_examples.py::test_printcap returned ((7, 38), {'FUSE_CAP_READDIRPLUS_AUTO', 'FUSE_CAP_ASYNC_DIO', 'FUSE_CAP_SPLICE_READ', 'FUSE_CAP_CACHE_SYMLINKS', 'FUSE_CAP_IOCTL_DIR', 'FUSE_CAP_NO_OPENDIR_SUPPORT', 'FUSE_CAP_NO_OPEN_SUPPORT', 'FUSE_CAP_POSIX_LOCKS', 'FUSE_CAP_READDIRPLUS', 'FUSE_CAP_POSIX_ACL', 'FUSE_CAP_ATOMIC_O_TRUNC', 'FUSE_CAP_SPLICE_MOVE', 'FUSE_CAP_EXPORT_SUPPORT', 'FUSE_CAP_FLOCK_LOCKS', 'FUSE_CAP_EXPLICIT_INVAL_DATA', 'FUSE_CAP_EXPIRE_ONLY', 'FUSE_CAP_DONT_MASK', 'FUSE_CAP_WRITEBACK_CACHE', 'FUSE_CAP_AUTO_INVAL_DATA', 'FUSE_CAP_PARALLEL_DIROPS', 'FUSE_CAP_SPLICE_WRITE', 'FUSE_CAP_ASYNC_READ'}), which will be an error in a future version of pytest. Did you mean to use `assert` instead of `return`?
warnings.warn(
```
This addresses: https://github.com/libfuse/libfuse/issues/724
HAVE_LIBC_VERSIONED_SYMBOLS configures the library if to use
versioned symbols and is set at meson configuration time.
External filesystems (the main target, actually)
include fuse headers and the preprocessor
then acts on HAVE_LIBC_VERSIONED_SYMBOLS. Problem was now that
'config.h' was not distributed with libfuse and so
HAVE_LIBC_VERSIONED_SYMBOLS was never defined with external
tools and the preprocessor did the wrong decision.
This commit also increases the the minimal meson version,
as this depends on meson feature only available in 0.50
<quote 'meson' >
WARNING: Project specifies a minimum meson_
version '>= 0.42' but uses features which were added
in newer versions:
* 0.50.0: {'install arg in configure_file'}
</quote>
Additionally the config file has been renamed to "fuse_config.h"
to avoid clashes - 'config.h' is not very specific.
The io for FUSE requests and responses can now be further customized by allowing to write custom functions for reading/writing the responses. This includes overriding the splice io.
The reason for this addition is that having a custom file descriptor is not sufficient to allow custom io. Different types of file descriptor require different mechanisms of io interaction. For example, some file descriptor communication has boundaries (SOCK_DGRAM, EOF, etc...), while other types of fd:s might be unbounded (SOCK_STREAMS, ...). For unbounded communication, you have to read the header of the FUSE request first, and then read the remaining packet data. Furthermore, the one read call does not necessarily return all the data expected, requiring further
calls in a loop.
This test is too simple to check for all functionalities of notify_expire as it always successfully passes when libfuse supports the function (even if kernel does not support it - it just takes it as notify_inval)
fuse_loop_mt and fuse_new had not been defined when
HAVE_LIBC_VERSIONED_SYMBOLS had not been set and additionally,
fuse_new_31 was missing in the version script and was therefore
an unusable symbol.
This also adds a test for unset HAVE_LIBC_VERSIONED_SYMBOLS.
meson configure -D buildtype=debugoptimized
meson configure -D b_sanitize=address,undefined
Results in '-fsanitize=address,undefined ... -O2 -g' that made
compilation to give errors with recent gcc versions.
bernd@t1700bs build-ubuntu>ninja -v
[1/2] ccache gcc -Itest/test_syscalls.p -Itest -I../test -Iinclude -I../include -Ilib -I../lib -I. -I.. -fdiagnostics-color=always -fsanitize=address,undefined -fno-omit-frame-pointer -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Werror -O2 -g -D_REENTRANT -DHAVE_CONFIG_H -Wno-sign-compare -Wstrict-prototypes -Wmissing-declarations -Wwrite-strings -fno-strict-aliasing -Wno-unused-result -DHAVE_SYMVER_ATTRIBUTE -MD -MQ test/test_syscalls.p/test_syscalls.c.o -MF test/test_syscalls.p/test_syscalls.c.o.d -o test/test_syscalls.p/test_syscalls.c.o -c ../test/test_syscalls.c
FAILED: test/test_syscalls.p/test_syscalls.c.o
ccache gcc -Itest/test_syscalls.p -Itest -I../test -Iinclude -I../include -Ilib -I../lib -I. -I.. -fdiagnostics-color=always -fsanitize=address,undefined -fno-omit-frame-pointer -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Werror -O2 -g -D_REENTRANT -DHAVE_CONFIG_H -Wno-sign-compare -Wstrict-prototypes -Wmissing-declarations -Wwrite-strings -fno-strict-aliasing -Wno-unused-result -DHAVE_SYMVER_ATTRIBUTE -MD -MQ test/test_syscalls.p/test_syscalls.c.o -MF test/test_syscalls.p/test_syscalls.c.o.d -o test/test_syscalls.p/test_syscalls.c.o -c ../test/test_syscalls.c
In file included from /usr/include/string.h:519,
from ../test/test_syscalls.c:7:
In function ‘strncpy’,
inlined from ‘test_socket’ at ../test/test_syscalls.c:1885:2,
inlined from ‘main’ at ../test/test_syscalls.c:2030:9:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:95:10: error: ‘__builtin_strncpy’ output may be truncated copying 107 bytes from a string of length 1023 [-Werror=stringop-truncation]
95 | return __builtin___strncpy_chk (__dest, __src, __len,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
96 | __glibc_objsize (__dest));
| ~~~~~~~~~~~~~~~~~~~~~~~~~
I disagree a bit on the gcc sanity here, as the code was behaving
correctly and even already checked the string length. But sice
the string length is already verified, that length can be used
for the final strncpy.
Simulate write() delay and verify that close(rofd) does not
block waiting on pending writes.
The support for the flag was added in kernel v5.16-rc1.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
On some tests on regular files, open an O_PATH fd of the testfile and
record it along side the size and mode and inode.
At the end of all tests, use recorded testfiles info to re-check the size
mode and inode of the unlinked testfiles.
With O_PATH fd, the server does not have to keep the inode alive so FUSE
inode may be stale or bad. Therefore, ESTALE and EIO are valid results
for fstat() on the old testfile fd's, but returning the wrong size or
mode is an invalid result.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Generate unique filename per test (only for regular file for now).
Make sure to unlink the unique filename after each test.
realpath variable was renamed to basepath_r to fix build warning
on conflicting symbols with realpath() function.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
rename dir loop test fails when test tmp dir is xfs with an error
test_rename_dir_loop() - rename : File exists
That is because xfs returns EEXIST for the case of renaming over
a non-empty directory.
According to rename(2) man page, EEXIST and ENOTEMPTY are both valid
error code in this case.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
When not using the readdir_plus mode, the d_type was not returned,
and the use_ino flag was not used for returning d_ino.
This patch fixes the returned values for d_ino and d_type by readdir(3)
The test for the returned value of d_ino has been adjusted to also
take the d_type into consideration and to check the returned values in
both basic readdir and readdir_plus modes. This is done by executing
the passthrough test twice.
Co-authored-by: Jean-Pierre André <jpandre@users.sourceforge.net>
- Test added for all passthrough examples.
- passthrough.c uses offset==0 mode. The others don't.
- passthrough.c changed to set FUSE_FILL_DIR_PLUS to make the test pass.
- This fixes#583.
In test_syscalls.c, several funcs have potential fd leakage
problems. This patch will fix them.
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Signed-off-by: Haotian Li <lihaotian9@huawei.com>
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>
Upgrade pip to fix [*]:
[66/66] Linking target example/passthrough_hp.
Traceback (most recent call last):
File "/usr/lib/python3.5/runpy.py", line 174, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/usr/lib/python3.5/runpy.py", line 133, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "/usr/lib/python3.5/runpy.py", line 109, in _get_module_details
__import__(pkg_name)
File "/usr/local/lib/python3.5/dist-packages/pytest/__init__.py", line 6, in <module>
from _pytest.assertion import register_assert_rewrite
File "/usr/local/lib/python3.5/dist-packages/_pytest/assertion/__init__.py", line 7, in <module>
from _pytest.assertion import rewrite
File "/usr/local/lib/python3.5/dist-packages/_pytest/assertion/rewrite.py", line 24, in <module>
from _pytest.assertion import util
File "/usr/local/lib/python3.5/dist-packages/_pytest/assertion/util.py", line 14, in <module>
import _pytest._code
File "/usr/local/lib/python3.5/dist-packages/_pytest/_code/__init__.py", line 2, in <module>
from .code import Code # noqa
File "/usr/local/lib/python3.5/dist-packages/_pytest/_code/code.py", line 28, in <module>
import pluggy
File "/usr/local/lib/python3.5/dist-packages/pluggy/__init__.py", line 16, in <module>
from .manager import PluginManager, PluginValidationError
File "/usr/local/lib/python3.5/dist-packages/pluggy/manager.py", line 11, in <module>
import importlib_metadata
File "/usr/local/lib/python3.5/dist-packages/importlib_metadata/__init__.py", line 9, in <module>
import zipp
ImportError: No module named 'zipp'
The command "test/travis-build.sh" exited with 1.
[*] https://travis-ci.org/libfuse/libfuse/builds/651523034
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
tst_rmdir and tst_unlink now pass for passthrough_hp.
Previously, tst_rmdir and tst_unlink created the directory / file
using src_dir, causing the test to fail as the cache was stale.
Now, the src_dir is optional. When cache is enabled, tst_rmdir
and tst_unlink do not provide a src_dir, forcing the test to
use mnt_dir itself.
Recent GCC releases have warnings related to common strncpy(3) bugs.
These warnings can be avoided by explicitly NUL-terminating the buffer
or using memcpy(3) when the intention is to copy just the characters
without the NUL terminator.
This commit fixes the following warnings:
[1/27] Compiling C object 'test/9f86d08@@test_syscalls@exe/test_syscalls.c.o'.
In function ‘test_socket’,
inlined from ‘main’ at ../test/test_syscalls.c:1899:9:
../test/test_syscalls.c:1760:2: warning: ‘strncpy’ output may be truncated copying 108 bytes from a string of length 1023 [-Wstringop-truncation]
1760 | strncpy(su.sun_path, testsock, sizeof(su.sun_path));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[2/27] Compiling C object 'lib/76b5a35@@fuse3@sha/fuse.c.o'.
../lib/fuse.c: In function ‘add_name’:
../lib/fuse.c:968:2: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
968 | strncpy(s, name, len);
| ^~~~~~~~~~~~~~~~~~~~~
../lib/fuse.c:944:15: note: length computed here
944 | size_t len = strlen(name);
| ^~~~~~~~~~~~
[3/27] Compiling C object 'lib/76b5a35@@fuse3@sha/fuse_lowlevel.c.o'.
../lib/fuse_lowlevel.c: In function ‘fuse_add_direntry’:
../lib/fuse_lowlevel.c:288:2: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
288 | strncpy(dirent->name, name, namelen);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../lib/fuse_lowlevel.c:276:12: note: length computed here
276 | namelen = strlen(name);
| ^~~~~~~~~~~~
../lib/fuse_lowlevel.c: In function ‘fuse_add_direntry_plus’:
../lib/fuse_lowlevel.c:381:2: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
381 | strncpy(dirent->name, name, namelen);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../lib/fuse_lowlevel.c:366:12: note: length computed here
366 | namelen = strlen(name);
| ^~~~~~~~~~~~
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
FreeBSD doesn't allow creating sockets using mknod(2). Instead, one has to use socket(2)
and bind(2). Add appropriate logic to the examples and add a test case.
sprintf(3)/snprintf(3) destination buffers need to be large enough
so that gcc doesn't warn -Wformat-truncation= or -Wformat-overflow=
when source buffer size is 1024 bytes.
--
../test/test_syscalls.c:1445:47: warning: '%s' directive output may be truncated writing 1 byte into a region of size between 0 and 1023 [-Wformat-truncation=]
#define PATH(p) (snprintf(path, sizeof path, "%s/%s", testdir, p), path)
^~~~~~~
../test/test_syscalls.c:1458:19:
res = mkdir(PATH("a"), 0755);
~~~
Signed-off-by: Tomohiro Kusumi <kusumi.tomohiro@gmail.com>