fix(broker): audit a request whose descriptors do not fit on macOS

Merged
KI
21d ago
+108-50

Problem

On macOS, a worker can make the broker drop its connection with no audit event, which RFC 0011 and the threat model say cannot happen: every refusal is one request event with malformed_frame.

It takes one request that attaches more descriptors than the broker's descriptor table can hold. Under launchd's default soft limit of 256, one request with 253 descriptors is enough. Linux reports that message truncated (MSG_CTRUNC), which the broker already refuses and audits. macOS can fail recvmsg instead, with EMSGSIZE or EMFILE. Neither errno has a framing reason, so the connection ended without an event. macOS can also deliver only the descriptors that fit, which the broker already refused and audited as attached descriptors.

It still failed closed: nothing was served and no descriptor stayed open.

Found in an internal review.

Change

  • read_frame, when it refuses descriptors (the broker's side), treats EMFILE and EMSGSIZE from recvmsg like MSG_CTRUNC: the connection fails with the same malformed_frame error and message. Only attached descriptors cause either, and a request carries none. The client's side, which accepts one descriptor per response, is unchanged.
  • a_request_whose_descriptors_cannot_be_received_fails_the_connection_closed was Linux only. It now runs on macOS too, checks for exactly one request/deny/malformed_frame event, and runs with no free descriptor slot and with half a message's worth free. It accepts either refusal message, "more descriptors than could be received" or "requests carry none", because which one macOS reaches depends on the table. Both are the same malformed_frame refusal, and the test still checks that nothing was served and every descriptor was closed.
  • RFC 0003, the threat model row (no longer "Linux only"), and the changelog.

Verification

  • The test went first. On macOS, before the change:
    assertion `left == right` failed: room 0: Message too long (os error 40)
      left: Uncategorized
     right: InvalidData
    
    An earlier run with no free slot failed with Too many open files (os error 24), so macOS gives either errno for a full table. After the change it passed three runs in a row.
  • On CI's macOS 26 runner, the first push failed the test's message check with half a message's worth free: room 126: peer attached a file descriptor to a request; requests carry none. There, macOS delivered the descriptors that fit with no error, and the broker refused them as attached descriptors. The second commit accepts that message too.
  • cargo test --locked on macOS: 122 passed, 0 failed. cargo fmt --all --check passed. cargo clippy --locked --all-targets -- -D warnings is clean on macOS and, with Rust 1.100, for x86_64-unknown-linux-gnu and aarch64-unknown-linux-gnu. cargo +1.85.0 check --locked --all-targets passed.

Not verified locally: Linux, where the test now also checks the audit event. That is this PR's CI.

Documentation and release

RFC 0003, the threat model, and the changelog. No version change.