Skip to content

linux: handle fchmod EPERM on WSL DrvFs - #5257

Closed
Zamiell wants to merge 1 commit into
libuv:v1.xfrom
Zamiell:fix-copyfile-9p
Closed

Zamiell wants to merge 1 commit into
libuv:v1.xfrom
Zamiell:fix-copyfile-9p

Conversation

@Zamiell

@Zamiell Zamiell commented Sep 3, 2026 •

Copy link
Copy Markdown

uv_fs_copyfile() can successfully copy data to a WSL DrvFs mount and
then fail with EPERM while trying to preserve the source mode. DrvFs
without metadata support cannot represent arbitrary Unix permissions,
so mode preservation should be best-effort in that configuration, as it
already is for CIFS/SMB.

The destination is identified through its mount ID in
/proc/self/fdinfo and the corresponding /proc/self/mountinfo record.
The exception requires the WSL-specific 9p + aname=drvfs
combination and the absence of the metadata option, rather than
matching every 9p filesystem.

The error is suppressed only for source modes containing a write bit.
DrvFs without metadata maps removal of all write bits to the Windows
read-only attribute, so failures that could leave a read-only source
writable remain visible.

Validation:

  • Built the static and test targets on Linux.
  • Ran uv_run_tests_a fs_copyfile.
  • Copied from the native WSL filesystem to /mnt/c and compared the
    resulting contents.
  • Injected fchmod(EPERM) and verified that it is suppressed for a
    writable source on DrvFs, but preserved on ext4 and for a read-only
    source on DrvFs.

Refs: nodejs/node#44261

(For transparency, this PR was generated by GPT 5.6 Sol.)

uv_fs_copyfile() can copy file data to a WSL DrvFs mount and then fail while preserving its mode because fchmod() returns EPERM. DrvFs without metadata support cannot represent arbitrary Unix permissions, so treat that failure as best-effort for writable source files.

Identify the exact destination mount through procfs and require the WSL-specific 9p aname=drvfs option without metadata. This avoids suppressing meaningful permission errors on generic 9p mounts and metadata-enabled DrvFs.

Refs: nodejs/node#44261

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Zamiell <5511220+Zamiell@users.noreply.github.com>

@bnoordhuis bnoordhuis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the very least you should first check that fstatfs sets s.f_type to 0x01021997 (V9FS_MAGIC) and share the syscall with uv__is_cifs_or_smb (no duplicate work)...

...having said that, I really don't want to parse multiple text files just to figure out if we're dealing with a buggy filesystem. Chances of this PR getting merged are slim.

@Zamiell

Zamiell commented Sep 4, 2026

Copy link
Copy Markdown
Author

ok, sounds good, I opened this issue for Microsoft: microsoft/WSL#41519

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants