[release/10.0] Fix cgroup v2 memory limit traversal at hierarchy root - #133640
[release/10.0] Fix cgroup v2 memory limit traversal at hierarchy root#133640github-actions[bot] wants to merge 1 commit into
Conversation
Related to #130092 Fixes #133470 Fix managed cgroup v2 memory limit traversal when the current cgroup is exactly the hierarchy mount root. The previous `do/while` loop moved to the parent directory before checking whether the mount root had been reached. This could walk outside the cgroup hierarchy and eventually dereference a null path. The traversal now stops before reading or moving above the hierarchy mount root. Path equality uses ordinal string comparison. Signed-off-by: cuishuang <imcusg@gmail.com>
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @dotnet/interop-contrib |
|
Hi, the code complete date for 10.0.13 (the October 2026 release) is Monday 14 September. Make sure to merge this PR on that date at the latest, or it won't make it into that release. As a reminder, if this is a product change, you also need Tactics approval before merging this PR (test-only or infra-only changes don't require Tactics approval). |
There was a problem hiding this comment.
🟢 Approval recommended
The focused backport matches the approved upstream fix and covers the reported boundary cases.
Pull request overview
Backports the managed cgroup v2 hierarchy-root traversal fix to .NET 10.
Changes:
- Stops memory-limit traversal at the hierarchy mount.
- Reads
memory.maxat the mount before stopping. - Adds regression coverage for root and nested cgroups.
Validation was not run during this review.
File summaries
| File | Description |
|---|---|
Interop.cgroups.cs |
Corrects bounded cgroup v2 traversal. |
cgroupsTests.cs |
Adds hierarchy-root regression tests. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| return foundAnyLimit; | ||
| } | ||
|
|
||
| private static bool IsPathAtOrBelowMount(string path, string mount) |
There was a problem hiding this comment.
This does redundant work and unnecessary allocations. It can be just
private static bool IsPathAtOrBelowMount(string path, string mount)
{
if (!path.StartsWith(mount, StringComparison.Ordinal))
return false;
return path.Length == mount.Length ||
mount == "/" ||
path[mount.Length] == '/';
}
| minLimit = currentLevelLimit; | ||
| } | ||
| } | ||
| if (string.Equals(currentCGroupMemoryPath, cgroupMemoryHierarchyMountPath, StringComparison.Ordinal)) |
There was a problem hiding this comment.
Similar here, this is a very verbose way to write if (currentCGroupMemoryPath == cgroupMemoryHierarchyMountPath)
Did you mean to backport it to .NET 11, or both .NET 11 and .NET 10? |
Backport of #133471 to release/10.0
/cc @janvorli @cuishuang
Customer Impact
This issue affects Linux environments using cgroup v2 where the current process is assigned to the root of the cgroup hierarchy visible through the current cgroup mount.
In this configuration, managed cgroup memory-limit traversal can continue above the hierarchy mount and eventually throw a
NullReferenceException. This would happen when user code attempts to accessSystem.Diagnostics.Process.MaxWorkingSet/MinWorkingSetproperties.The corresponding native implementation was fixed by #130377, but I haven't realized there is
a managed implementation too; this backport fixes the managed implementation so that .NET 10
handles the configuration consistently.
Regression
Testing
Regression tests verify that:
• the hierarchy mount's memory.max is read when the current cgroup path is the mount itself;
• traversal of a nested cgroup stops at the hierarchy mount and does not inspect directories above it; and
• cgroup path construction correctly returns the hierarchy mount when the process is assigned to the visible hierarchy root.
Risk
Low. The change is limited to managed cgroup v2 memory-limit traversal. It preserves traversal of the current cgroup and its ancestors, but stops after processing the hierarchy mount and prevents reading paths outside that hierarchy. The behavior is consistent with the native CoreCLR implementation.