Hi Miklos,
On 05/11/2026 23:09, Miklos Szeredi wrote:
> The request timeout is implemented by aborting the connection:
> fuse_check_timeout() calls fuse_chan_abort(), which splices
> fpq->processing onto a local list and ends those requests. Ending a
> request wakes the waiting caller, which then drops the last reference and
> frees it.
>
> That is safe for /dev/fuse, where the request has already been copied out
> to userspace and nothing outside the kernel retains a pointer to it. It
> is not safe for virtiofs. virtio_fs_enqueue_req() passes the bare req as
> the virtqueue token, and the scatterlists point at req->in.h, req->out.h,
> req->argbuf and the request's folios; the device still owns all of that
> after the abort. When the device eventually completes the request,
> virtio_fs_requests_done_work() gets the freed req back from
> virtqueue_get_buf() and passes it to virtio_fs_verify_response() and
> virtio_fs_request_complete(), which dereference req->args - the caller's
> stack frame, long gone - and kfree() whatever req->argbuf now reads as.
> The device may also have written the reply into the freed request or into
> folios that have since been reused.
>
> This is precisely why virtio_fs_conn_destroy() drains all queues down to
> in_flight == 0 before calling fuse_conn_destroy(): once buffers are in a
> virtqueue, the only ways to reclaim them are to wait for completion or to
> reset the device. virtiofs already disables the other two paths that
> could abort a live connection, via ctx->no_control and
> ctx->no_force_umount; the timeout is the one that was left.
>
> Timeouts make little sense for virtiofs in the first place. A timeout is
> a guest-side reaction to a wedged host, and the guest has no recourse: it
> can neither take the buffers back nor make the host answer.
>
> So add fuse_conn::no_req_timeout for transports that cannot revoke a
> request once it has been handed to the server, set it from virtiofs, and
> use it to skip both fuse_init_server_timeout() and the
> FUSE_REQUEST_TIMEOUT negotiation flag. Skipping the former matters on its
> own: without it the fs/fuse/default_request_timeout sysctl would arm the
> timer even though FUSE_REQUEST_TIMEOUT was never offered to the server.
>
> Note that this is not a security issue. virtiofs inverts the usual fuse
> trust relationship - the server is the privileged, trusted side and the
> guest kernel is the untrusted one - so a server intent on corrupting guest
> memory has far more direct means at its disposal.
>
> Fixes: 0f6439f61a6e ("fuse: add kernel-enforced timeout option for requests")
> Reported-by: Sashiko <[email protected]>
> Closes: https://sashiko.dev/#/bug/linux-8171ebf0-ef01-4ccd-943e-8633a8d54239
> Signed-off-by: Miklos Szeredi <[email protected]>
> ---
> fs/fuse/fuse_i.h | 10 ++++++++++
> fs/fuse/inode.c | 9 ++++++---
> fs/fuse/virtio_fs.c | 7 +++++++
> 3 files changed, 23 insertions(+), 3 deletions(-)
>
> diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
> index ec5ccdf18a25..a033b0bc4576 100644
> --- a/fs/fuse/fuse_i.h
> +++ b/fs/fuse/fuse_i.h
> @@ -418,6 +418,7 @@ struct fuse_fs_context {
> bool destroy:1;
> bool no_control:1;
> bool no_force_umount:1;
> + bool no_req_timeout:1;
> bool legacy_opts_show:1;
> bool syncfs_capable:1;
> enum fuse_vdax_mode vdax_mode;
> @@ -698,6 +699,15 @@ struct fuse_conn {
> /** @no_force_umount: Do not allow MNT_FORCE umount */
> unsigned int no_force_umount:1;
>
> + /**
> + * @no_req_timeout: Do not enforce a request timeout
> + *
> + * Set by transports that cannot revoke a request once it has been
> + * handed to the server, since the timeout is implemented by aborting
> + * the connection.
> + */
> + unsigned int no_req_timeout:1;
> +
First, I'm wondering if we should also update the description of the FUSE
timeout
files in Documentation/admin-guide/sysctl/fs.rst.
Additionally, I have a further thought regarding the current virtiofs
implementation:
if the vhost-user backend (such as virtiofsd) hangs or exits unexpectedly,
guest
applications accessing virtiofs will hang indefinitely in the guest kernel. The
dirty
pages currently under writeback continue to hold the writeback state,
preventing the
filesystem from being unmounted. Furthermore, when writeback or page reclaim
subsequently
encounters these pages, the hang can propagate to other processes in the guest.
Even restarting
virtiofsd on the host does not resolve this, which can be quite unfriendly to
users. Given this,
I'm wondering if we should consider introducing a fallback or recovery
mechanism for
virtiofsāperhaps allowing a manual write to a file under
/sys/fs/virtiofs/<device_id> or permitting
a forced unmount to invoke virtio_reset_device() for cleanup. What are your
thoughts on this?
Thanks,
Li Wang