Skip to content

fix(deviceplugin): add error handling and symlink guard in Allocate - #2655

Closed
SanyamRana wants to merge 1 commit into
Project-HAMi:masterfrom
SanyamRana:fix/allocate-dir-creation-error-handling-and-lpe
Closed

fix(deviceplugin): add error handling and symlink guard in Allocate#2655
SanyamRana wants to merge 1 commit into
Project-HAMi:masterfrom
SanyamRana:fix/allocate-dir-creation-error-handling-and-lpe

Conversation

@SanyamRana

@SanyamRana SanyamRana commented Aug 14, 2026

Copy link
Copy Markdown

The Allocate function in the NVIDIA device plugin created two host directories (per-container vGPU cache and /tmp/vgpulock) with four bare os.MkdirAll / os.Chmod calls whose return values were silently discarded.

This caused two problems:

  1. Missing error handling: if MkdirAll failed (disk full, permission denied on the parent, read-only filesystem), the plugin continued to append volume mounts that would silently fail inside the container. The allocation appeared to succeed but the pod runtime was broken.

  2. Local Privilege Escalation via symlink: the plugin runs as root. /tmp is world-writable. A malicious local user could race to place a symlink at /tmp/vgpulock pointing at a sensitive file such as /etc/shadow. os.Chmod follows symlinks, so the plugin would silently change /etc/shadow to mode 0777, allowing any user on the node to read or write it.

Fix: wrap every MkdirAll and Chmod call with an error check that calls PodAllocationFailed and returns the error immediately. Before each Chmod, use os.Lstat (which does NOT follow symlinks) to verify the path is a real directory; refuse to chmod if a symlink is found.

What type of PR is this?

What this PR does / why we need it:

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

Summary by CodeRabbit

  • Bug Fixes
    • Improved device allocation reliability by detecting failures when preparing required cache and lock directories.
    • Prevented unsafe permission changes when directory paths are symbolic links.
    • Allocation now fails cleanly when directory creation, inspection, or permission updates cannot be completed.

The Allocate function in the NVIDIA device plugin created two host
directories (per-container vGPU cache and /tmp/vgpulock) with four
bare os.MkdirAll / os.Chmod calls whose return values were silently
discarded.

This caused two problems:

1. Missing error handling: if MkdirAll failed (disk full, permission
   denied on the parent, read-only filesystem), the plugin continued
   to append volume mounts that would silently fail inside the
   container. The allocation appeared to succeed but the pod runtime
   was broken.

2. Local Privilege Escalation via symlink: the plugin runs as root.
   /tmp is world-writable. A malicious local user could race to place
   a symlink at /tmp/vgpulock pointing at a sensitive file such as
   /etc/shadow. os.Chmod follows symlinks, so the plugin would
   silently change /etc/shadow to mode 0777, allowing any user on the
   node to read or write it.

Fix: wrap every MkdirAll and Chmod call with an error check that
calls PodAllocationFailed and returns the error immediately. Before
each Chmod, use os.Lstat (which does NOT follow symlinks) to verify
the path is a real directory; refuse to chmod if a symlink is found.

Signed-off-by: Sanyam Rana <sanyamrana26@gmail.com>
@hami-robot

hami-robot Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: SanyamRana
Once this PR has been reviewed and has the lgtm label, please assign archlitchi for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@github-actions github-actions Bot added the kind/bug Something isn't working label Aug 14, 2026
@SanyamRana
SanyamRana marked this pull request as draft August 14, 2026 11:57
@SanyamRana SanyamRana closed this Aug 14, 2026
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3c79909d-c098-4523-a8b1-0700f80350ad

📥 Commits

Reviewing files that changed from the base of the PR and between 51c593c and 7c20261.

📒 Files selected for processing (1)
  • pkg/device-plugin/nvidiadevice/nvinternal/plugin/server.go

📝 Walkthrough

Walkthrough

Allocate now handles vGPU cache and lock directory errors. It checks directory metadata before chmod and rejects symlink paths. Allocation returns an error when setup or permission operations fail.

Changes

vGPU allocation safety

Layer / File(s) Summary
Directory validation and failure handling
pkg/device-plugin/nvidiadevice/nvinternal/plugin/server.go
Allocate now checks directory creation, metadata inspection, and permission updates. It marks allocation as failed and returns an error when an operation fails. It rejects symlink paths before chmod.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers: peachest, mesutoezdil, archlitchi

Poem

A rabbit checks each cache and lock,
Before the chmod doors unlock.
Symlinks meet a firm “not here,”
Failed setup ends allocation clear.
Safe vGPU paths now bound and bright.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant