Skip to content

fcntl(F_SETFL) and setsockopt use translate() instead of translate_writable_vfd() #97

Description

@perbu

lib/tinykvm/linux/system_calls.cpp:1828 (SYS_fcntl, F_SETFL) and
:1133 (SYS_setsockopt).

Both are mutating operations on a host fd, but both resolve the vfd with the
plain translate() rather than translate_writable_vfd(). The neighbouring
F_SETLK64 case at :1855 uses translate_writable_vfd(), which is the
intended idiom for a write path — the local variable at :1828 is even already
named writable_fd.

Consequence worth noting for the fork deployment: forks share the master's
real_fd (fds.cpp:303,331), and reset_to() does not restore file status
flags, so a flag set through this path persists across a reset.

Fix: use translate_writable_vfd() in both places.

Found by an internal audit of the host-side Linux emulation. A fix PR with a
regression test follows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions