Skip to content

[release/2.2] Fix nil pointer dereference in container spec memory metrics when memory constraints are not fully configured#12731

Merged
fuweid merged 1 commit intocontainerd:release/2.2from
k8s-infra-cherrypick-robot:cherry-pick-12492-to-release/2.2
Dec 30, 2025
Merged

[release/2.2] Fix nil pointer dereference in container spec memory metrics when memory constraints are not fully configured#12731
fuweid merged 1 commit intocontainerd:release/2.2from
k8s-infra-cherrypick-robot:cherry-pick-12492-to-release/2.2

Conversation

@k8s-infra-cherrypick-robot
Copy link
Copy Markdown

@k8s-infra-cherrypick-robot k8s-infra-cherrypick-robot commented Dec 27, 2025

This is an automated cherry-pick of #12492

/assign akhilerm

Fixes: #12730

Add nil checks for Memory.Limit, Memory.Reservation, and Memory.Swap
before dereferencing them in extractContainerSpecMetrics. These fields
are optional pointers in OCI runtime spec and can be nil when not set.

- Memory.Limit: Set from Pod resources.limits.memory
- Memory.Reservation: Only set via NRI plugins (rarely used)
- Memory.Swap: Set from memory_swap_limit_in_bytes (optional)

This prevents potential panic when collecting metrics from containers
that don't have all memory limits configured, and makes the code
consistent with CPU resource handling and helpers.go.

Signed-off-by: You Binhao <[email protected]>
@akhilerm
Copy link
Copy Markdown
Member

/cc @AkihiroSuda

@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review Dec 30, 2025
@fuweid fuweid merged commit 5db19f4 into containerd:release/2.2 Dec 30, 2025
90 of 92 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Dec 30, 2025
@akhilerm akhilerm linked an issue Dec 31, 2025 that may be closed by this pull request
@samuelkarp samuelkarp changed the title [release/2.2] Fix nil pointer dereference in container spec memory metrics [release/2.2] Fix nil pointer dereference in container spec memory metrics when memory constraints are not fully configured Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cri Container Runtime Interface (CRI) impact/changelog kind/bug size/M

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

#12492 requires backporting to release 2.2 branch

6 participants