fix(vGPUmonitor): clamp corrupt device count from shared memory region - #2497
fix(vGPUmonitor): clamp corrupt device count from shared memory region#2497Nitish08-08 wants to merge 1 commit into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Nitish08-08 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesNVIDIA device count bounds
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 2⚔️ Resolve merge conflicts 💡
🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/monitor/nvidia/v0/spec_test.go (1)
52-53: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExercise the bounded limit-setter paths in both test suites.
The new boundary cases validate only
DeviceNum(). They do not prove that the two limit setters use the clamped count.
pkg/monitor/nvidia/v0/spec_test.go#L52-L53: callSetDeviceSmLimitandSetDeviceMemoryLimitwithnum = math.MaxUint64, then verify bounded writes and no panic.pkg/monitor/nvidia/v1/spec_test.go#L138-L155: add the same setter assertions for the v1 specification.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/monitor/nvidia/v0/spec_test.go` around lines 52 - 53, Extend the boundary tests in pkg/monitor/nvidia/v0/spec_test.go:52-53 to use num = math.MaxUint64 with SetDeviceSmLimit and SetDeviceMemoryLimit, asserting bounded writes and no panic. Add equivalent setter assertions in pkg/monitor/nvidia/v1/spec_test.go:138-155, verifying both setters honor the clamped device count.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pkg/monitor/nvidia/v0/spec_test.go`:
- Around line 52-53: Extend the boundary tests in
pkg/monitor/nvidia/v0/spec_test.go:52-53 to use num = math.MaxUint64 with
SetDeviceSmLimit and SetDeviceMemoryLimit, asserting bounded writes and no
panic. Add equivalent setter assertions in
pkg/monitor/nvidia/v1/spec_test.go:138-155, verifying both setters honor the
clamped device count.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 8551c801-3772-46c0-b922-4aeb70b1c1ec
📒 Files selected for processing (4)
pkg/monitor/nvidia/v0/spec.gopkg/monitor/nvidia/v0/spec_test.gopkg/monitor/nvidia/v1/spec.gopkg/monitor/nvidia/v1/spec_test.go
9d3e647 to
ce243bc
Compare
DeviceNum() returned int(sr.num) unclamped even though num is read from an mmap'd shared-memory cache written by the contained libvgpu. A torn or corrupt value larger than maxDevices makes metrics.go iterate out of bounds over the fixed-size [16] device arrays, and SetDeviceSmLimit/ SetDeviceMemoryLimit write OOB, panicking the vGPUmonitor daemonset pod. Clamp DeviceNum() to [0, maxDevices], mirroring the existing activeProcs() hardening, and make the limit setters iterate DeviceNum(). Signed-off-by: Nitish <nitishsahani0708@gmail.com>
ce243bc to
cc79045
Compare
DeviceNum() in the v0/v1 shared-memory spec (pkg/monitor/nvidia/{v0,v1}/spec.go) returned int(sr.num) unclamped. num is read from an mmap'd shared-memory cache written by the containerized libvgpu, so a torn/corrupt value (larger than the fixed [16] device arrays) makes collectContainerMetrics (cmd/vGPUmonitor/metrics.go) index out of bounds on every device array, and SetDeviceSmLimit/SetDeviceMemoryLimit write out of bounds - panicking the vGPUmonitor daemonset pod. This clamps DeviceNum() to [0, maxDevices], mirroring the existing activeProcs() hardening, and makes the limit setters iterate the clamped DeviceNum(). Verification: go test ./pkg/monitor/nvidia/v0/ ./pkg/monitor/nvidia/v1/ -short -count=1 passes; added regression cases for num > maxDevices and corrupt math.MaxUint64.
Summary by CodeRabbit