Fix: Add nil checks for Linux spec fields in Exec() #396
+2
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a nil pointer dereference in Exec() that can occur when the OCI spec does not include
linux.resources, which is valid when containers are started without explicit resource limits.
The current implementation assumes that Spec.Linux and Spec.Linux.Resources are always present
when checking memory limits and seccomp configuration. When these fields are omitted from the OCI
spec, the runtime panics during container startup.
This change adds defensive checks to ensure optional OCI fields are handled safely while preserving
the existing behavior for memory and seccomp configuration.
Root Cause
The OCI runtime specification defines both linux and linux.resources as optional fields.
Containerd and Kubernetes only populate linux.resources when resource limits are explicitly
configured.
However, Exec() accessed the following fields without verifying parent objects were non-nil:
• Spec.Linux.Resources.Memory
• Spec.Linux.Seccomp
When containers are started without memory limits, Spec.Linux or Spec.Linux.Resources may be nil,
causing a nil pointer dereference during execution.
Steps to Reproduce
Fix Applied
Defensive nil checks were added before accessing optional OCI fields:
• Verify Spec.Linux is non-nil
• Verify Spec.Linux.Resources is non-nil before checking memory limits
• Handle the case where Spec.Linux is nil when evaluating seccomp configuration
Execution flow remains unchanged:
• Memory limits from the OCI spec are used when present
• Otherwise, default memory configuration from runtime config is applied
Impact
Testing