Repository navigation
Description
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:
- A
ReadOperror endsServeOps, andJoinreturns the error. TodayServeOpspanics. ReadOprejects a malformed message with EIO and keeps serving. Today some malformed messages panic insideReadOp, and the rest return an error thatServeOpsturns 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.
- panic: convertInMessage: Can't grow for 262144-byte read #81 hit this panic. A kernel built with a larger
FUSE_MAX_PAGES_PER_REQsent a read that the library could not convert. - fix: throw error when ReadOp buffer allocation fails #193 proposed a new
ReadOperror, and its description shows the panic that the error then causes. - A
LOOKUPmessage whose name has no terminating NUL is enough today. The panic value isconvertInMessage: Corrupt OpLookup.
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.
OpSymlinkwith one name, such as"name\x00":names[i+1:len(names)-1]panics withslice bounds out of range [5:4](conversions.go L251-L261). A body of"\x00"panics with[1:0].OpRenamewith aRenameInfollowed by one name, such as"old\x00": the same expression panics withslice bounds out of range [4:3](conversions.go L274-L306).OpReaddirandOpReaddirpluswithSize0:outMsg.Grow(0)(L420-L421, L451-L452) takes&b[0]of an empty slice and panics withindex out of range [0] with length 0(internal/buffer/out_message.go L53-L58).OpReaddirpluschecksreadSize > 0only afterGrow.OpGetxattrchecksSizebefore it callsGrow(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
ServeOps: on an error other thanio.EOF, stop reading, wait for the ops in flight, callDestroy, and return.Joinreturns the error.Server.ServeOpshas no return value, so one way is forConnectionto keep the first fatalReadOperror, and for the goroutine inMountto join it with thecloseerror thatJoinalready returns. TheServerinterface stays the same.- Conversion errors:
ReadOpreplies EIO to the request'sUnique, except for ops that expect no reply, such asFORGET. 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. - Framing:
convertInMessagechecks thatOpSymlinkandOpRenamehold a second name, and returnsCorrupt OpSymlinkorCorrupt OpRenamewhen they do not.OpReaddirandOpReaddirplustreatSize0 as an empty destination, asOpGetxattrdoes. With change 2, these messages get EIO. - Duplicate
Unique:ReadOpreturns an error instead of a panic. With change 1,ServeOpsstops andJoinreturns the error. An EIO reply does not work here, because the kernel side matches a reply to a request byUniquealone.
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