Skip to content

Rosetta initialization hijacks/overwrites guest file descriptor 3, conflicting with applications #106

@doanbaotrung

Description

@doanbaotrung

Problem Description

During Rosetta bootstrap on macOS, the runner initializes the Rosetta guest translator and passes the target guest binary path. In the implementation, the code hardcodes guest file descriptor 3 to store the guest binary's host file descriptor:

int bin_guest_fd = fd_alloc_at(3, FD_REGULAR, bin_host_fd, NULL);

This causes major issues for guest applications that rely on file descriptor 3 for their own purposes.

For example, when running apt update inside the guest, apt launches signature verification helpers (like gpgv) and sets up a status communication pipe mapped explicitly to guest file descriptor 3 (invoking gpgv --status-fd 3). Because the runner hijacks and overwrites guest fd 3 to point to the guest binary file descriptor, the status pipe is broken. As a result, apt cannot read the signature status, failing with:

Internal error: Good signature, but could not determine key fingerprint?!

Proposed Fix

Instead of hardcoding guest fd 3, allocate the guest file descriptor dynamically using the first unused fd, and pass it properly to the guest binary stack via AT_EXECFD.

  1. In rosetta_finalize (src/core/rosetta.c), change fd_alloc_at(3, ...) to fd_alloc(...) to obtain a dynamic guest file descriptor, and return it.
  2. In rosettad_set_binary_path (src/core/rosetta.c), format the target path dynamically to match the allocated file descriptor (i.e. /proc/self/fd/<bin_guest_fd>).
  3. In guest_bootstrap_prepare and guest_bootstrap_rosetta_post_reset (src/core/bootstrap.c), capture the allocated descriptor returned from rosetta_finalize and supply it as the execfd parameter to build_linux_stack (which populates the AT_EXECFD auxiliary vector).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions