Fuse Xfs

Download Latest Version fuse-xfs-0.2.1.tar.gz (1.2 MB) Get Updates. Get project updates, sponsored content from our select partners, and more. XFS is probably the filesystem it's most natural to compare JFS to, as they have similar core features and were both ported to Linux at around the same time in 2001. It's also an OS that came from an old UNIX (IRIX) and is only three years younger than JFS, so understandably has a number of similar design decisions. XFS is a highly scalable, high-performance file system which was originally designed at Silicon Graphics, Inc. It was created to support extremely large filesystems (up to 16 exabytes), files (8 exabytes) and directory structures (tens of millions of entries). Full-featured Linux BTRFS, Ext4, XFS as a FUSE module.

Definitions¶

Userspace filesystem:

A filesystem in which data and metadata are provided by an ordinaryuserspace process. The filesystem can be accessed normally throughthe kernel interface.

Filesystem daemon:

The process(es) providing the data and metadata of the filesystem.

Non-privileged mount (or user mount):

A userspace filesystem mounted by a non-privileged (non-root) user.The filesystem daemon is running with the privileges of the mountinguser. NOTE: this is not the same as mounts allowed with the “user”option in /etc/fstab, which is not discussed here.

Filesystem connection:

A connection between the filesystem daemon and the kernel. Theconnection exists until either the daemon dies, or the filesystem isumounted. Note that detaching (or lazy umounting) the filesystemdoes not break the connection, in this case it will exist untilthe last reference to the filesystem is released.

Mount owner:

The user who does the mounting.

User:

The user who is performing filesystem operations.

What is FUSE?¶

FUSE is a userspace filesystem framework. It consists of a kernelmodule (fuse.ko), a userspace library (libfuse.*) and a mount utility(fusermount).

One of the most important features of FUSE is allowing secure,non-privileged mounts. This opens up new possibilities for the use offilesystems. A good example is sshfs: a secure network filesystemusing the sftp protocol.

The userspace library and utilities are available from theFUSE homepage:

Filesystem type¶

The filesystem type given to mount(2) can be one of the following:

fuse

This is the usual way to mount a FUSE filesystem. The firstargument of the mount system call may contain an arbitrary string,which is not interpreted by the kernel.

fuseblk

The filesystem is block device based. The first argument of themount system call is interpreted as the name of the device.

Mount options¶

fd=N

The file descriptor to use for communication between the userspacefilesystem and the kernel. The file descriptor must have beenobtained by opening the FUSE device (‘/dev/fuse’).

rootmode=M

The file mode of the filesystem’s root in octal representation.

user_id=N

The numeric user id of the mount owner.

group_id=N

The numeric group id of the mount owner.

default_permissions

By default FUSE doesn’t check file access permissions, thefilesystem is free to implement its access policy or leave it tothe underlying file access mechanism (e.g. in case of networkfilesystems). This option enables permission checking, restrictingaccess based on file mode. It is usually useful together with the‘allow_other’ mount option.

allow_other

This option overrides the security measure restricting file accessto the user mounting the filesystem. This option is by default onlyallowed to root, but this restriction can be removed with a(userspace) configuration option.

max_read=N

With this option the maximum size of read operations can be set.The default is infinite. Note that the size of read requests islimited anyway to 32 pages (which is 128kbyte on i386).

blksize=N

Set the block size for the filesystem. The default is 512. Thisoption is only valid for ‘fuseblk’ type mounts.

Control filesystem¶

There’s a control filesystem for FUSE, which can be mounted by:

Mounting it under the ‘/sys/fs/fuse/connections’ directory makes itbackwards compatible with earlier versions.

Under the fuse control filesystem each connection has a directorynamed by a unique number.

For each connection the following files exist within this directory:

waiting

The number of requests which are waiting to be transferred touserspace or being processed by the filesystem daemon. If there isno filesystem activity and ‘waiting’ is non-zero, then thefilesystem is hung or deadlocked.

abort

Fuse-xfs 使い方

Writing anything into this file will abort the filesystemconnection. This means that all waiting requests will be aborted anerror returned for all aborted and new requests.

Only the owner of the mount may read or write these files.

Interrupting filesystem operations¶

If a process issuing a FUSE filesystem request is interrupted, thefollowing will happen:

  • If the request is not yet sent to userspace AND the signal isfatal (SIGKILL or unhandled fatal signal), then the request isdequeued and returns immediately.

  • If the request is not yet sent to userspace AND the signal is notfatal, then an interrupted flag is set for the request. Whenthe request has been successfully transferred to userspace andthis flag is set, an INTERRUPT request is queued.

  • If the request is already sent to userspace, then an INTERRUPTrequest is queued.

INTERRUPT requests take precedence over other requests, so theuserspace filesystem will receive queued INTERRUPTs before any others.

The userspace filesystem may ignore the INTERRUPT requests entirely,or may honor them by sending a reply to the original request, withthe error set to EINTR.

It is also possible that there’s a race between processing theoriginal request and its INTERRUPT request. There are two possibilities:

  1. The INTERRUPT request is processed before the original request isprocessed

  2. The INTERRUPT request is processed after the original request hasbeen answered

If the filesystem cannot find the original request, it should wait forsome timeout and/or a number of new requests to arrive, after which itshould reply to the INTERRUPT request with an EAGAIN error. In case1) the INTERRUPT request will be requeued. In case 2) the INTERRUPTreply will be ignored.

Aborting a filesystem connection¶

It is possible to get into certain situations where the filesystem isnot responding. Reasons for this may be:

  1. Broken userspace filesystem implementation

  2. Network connection down

  3. Accidental deadlock

  4. Malicious deadlock

(For more on c) and d) see later sections)

In either of these cases it may be useful to abort the connection tothe filesystem. There are several ways to do this:

  • Kill the filesystem daemon. Works in case of a) and b)

  • Kill the filesystem daemon and all users of the filesystem. Worksin all cases except some malicious deadlocks

  • Use forced umount (umount -f). Works in all cases but only iffilesystem is still attached (it hasn’t been lazy unmounted)

  • Abort filesystem through the FUSE control filesystem. Mostpowerful method, always works.

How do non-privileged mounts work?¶

Since the mount() system call is a privileged operation, a helperprogram (fusermount) is needed, which is installed setuid root.

The implication of providing non-privileged mounts is that the mountowner must not be able to use this capability to compromise thesystem. Obvious requirements arising from this are:

  1. mount owner should not be able to get elevated privileges with thehelp of the mounted filesystem

  2. mount owner should not get illegitimate access to information fromother users’ and the super user’s processes

  3. mount owner should not be able to induce undesired behavior inother users’ or the super user’s processes

How are requirements fulfilled?¶

  1. The mount owner could gain elevated privileges by either:

    1. creating a filesystem containing a device file, then opening this device

    2. creating a filesystem containing a suid or sgid application, then executing this application

    The solution is not to allow opening device files and ignoresetuid and setgid bits when executing programs. To ensure thisfusermount always adds “nosuid” and “nodev” to the mount optionsfor non-privileged mounts.

  2. If another user is accessing files or directories in thefilesystem, the filesystem daemon serving requests can record theexact sequence and timing of operations performed. Thisinformation is otherwise inaccessible to the mount owner, so thiscounts as an information leak.

    The solution to this problem will be presented in point 2) of C).

  3. There are several ways in which the mount owner can induceundesired behavior in other users’ processes, such as:

    1. mounting a filesystem over a file or directory which the mountowner could otherwise not be able to modify (or could onlymake limited modifications).

      This is solved in fusermount, by checking the accesspermissions on the mountpoint and only allowing the mount ifthe mount owner can do unlimited modification (has writeaccess to the mountpoint, and mountpoint is not a “sticky”directory)

    2. Even if 1) is solved the mount owner can change the behaviorof other users’ processes.

      1. It can slow down or indefinitely delay the execution of afilesystem operation creating a DoS against the user or thewhole system. For example a suid application locking asystem file, and then accessing a file on the mount owner’sfilesystem could be stopped, and thus causing the systemfile to be locked forever.

      2. It can present files or directories of unlimited length, ordirectory structures of unlimited depth, possibly causing asystem process to eat up diskspace, memory or otherresources, again causing DoS.

      The solution to this as well as B) is not to allow processesto access the filesystem, which could otherwise not bemonitored or manipulated by the mount owner. Since if themount owner can ptrace a process, it can do all of the abovewithout using a FUSE mount, the same criteria as used inptrace can be used to check if a process is allowed to accessthe filesystem or not.

      Note that the ptrace check is not strictly necessary toprevent B/2/i, it is enough to check if mount owner has enoughprivilege to send signal to the process accessing thefilesystem, since SIGSTOP can be used to get a similar effect.

I think these limitations are unacceptable?¶

If a sysadmin trusts the users enough, or can ensure through othermeasures, that system processes will never enter non-privilegedmounts, it can relax the last limitation with a ‘user_allow_other’config option. If this config option is set, the mounting user canadd the ‘allow_other’ mount option which disables the check for otherusers’ processes.

Fuse

Kernel - userspace interface¶

The following diagram shows how a filesystem operation (in thisexample unlink) is performed in FUSE.

Note

Fuse Xfs

Everything in the description above is greatly simplified

There are a couple of ways in which to deadlock a FUSE filesystem.Since we are talking about unprivileged userspace programs,something must be done about these.

Scenario 1 - Simple deadlock:

The solution for this is to allow the filesystem to be aborted.

Scenario 2 - Tricky deadlock

This one needs a carefully crafted filesystem. It’s a variation onthe above, only the call back to the filesystem is not explicit,but is caused by a pagefault.

The solution is basically the same as above.

An additional problem is that while the write buffer is being copiedto the request, the request must not be interrupted/aborted. This isbecause the destination address of the copy may not be valid after therequest has returned.

This is solved with doing the copy atomically, and allowing abortwhile the page(s) belonging to the write buffer are faulted withget_user_pages(). The ‘req->locked’ flag indicates when the copy istaking place, and abort is delayed until this flag is unset.

LWN.net needs you!

Without subscribers, LWN would simply not exist. Please consider signing up for a subscription and helping to keep LWN publishing

The advent of user namespaces and container technology has made it possibleto extend more root-like powers to unprivileged users in a (we hope) safeway. One remaining sticking point is the mounting of filesystems, whichhas long been fraught with security problems. Work has been proceeding toallow such mounts for years, and it has gotten a little closer with theposting of a patch series intended for the 4.18 kernel. But, as anunrelated discussion has made clear, truly safe unprivileged filesystemmounting is still a rather distant prospect — at least, if one wants to doit in the kernel.

Attempts to make the mount operation safe for ordinary users are nothingnew; LWN covered one patch set back in2008. That work was never merged, but the effort to allow unprivilegedmounts picked up in 2015, when EricBiederman (along with others, Seth Forshee in particular) got serious aboutallowing user namespaces to perform filesystem mounts. The initial work was merged in 2016 for the 4.8 kernel, but it was known to not be acomplete solution to the problem, so most filesystems can still only bemounted by users who are privileged in the initial namespace.

Biederman has recently posted a new patchset 'wrapping up' support for unprivileged mounts. It takes care of anumber of details, such as allowing the creation of device nodes onfilesystems mounted in user namespaces — an action that is deemed to besafe because the kernel will not recognize device nodes on suchfilesystems. He clearly thinks that this feature is getting closer tobeing ready for more general use.

The plan is not to allow the unprivileged mounting of anyfilesystem, though. Only filesystem types that have been explicitly markedas being safe for mounting in this mode will be allowed. The intended usecase is evidently to allow mounting of filesystems via the FUSE mechanism,meaning that the actual implementation will be running in user space. Thatshould shield the kernel from vulnerabilities in the filesystem codeitself, which turns out to be a good thing.

In a separate discussion, the 'syzbot' fuzzing project recently reported a problem with the XFS filesystem;syzbot has been doing some fuzzing of on-disk data and a number of bugshave turned up as a result. In this case, though, XFS developer DaveChinner explained that the problem wouldnot be fixed. It is a known problem that only affects an older('version 4') on-disk format and which can only be defended against atthe cost of breaking an unknown (but large) number of otherwise workingfilesystems. Beyond that, XFS development is focused on the version 5format, which has checksumming and other mechanisms that catch mostmetadata corruption problems.

There was an extensive discussion over whether the XFS developers aretaking the right approach, but it took a bit of a diversion after EricSandeen complained about bugs that involve'merely mounting a crafted filesystem that in reality would never(until the heat death of the universe) corrupt itself into that state onits own'. Ted Ts'o pointed out thatsuch filesystems (and the associated crashes) can indeed come about in reallife if an attacker creates one and somehow convinces the system to mount it. He named Fedora andChrome OS as two systems that facilitate this kind of attack byautomatically mounting filesystems found on removable media — USB devices,for example.

There is a certain class of user that enjoys the convenience ofautomatically mounted filesystems, of course. There is also the containeruse case, where there are good reasons for allowingunprivileged users to mount filesystems on their own. So, one might think,it is important to fix all of the bugs associated with on-disk formatcorruption to make this safe. Chinner has badnews for anybody who is waiting for that to happen, though:

There's little we can do to prevent people from exploiting flaws in the filesystem's on-disk format. No filesystem has robust, exhaustive verification of all it's metadata, nor is that something we can really check at runtime due to the complexity and overhead of runtime checking.

Many types of corruption can be caught with checksums and such. Othertypes are more subtle, though; Chinner mentioned linking important metadatablocks into an ordinary file as an example. Defending the system fullyagainst such attacks would be difficult to do, to say the least, and wouldlikely slow the filesystem to a crawl.That said, Chinner doesn't expectdistributors like Fedora to stop mounting filesystems automatically:'They'll do that when we provide them with a safe, easy to usesolution to the problem. This is our problem to solve, not blame-shift itaway.' That, obviously, leaves open the question of how to solve aproblem that has just been described as unsolvable.

To Chinner, the answer is clear, at least in general terms: 'We'velearnt this lesson the hard way over and over again: don't parse untrustedinput in privileged contexts'. The meaning is that, if the contentsof a particular filesystem image are not trusted (they come from anunprivileged user, for example), that filesystem should not be managed inkernel space. In other words, FUSE should be the mechanism of choice forany sort of unprivileged mount operation.

Ts'o protested that FUSE is 'a prettyterrible security boundary' and that it lacks support for many importantfilesystem types. But FUSE is what we have for now, and it does move thehandling of untrusted filesystems out of the kernel. The fusefs-lkl module(which seems to lack a web site of its own, but is built using the Linux kernel library project)makes any kernel-supported filesystem accessible via FUSE.

When asked (by Ts'o) about making unprivileged filesystem mounts safe,Biederman made it clear that he, too,doesn't expect most kernel filesystems to be safe to use in this modeanytime soon:

Right now my practical goal is to be able to say: 'Go run your filesystem in userspace with fuse if you want stronger security guarantees.' I think that will be enough to make removable media reasonably safe from privilege escalation attacks.
It would thus seem that there is a reasonably well understood path towardfinally allowing unprivileged users to mount filesystems withoutthreatening the integrity of the system as a whole. There is clearly somework yet to be done to fit all of the pieces together. Once that is done,we may finally have a solution to a problem that developers have beenworking on for at least a decade.
Index entries for this article
KernelNamespaces/User namespaces

Fuse Ext4

(Log in to post comments)