Skip to content

Use owner-only permissions for EventPipe output files - #137670

Open
tommcdon wants to merge 9 commits into
dotnet:mainfrom
tommcdon:dev/tommcdon/fix_ep_rt_file_write
Open

tommcdon wants to merge 9 commits into
dotnet:mainfrom
tommcdon:dev/tommcdon/fix_ep_rt_file_write

Conversation

@tommcdon

@tommcdon tommcdon commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: d74c8e91fdc3d5a3c626b8c53b3467b29b8a0201

Dimension Assessment Rationale
Change confidence 9/10 ↑ End-to-end Linux x64 CoreCLR startup tracing at this revision wrote valid .nettrace files with mode 0600 for fresh creation and replacement.
↑ Windows Checked CoreCLR and NativeAOT runtime builds passed; native minipal tests passed 27/27.
↑ Native fileio tests passed 1/1 on Linux x64 and macOS x64; the only change since is a header comment.
↑ The non-atomic replacement side effect is documented in fileio.h, as requested in review.
Diagnosis confidence 9/10 ↑ Same Linux build with the merge-base EventPipe caller wrote 0644 files under umask 0022; this PR's caller wrote 0600.
↑ Primitive-level reproduction showed the same 0644 to 0600 change on Linux and macOS.
Evidence fit 9/10 ↑ End-to-end before/after startup tracing reproduces the group- and world-readable trace output and shows it fixed.

Summary

  • Add a reusable cross-platform minipal helper that replaces an existing regular file with a newly created owner-only file.
  • Use the helper for CoreCLR and NativeAOT EventPipe output.
  • Reject symlinks and other non-regular output paths without modifying them.
  • Normalize file-open failures to the shared null-handle contract. The helper itself returns the platform handle or -1, without an errno/GetLastError contract.
  • Add native minipal fileio tests and register them in the managed launcher. The Windows delete-sharing test checks the first replacement attempt without retrying after the reader closes.

Compatibility

On Unix, an existing regular output file is replaced. Symlinks, FIFOs, devices, sockets, and directories are not accepted as EventPipe output paths.

On Windows, existing regular files are deleted and recreated with an owner-only security descriptor rather than truncated using CREATE_ALWAYS. Replacement fails if an existing handle does not share delete access; previously truncation could succeed in that situation. Read-only files, directories, and reparse points are rejected.

Replacement is not atomic. Deletion can succeed while subsequent creation fails, leaving the previous path absent. A controlled descriptor-exhaustion check confirmed this on Linux and macOS. This contract is documented in fileio.h. No failure atomicity is provided.

Testing

End-to-end Linux x64 (WSL Ubuntu) validation of commit d74c8e91fdc3d5a3c626b8c53b3467b29b8a0201. The only change since f90e0e7 is the fileio.h comment documenting non-atomic replacement:

  • NUGET_PACKAGES=~/rt-e2e/.packages ./build.sh clr+libs -rc release -lc release /p:NoPgoOptimize=true — passed. PGO/LTO was disabled because the local linker could not read LTO archives for singlefilehost; this is unrelated to the PR.
  • With umask 0022, DOTNET_EnableEventPipe=1, and DOTNET_EventPipeOutputPath set, a hello-world app run under corerun produced valid Nettrace files with mode 0600 for both fresh creation and replacement of an existing 0644 file.
  • With only ep-rt-coreclr.h reverted to merge base 0b2abb835bc and ./build.sh clr.runtime -c release /p:NoPgoOptimize=true rebuilt, the same runs produced mode 0644.

Additional direct Linux x64 and macOS x64 validation of the helper and native fileio test sources at commit f90e0e7367603b15d178c436c0a6e87580f3bc8d:

  • Linux x64 via WSL Ubuntu: sh run.sh in a standalone source bundle — passed. The script compiled the unchanged fileio.c, existing fileio-tests.c, and native common runner with cc -std=c11 -D_DEFAULT_SOURCE -D_DARWIN_C_SOURCE -Wall -Wextra -Werror, HAVE_O_CLOEXEC=1, and a fileio-only group launcher. Native fileio group: 1/1 passed, zero failures.
  • macOS x64 via SSH to the validation host: CC=clang sh run.sh in the same source bundle — passed with the same flags and native fileio result, 1/1 passed, zero failures.
  • On both platforms, a controlled reproduction using the target-branch CoreCLR/NativeAOT Unix file-open primitive (creat with mode 0666, umask 0022) produced mode 0644. The current helper produced mode 0600 for replacement and fresh creation; ownership matched the effective user, and replacement received a new inode.
  • On both platforms, exhausting the process descriptor limit before invoking the helper on an existing file produced -1/EMFILE, followed by lstat reporting ENOENT. This confirms the documented deletion-before-creation failure side effect; it does not establish failure atomicity.

These were direct helper/native tests, not full Linux/macOS runtime builds or end-to-end EventPipe startup runs. No new overall CI success is claimed.

Fresh Windows x64 validation of commit f90e0e7367603b15d178c436c0a6e87580f3bc8d:

  • .\build.cmd clr.runtime+clr.nativeaotruntime -rc Checked — passed; both native runtime targets completed with 0 warnings and 0 errors. This builds the NativeAOT runtime, not a full NativeAOT compiler/application suite.
  • .\src\tests\build.cmd x64 Debug -Tree native\minipal — passed with 0 warnings and 0 errors.
  • From artifacts\tests\coreclr\windows.x64.Debug\native\minipal\NativeMinipalTests, with CORE_ROOT set to the matching Debug Tests\Core_Root: & "$env:CORE_ROOT\corerun.exe" .\NativeMinipalTests.dll — passed; native groups executed fileio 1/1, utf8 12/12, and u16 14/14, with 0 failures; launcher exit code 100.
  • git diff --check — passed before committing.
  • Rubber-duck review of the retry removal found no introduced blocking issues; Windows sharing behavior remains filesystem-dependent beyond the tested environment.

The Windows fileio run exercised protected owner-only DACL/ownership, non-inheritable handles, fresh creation and regular-file replacement, hard-link isolation, invalid paths, directory/symlink rejection, read-only rejection, reader-without-delete-sharing rejection, and first-attempt replacement with a delete-sharing reader retaining the old contents. No symlink skip was printed in this run.

macOS runtime builds, NativeAOT startup tracing, WASI, and full NativeAOT application tests were not rerun for this revision. CI investigation is separate from the local validation above; no overall CI success is claimed.

Earlier validation recorded for commit 28f7700b277 (historical results, not validation of the current revision):

  • .\build.cmd clr.runtime+clr.nativeaotruntime -rc Debug — passed with 0 warnings and 0 errors.
  • ./build.sh clr+libs+host — passed with 0 warnings and 0 errors on Linux.
  • ./build.sh clr.aot+libs -rc Debug -lc Debug — passed with 0 warnings and 0 errors on Linux.
  • Direct minipal helper validation — passed fresh 0600 creation, close-on-exec, regular-file replacement, unchanged symlink/FIFO rejection, and null-path handling.
  • CoreCLR startup tracing — passed; 50,000 events read with 0 events lost.
  • NativeAOT startup tracing — passed; 50,000 events read with 0 events lost.
  • CoreCLR and NativeAOT behavior checks — fresh files had mode 0600; existing regular files received new inodes; symlinks and FIFOs were rejected unchanged; hardlink targets remained unchanged.
  • WASI eventpipe_objs and eventpipe-enabled targets — compiled successfully with the new minipal helper.
  • Windows NTFS sharing and ACL checks — CREATE_ALWAYS retained an existing file's inherited ACL; delete and recreate succeeded with a reader sharing delete access, but deletion failed with a reader not sharing delete access.

Note

This pull request was created and updated with GitHub Copilot.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 927a2924-cfef-43ac-ab2c-7ca6f87b7743
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 927a2924-cfef-43ac-ab2c-7ca6f87b7743
Co-authored-by: Copilot <[email protected]>

Copilot-Session: 927a2924-cfef-43ac-ab2c-7ca6f87b7743
Co-authored-by: Copilot <[email protected]>

Copilot-Session: 927a2924-cfef-43ac-ab2c-7ca6f87b7743
Comment thread src/native/minipal/CMakeLists.txt Resolved
Comment thread src/native/minipal/fileio.c Resolved
Comment thread src/native/minipal/fileio.h Resolved
Co-authored-by: Copilot <[email protected]>

Copilot-Session: 927a2924-cfef-43ac-ab2c-7ca6f87b7743
Co-authored-by: Copilot <[email protected]>

Copilot-Session: 927a2924-cfef-43ac-ab2c-7ca6f87b7743
@tommcdon

Copy link
Copy Markdown
Member Author

/ba-g The Windows x86 build hit CS2012 locking Microsoft.Extensions.Logging.Generators.resources.dll; the same error occurred on main in build https://dev.azure.com/dnceng-public/public/_build/results?buildId=1693484 (Roslyn 4.0 rather than 4.4). The abandoned macOS agent matches dotnet/dnceng#1886. The Helix monitor failed because non-monitor jobs failed; macOS and Windows x86 test coverage remain incomplete.

🤖 AI-authored reply via Agency Finish PR.

@lateralusX lateralusX 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.

Couple of smaller things + consider adding a test. I also believe the PR description is a little outdated and might need update as well.

Comment thread src/native/minipal/fileio.h Resolved
Comment thread src/native/minipal/fileio.c Resolved
Comment thread src/native/minipal/fileio.h Resolved
Co-authored-by: Copilot <[email protected]>

Copilot-Session: 927a2924-cfef-43ac-ab2c-7ca6f87b7743
Comment thread src/native/minipal/fileio.h Resolved
tommcdon and others added 2 commits November 25, 2026 11:49
Remove the retry after closing the delete-sharing reader so the native minipal test checks the first helper result.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 927a2924-cfef-43ac-ab2c-7ca6f87b7743
Deletion happens before creation, so a failed creation can leave the previous file absent.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 927a2924-cfef-43ac-ab2c-7ca6f87b7743

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants