Skip to content

truncate on /dev/shm drops the guest's record locks #469

Open

Description

@xalestar

truncate() on a /dev/shm path drops every POSIX record lock the guest holds on that file. sys_truncate in src/syscall/fs.c reaches a /dev/shm leaf through shm_open_leaf, truncates through that descriptor and closes it. On macOS, closing any descriptor for a file releases all of the process's fcntl record locks on it, and guest F_SETLK locks are host record locks.

Measured with a static aarch64 probe: open /dev/shm/elfuse-lock-probe, take an F_SETLK write lock, call truncate(path, 100), then have a forked child check the lock with F_GETLK.

Linux (qemu) elfuse main (e9fdbbb)
truncate 0 0
lock seen by the child held gone

Linux's vfs_truncate opens nothing, so the lock survives. #463 removed the same open-and-close from the regular-file path of truncate after review; the /dev/shm branch was left as it was.

Goal: truncate on a /dev/shm path leaves the guest's record locks in place. The branch opens the leaf because truncate(2) has no nofollow form, so a fix would have to keep that protection without closing a descriptor on the file.

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions