Skip to content

Proposal: end ServeOps with an error on a ReadOp error, and reject malformed messages with EIO #204

Open

Description

@dsfaccini

This issue was posted by Claude Code using claude-opus-5-5 on behalf of David.

Summary

Some messages from the kernel side make jacobsa/fuse panic, and the panic ends the process. I propose two changes:

  1. A ReadOp error ends ServeOps, and Join returns the error. Today ServeOps panics.
  2. ReadOp rejects a malformed message with EIO and keeps serving. Today some malformed messages panic inside ReadOp, and the rest return an error that ServeOps turns into a panic.

The kernel side is the Linux kernel, the macFUSE kernel extension, or the FUSE-T server. A correct kernel side does not send these messages. The goal is that a buggy kernel side costs one request, or at most the mount, but not the process.

What panics at a124548

I checked each panic below at a124548 with a test in package fuse that feeds the message to ReadOp through a socketpair. None of the tests mounts.

ServeOps panics on any ReadOp error

ServeOps calls panic(err) for every error other than io.EOF (fuseutil/file_system.go L113-L115). Mount runs ServeOps in its own goroutine (mount.go L93-L97), so the caller of Mount cannot recover the panic.

A conversion error leaves the request without a reply

When convertInMessage returns an error, ReadOp returns the OutMessage to its freelist but not the InMessage, and it sends no reply (connection.go L476-L482). On Linux, the process that made the request then waits until the connection is aborted, because the kernel keeps a request that userspace has read until it gets a reply (request_wait_answer).

Open PR #201 returns the InMessage to its freelist and returns a typed error that carries the raw bytes. It keeps the ServeOps panic.

Malformed framing panics inside convertInMessage

These panic inside ReadOp itself, so a server that checks the error from ReadOp does not see them either.

  • OpSymlink with one name, such as "name\x00": names[i+1:len(names)-1] panics with slice bounds out of range [5:4] (conversions.go L251-L261). A body of "\x00" panics with [1:0].
  • OpRename with a RenameIn followed by one name, such as "old\x00": the same expression panics with slice bounds out of range [4:3] (conversions.go L274-L306).
  • OpReaddir and OpReaddirplus with Size 0: outMsg.Grow(0) (L420-L421, L451-L452) takes &b[0] of an empty slice and panics with index out of range [0] with length 0 (internal/buffer/out_message.go L53-L58). OpReaddirplus checks readSize > 0 only after Grow. OpGetxattr checks Size before it calls Grow (L671-L673).

A duplicate Unique panics

When a second request arrives with the Unique of a request still in flight, recordCancelFunc panics with Already have cancel func for request <unique> (connection.go L287-L298). The macFUSE 5.5.0 release notes list this change for the kernel extension: "Prevent duplicate request identifiers during concurrent allocation". This suggests that a kernel extension before 5.5.0 can send such a pair.

finishOp panics with Unknown request ID in finishOp when it finds no entry (connection.go L349-L352). Today a second Reply for the same op reaches it. A fix that accepts a duplicate Unique must handle this path too.

Proposal

  1. ServeOps: on an error other than io.EOF, stop reading, wait for the ops in flight, call Destroy, and return. Join returns the error. Server.ServeOps has no return value, so one way is for Connection to keep the first fatal ReadOp error, and for the goroutine in Mount to join it with the close error that Join already returns. The Server interface stays the same.
  2. Conversion errors: ReadOp replies EIO to the request's Unique, except for ops that expect no reply, such as FORGET. It returns both messages to their freelists, as Return a typed error with raw bytes for malformed messages #201 does, and logs the error to the error logger. Then it reads the next message. With Return a typed error with raw bytes for malformed messages #201, the log line can include the raw bytes.
  3. Framing: convertInMessage checks that OpSymlink and OpRename hold a second name, and returns Corrupt OpSymlink or Corrupt OpRename when they do not. OpReaddir and OpReaddirplus treat Size 0 as an empty destination, as OpGetxattr does. With change 2, these messages get EIO.
  4. Duplicate Unique: ReadOp returns an error instead of a panic. With change 1, ServeOps stops and Join returns the error. An EIO reply does not work here, because the kernel side matches a reply to a request by Unique alone.

This does not add a recover around file system code, which #37 and #139 asked for and which neither merged. It changes only the library's own read path. A panic in a file system method still ends the process, as it does today.

If this direction works for you, I can send a PR on top of #201, with tests that feed messages to ReadOp and do not mount.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions