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

Open
#469 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
c, linux, macos

Research direction

Read sys_truncate and shm_open_leaf in src/syscall/fs.c, then compare the /dev/shm branch with the regular-file change in #463. Reproduce the issue with the described aarch64 probe: lock the file, truncate it, and have a child check the lock. Done means /dev/shm truncation preserves the guest's record lock while retaining the branch's protection against following symlinks.

Written by the indexing model from the issue text.

Description

bug

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.

Dominant language
C
Stars
287
Forks
33
Avg merge
2d 17h
Merged PRs (30d)
18

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sysprog21/elfuse

All issues in sysprog21/elfuse

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.