Skip to content

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

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

tommcdon wants to merge 12 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: d5956c768a9ba703d31481ab7e120ed50e694c05

Dimension Assessment Rationale
Change confidence 9/10 ↑ Windows x86 Checked native minipal tests passed: fileio 1/1, utf8 12/12, u16 14/14.
↑ Windows x64 Checked CoreCLR and NativeAOT builds passed with 0 warnings and 0 errors; latest-source Linux and macOS native fileio and permissions checks passed.
↓ No CI result for this pushed revision has been inspected yet.
Diagnosis confidence 10/10 ↑ Earlier end-to-end EventPipe traces on the implementation revision measured mode 0644 at the merge base and 0600 with the helper; the helper implementation is unchanged in this revision.
Evidence fit 10/10 ↑ End-to-end startup tracing reproduced the permissive output mode and verified owner-only output; direct Linux/macOS checks on the latest source also measured 0600 for fresh creation and replacement.

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-attempt result without retrying; if Windows defers deletion, it accepts only ERROR_ACCESS_DENIED, an absent path after the reader closes, and preserved contents through the existing reader.

Compatibility

On Unix, an existing regular 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; read-only files, directories, and reparse points are rejected. Even with delete sharing, Windows may defer removal until the last handle closes, so creation at the same path can fail with ERROR_ACCESS_DENIED after the old pathname has been removed.

Replacement is not atomic. Deletion can succeed while subsequent creation fails, leaving the previous path absent. This contract is documented in fileio.h; no failure atomicity is provided.

Testing

Fresh validation of final revision d5956c768a9ba703d31481ab7e120ed50e694c05:

  • src\tests\build.cmd -Test native\minipal\NativeMinipalTests.csproj x86 Checked — passed with 0 warnings and 0 errors.
  • From artifacts\tests\coreclr\windows.x86.Checked\native\minipal\NativeMinipalTests, run NativeMinipalTests.cmd with the matching Tests\Core_Root — passed: fileio 1/1, utf8 12/12, u16 14/14; launcher exit code 100.
  • build.cmd clr+libs -rc Checked -lc Release -arch x64 — passed with 0 warnings and 0 errors.
  • build.cmd clr.aot+libs -rc Checked -lc Release -arch x64 — passed with 0 warnings and 0 errors.
  • Latest-source standalone native fileio tests and permissions checks passed on WSL Linux x64 and macOS x64. Both measured baseline creat(0666) with umask 0022 as mode 0644; the helper produced mode 0600 for replacement and fresh creation, with matching owner and a new inode on replacement. Descriptor exhaustion returned -1/EMFILE and left the old path absent, matching the documented non-atomic failure behavior.
  • git diff --check — passed.

The preceding Windows x86 Checked CI run reported Win32 error 5 (ERROR_ACCESS_DENIED) and an absent path after the delete-sharing reader closed. The current test checks that observed deferred-delete outcome without retrying, while still allowing a successful first-attempt replacement on systems where the path is reusable immediately. Fresh CI for the final revision has not yet been inspected. The latest observed review decision is CHANGES_REQUESTED; merge remains gated on reviewer approval and complete, clean CI.

Note

This pull request was created and updated with GitHub Copilot.

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

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 <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 927a2924-cfef-43ac-ab2c-7ca6f87b7743
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 927a2924-cfef-43ac-ab2c-7ca6f87b7743
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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 <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 927a2924-cfef-43ac-ab2c-7ca6f87b7743
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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 <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 927a2924-cfef-43ac-ab2c-7ca6f87b7743
Comment thread src/native/minipal/fileio.h Resolved
tommcdon and others added 5 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 <223556219+Copilot@users.noreply.github.com>

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 <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 927a2924-cfef-43ac-ab2c-7ca6f87b7743
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 927a2924-cfef-43ac-ab2c-7ca6f87b7743
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 927a2924-cfef-43ac-ab2c-7ca6f87b7743
Accept the observed deferred-delete outcome without retrying, while checking the expected access-denied error and absent path.

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

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