Skip to content

[no-relnote] Add e2e test for firmware path traversal #1169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions tests/e2e/nvidia-container-toolkit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package e2e

import (
"context"
"fmt"
"path/filepath"
"strings"

Expand Down Expand Up @@ -297,4 +298,57 @@ var _ = Describe("docker", Ordered, ContinueOnFailure, func() {
Expect(err).ToNot(HaveOccurred())
})
})

When("Running a container where the firmware folder resolves outside the container root", Ordered, func() {
var outputDir string
BeforeAll(func(ctx context.Context) {
output, _, err := runner.Run("mktemp -d -p $(pwd)")
Expect(err).ToNot(HaveOccurred())
outputDir = strings.TrimSpace(output)

_, _, err = runner.Run("docker pull ubuntu")
Expect(err).ToNot(HaveOccurred())

_, _, err = runner.Run(`docker build -t firmware-test \
--build-arg RM_VERSION="$(basename $(ls -d /lib/firmware/nvidia/*.*))" \
--build-arg CURRENT_DIR="` + outputDir + `" \
- <<EOF
FROM ubuntu
RUN mkdir -p /lib/firmware/nvidia/
ARG RM_VERSION
ARG CURRENT_DIR
RUN ln -s /../../../../../../../../\$CURRENT_DIR /lib/firmware/nvidia/\$RM_VERSION
EOF`)
Expect(err).ToNot(HaveOccurred())
})

AfterEach(func(ctx context.Context) {
output, _, err := runner.Run("ls -A " + outputDir)
Expect(err).ToNot(HaveOccurred())
Expect(output).To(BeEmpty())
})

AfterAll(func(ctx context.Context) {
if outputDir != "" {
runner.Run(fmt.Sprintf("rm -rf %s", outputDir))
}
})

It("should not fail when using CDI", func(ctx context.Context) {
output, _, err := runner.Run("docker run --rm --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=runtime.nvidia.com/gpu=all firmware-test")
Expect(err).ToNot(HaveOccurred())
Expect(output).To(BeEmpty())
})

Copy link
Member

Choose a reason for hiding this comment

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

Our other CDI tests we use:

Suggested change
output, _, err := runner.Run("docker run --rm --runtime=nvidia --gpus=runtime.nvidia.com/gpu=all firmware-test")

It("should not fail when using the nvidia-container-runtime", func(ctx context.Context) {
_, _, err := runner.Run("docker run --rm --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all -e NVIDIA_DRIVER_CAPABILITIES=all firmware-test")
Expect(err).ToNot(HaveOccurred())
})

It("should fail when using the nvidia-container-runtime-hook", Label("legacy"), func(ctx context.Context) {
_, stderr, err := runner.Run("docker run --rm --runtime=runc --gpus=all firmware-test")
Expect(err).To(HaveOccurred())
Expect(stderr).To(ContainSubstring("nvidia-container-cli.real: mount error: path error:"))
Copy link
Member

@elezar elezar Jul 3, 2025

Choose a reason for hiding this comment

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

Let's add a test for the nvidia-container-runtime too:

Suggested change
Expect(stderr).To(ContainSubstring("nvidia-container-cli.real: mount error: path error:"))
It("should not fail when using the nvidia-container-runtime-hook", func(ctx context.Context) {
_, _, err := runner.Run("docker run --rm --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all -e NVIDIA_DRIVER_CAPABILITIES=all firmware-test")
Expect(err).ToNot(HaveOccurred())
output, _, _ := runner.Run(fmt.Sprintf("ls -A %s", outputDir))
Expect(output).To(BeEmpty())
}
It("should fail when using the nvidia-container-runtime-hook", Label("legacy"), func(ctx context.Context) {

})
})
})
Comment on lines +353 to 354
Copy link
Member

@elezar elezar Jul 3, 2025

Choose a reason for hiding this comment

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

Does it make sense to move the check for empty output folders to an AfterEach so that we don't have to repeat it for every test (and also don't forget to add it to new tests).

2 changes: 1 addition & 1 deletion tests/e2e/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (r remoteRunner) Run(script string) (string, string, error) {
// Run the script
err = session.Run(script)
if err != nil {
return "", "", fmt.Errorf("script execution failed: %v\nSTDOUT: %s\nSTDERR: %s", err, stdout.String(), stderr.String())
return "", stderr.String(), fmt.Errorf("script execution failed: %v\nSTDOUT: %s\nSTDERR: %s", err, stdout.String(), stderr.String())
}

// Return stdout as string if no errors
Expand Down