由非 root 用户挂载的 FUSE 文件系统无法由 root 访问(除非在挂载时使用 allow_other
)。
作为 root,我想要查询每次安装标志,例如 nosuid
,以便我可以将 mount()
与 MS_REMOUNT|MS_BIND|...
结合使用来添加每次安装 MS_RDONLY
标志。我已经在大多数文件系统上成功地使用 statvfs() 查询现有的挂载标志。但是有没有办法实现这个来处理 FUSE(以及带有 root_squash 的 NFS)等情况?
最佳答案
是的。 statvfs()
也适用于这种情况。同时,它避免了 FUSE 文件系统上的阻塞。
$ mkdir mnt
$ bindfs --no-allow-other mnt mnt
$ stat -f mnt
File: "mnt"
ID: 0 Namelen: 255 Type: fuseblk
Block size: 4096 Fundamental block size: 4096
Blocks: Total: 78150265 Free: 8223357 Available: 4722313
Inodes: Total: 19857408 Free: 18558102
$ strace stat -f mnt
...
statfs("mnt", {f_type=FUSE_SUPER_MAGIC, f_bsize=0, f_blocks=0, f_bfree=0, f_bavail=0, f_files=0, f_ffree=0, f_fsid={val=[0, 0]}, f_namelen=0, f_frsize=0, f_flags=ST_VALID|ST_NOSUID|ST_NODEV|ST_RELATIME}) = 0
...
File: "mnt"
ID: 0 Namelen: 0 Type: fuseblk
Block size: 0 Fundamental block size: 0
Blocks: Total: 0 Free: 0 Available: 0
Inodes: Total: 0 Free: 0
+++ exited with 0 +++
statvfs()
被明确记录为不需要访问目标目录,只需要访问父目录。
EACCES (statvfs()) Search permission is denied for a component of the path prefix of path. (See also path_resolution(7).)
不幸的是,您的重新安装过程确实存在竞争条件,如果您无法打开目标目录,则无法修复该条件。注意 O_PATH
允许您打开目录,而不需要目录本身的任何权限。 (然后可以使用/proc/self/fd/%d
(包括通过mount()
)将O_PATH
fds 作为路径进行寻址)。
关于linux - root 可以可靠地确定每个安装的 ("bind mount")标志,例如对于 FUSE 文件系统?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52057444/