Skip to content

Fix potential double-locking of RWMutex in device manager#136235

Open
ValeryCherneykin wants to merge 1 commit intokubernetes:masterfrom
ValeryCherneykin:fix-device-manager-double-locking
Open

Fix potential double-locking of RWMutex in device manager#136235
ValeryCherneykin wants to merge 1 commit intokubernetes:masterfrom
ValeryCherneykin:fix-device-manager-double-locking

Conversation

@ValeryCherneykin
Copy link

What type of PR is this?

/kind bug

What this PR does / why we need it:

The podDevices() function was calling containerDevices() while holding the read lock, but containerDevices() also attempts to acquire the same lock. This could cause a deadlock when a writer tries to acquire the lock between the two RLock() calls.

Introduce containerDevicesLocked() that expects the caller to already hold the lock, and use it from podDevices() to avoid nested locking.

Which issue(s) this PR is related to:

Fixes #127826

Special notes for your reviewer:

The fix follows the standard Go pattern of having a *Locked variant of a function that expects the caller to hold the lock.

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

N/A

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. kind/bug Categorizes issue or PR as related to a bug. labels Jan 14, 2026
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jan 14, 2026

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: ValeryCherneykin / name: ValeryCherneykin (fde201b)

@k8s-ci-robot k8s-ci-robot added do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jan 14, 2026
@k8s-ci-robot
Copy link
Contributor

Welcome @ValeryCherneykin!

It looks like this is your first PR to kubernetes/kubernetes 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kubernetes has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jan 14, 2026
@k8s-ci-robot
Copy link
Contributor

Hi @ValeryCherneykin. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. area/kubelet sig/node Categorizes an issue or PR as relevant to SIG Node. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jan 14, 2026
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: ValeryCherneykin
Once this PR has been reviewed and has the lgtm label, please assign derekwaynecarr for approval. For more information see the 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

  The podDevices() function was calling containerDevices() while holding
  the read lock, but containerDevices() also attempts to acquire the same
  lock. This could cause a deadlock when a writer tries to acquire the
  lock between the two RLock() calls.

  Introduce containerDevicesLocked() that expects the caller to already
  hold the lock, and use it from podDevices() to avoid nested locking.
@ValeryCherneykin ValeryCherneykin force-pushed the fix-device-manager-double-locking branch from 1bd48b4 to fde201b Compare January 14, 2026 19:03
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jan 14, 2026
Copy link
Contributor

@ffromani ffromani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ok-to-test
/cc

Comment on lines +39 to +46
type (
resourceAllocateInfo map[string]deviceAllocateInfo // Keyed by resourceName.
containerDevices map[string]resourceAllocateInfo // Keyed by containerName.
podDevices struct {
sync.RWMutex
devs map[string]containerDevices // Keyed by podUID.
}
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary change, let's please keep the change minimal and focused (no style + functional changes bundled together)

@k8s-ci-robot k8s-ci-robot requested a review from ffromani January 15, 2026 13:41
@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 15, 2026
@k8s-ci-robot
Copy link
Contributor

@ValeryCherneykin: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubernetes-unit-windows-master fde201b link false /test pull-kubernetes-unit-windows-master
pull-kubernetes-e2e-gce fde201b link true /test pull-kubernetes-e2e-gce

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@gzb1128
Copy link

gzb1128 commented Jan 31, 2026

Since this PR has been inactive for 2 weeks, I've created PR #136660 to continue moving this fix forward. The changes are identical to the approved fix here, just rebased onto the latest master.

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

Labels

area/kubelet cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-none Denotes a PR that doesn't merit a release note. sig/node Categorizes an issue or PR as relevant to SIG Node. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Development

Successfully merging this pull request may close these issues.

device manager: potential Double-Locking of Mutex

4 participants