-
Notifications
You must be signed in to change notification settings - Fork 17
kata.kernel-uvm: add AML sandbox #2231
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
81816b3
kata.kernel-uvm: add AML sandbox
katexochen 0b15f66
package/qemu-badaml: init, pass acpi table
sespiros 89b191a
badaml-payload: init
katexochen b57c9a3
badaml-payload: initrd file overwrite
katexochen 7fb0c7f
badaml-payload: scan all memory
katexochen 263aec6
nixos: add option for kernel ACPI debug messages
sespiros 29f7e7d
node-installer-image: make extensible
katexochen eb865fa
sets/badaml-{vuln,sandbox}: init
katexochen fe9a47c
e2e/badaml-{vuln,sandbox}: init
katexochen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| name: e2e test badaml | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - sets/badaml-vuln | ||
| - sets/badaml-sandbox | ||
| - packages/kata/kernel-uvm/** | ||
| - packages/qemu-badaml/** | ||
| - packages/badaml-payload/** | ||
| - e2e/badaml-vuln/** | ||
| - e2e/badaml-sandbox/** | ||
|
|
||
| jobs: | ||
| tests: | ||
| strategy: | ||
| matrix: | ||
| platform: | ||
| - name: Metal-QEMU-SNP | ||
| runner: SNP | ||
| self-hosted: true | ||
| - name: Metal-QEMU-TDX | ||
| runner: TDX | ||
| self-hosted: true | ||
| - name: Metal-QEMU-SNP-GPU | ||
| runner: SNP-GPU | ||
| self-hosted: true | ||
| - name: Metal-QEMU-TDX-GPU | ||
| runner: TDX-GPU | ||
| self-hosted: true | ||
| test-name: | ||
| - badaml-vuln | ||
| - badaml-sandbox | ||
| fail-fast: false | ||
| name: "${{ matrix.platform.name }}" | ||
| uses: ./.github/workflows/e2e.yml | ||
| with: | ||
| skip-undeploy: false | ||
| test-name: ${{ matrix.test-name }} | ||
| platform: ${{ matrix.platform.name }} | ||
| runner: ${{ matrix.platform.runner }} | ||
| self-hosted: ${{ matrix.platform.self-hosted }} | ||
| debug-shell: true | ||
| secrets: | ||
| GITHUB_TOKEN_IN: ${{ secrets.GITHUB_TOKEN }} | ||
| CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }} | ||
| NUNKI_CI_COMMIT_PUSH_PR: ${{ secrets.NUNKI_CI_COMMIT_PUSH_PR }} | ||
| TEAMS_CI_WEBHOOK: ${{ secrets.TEAMS_CI_WEBHOOK }} | ||
| CONTRAST_GHCR_READ: ${{ secrets.CONTRAST_GHCR_READ }} | ||
| permissions: | ||
| contents: read | ||
| packages: write | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Copyright 2026 Edgeless Systems GmbH | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
|
|
||
| //go:build e2e | ||
|
|
||
| package badamlsandbox | ||
|
|
||
| import ( | ||
| "flag" | ||
| "os" | ||
| "testing" | ||
|
|
||
| badamlvuln "github.com/edgelesssys/contrast/e2e/badaml-vuln" | ||
| "github.com/edgelesssys/contrast/e2e/internal/contrasttest" | ||
| ) | ||
|
|
||
| func TestBadAMLVulnerability(t *testing.T) { | ||
| badamlvuln.BadAMLTest(t, false) | ||
| } | ||
|
|
||
| func TestMain(m *testing.M) { | ||
| contrasttest.RegisterFlags() | ||
| flag.Parse() | ||
| os.Exit(m.Run()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| // Copyright 2026 Edgeless Systems GmbH | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
|
|
||
| //go:build e2e | ||
|
|
||
| package badamlvuln | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/edgelesssys/contrast/e2e/internal/contrasttest" | ||
| "github.com/edgelesssys/contrast/internal/kuberesource" | ||
| "github.com/edgelesssys/contrast/internal/manifest" | ||
| "github.com/edgelesssys/contrast/internal/platforms" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // BadAMLTest is the shared logic between the badaml-vuln and badaml-sandbox tests. | ||
| func BadAMLTest(t *testing.T, expectSuccessfulAttack bool) { | ||
| platform, err := platforms.FromString(contrasttest.Flags.PlatformStr) | ||
| require.NoError(t, err) | ||
|
|
||
| ct := contrasttest.New(t) | ||
|
|
||
| require.True(t, contrasttest.Flags.InsecureEnableDebugShell, "the --insecure-enable-debug-shell-access flag must be set to true to extract the initrd start address") | ||
|
|
||
| runtimeHandler, err := manifest.RuntimeHandler(platform) | ||
| require.NoError(t, err) | ||
| resources := kuberesource.CoordinatorBundle() | ||
| resources = kuberesource.PatchRuntimeHandlers(resources, runtimeHandler) | ||
| resources = kuberesource.AddPortForwarders(resources) | ||
| ct.Init(t, resources) | ||
|
|
||
| require.True(t, t.Run("generate", ct.Generate), "contrast generate needs to succeed for subsequent tests") | ||
| require.True(t, t.Run("apply", ct.Apply), "Kubernetes resources need to be applied for subsequent tests") | ||
| if platform == platforms.MetalQEMUTDX { | ||
| // TODO(katexochen): Set on TDX currently fails, as we are still measuring the ACPI tables, so | ||
| // the injected BadAML table is detected during remote attestation. For TDX-GPU, we don't measure | ||
| // the table so the attack works. | ||
| require.True(t, t.Run("wait for debugshell", func(t *testing.T) { | ||
| ctx, cancel := context.WithTimeout(t.Context(), ct.FactorPlatformTimeout(2*time.Minute)) | ||
| defer cancel() | ||
| require.NoError(t, ct.Kubeclient.WaitForContainer(ctx, ct.Namespace, "coordinator-0", "contrast-debug-shell")) | ||
| }), "debugshell start must succeed for subsequent tests") | ||
| } else { | ||
| require.True(t, t.Run("set", ct.Set), "contrast set needs to succeed for subsequent tests") | ||
| } | ||
|
|
||
| var content string | ||
| require.True(t, t.Run("get content of /run/deadbeef.bin", func(t *testing.T) { | ||
| ctx, cancel := context.WithTimeout(t.Context(), ct.FactorPlatformTimeout(1*time.Minute)) | ||
| defer cancel() | ||
| cmd := []string{"debugshell", `hexdump -e '1/1 "%02x"' -n4 /run/deadbeef.bin`} | ||
| stdout, stderr, err := ct.Kubeclient.ExecContainer(ctx, ct.Namespace, "coordinator-0", "contrast-debug-shell", cmd) | ||
| require.NoError(t, err, "running %q:\nstdout:\n%s\nstderr:\n%s", cmd, stdout, stderr) | ||
| content = stdout | ||
| }), "getting content of /run/deadbeef.bin needs to succeed for subsequent tests") | ||
|
|
||
| require.True(t, t.Run("get dmesg logs", func(t *testing.T) { | ||
| ctx, cancel := context.WithTimeout(t.Context(), ct.FactorPlatformTimeout(1*time.Minute)) | ||
| defer cancel() | ||
| cmd := []string{"debugshell", "dmesg | grep -i acpi"} | ||
| stdout, stderr, err := ct.Kubeclient.ExecContainer(ctx, ct.Namespace, "coordinator-0", "contrast-debug-shell", cmd) | ||
| require.NoError(t, err, "running %q:\nstdout:\n%s\nstderr:\n%s", cmd, stdout, stderr) | ||
| t.Log(stdout) | ||
| })) | ||
|
|
||
| name := "check attack is" | ||
| if !expectSuccessfulAttack { | ||
| name += " not" | ||
| } | ||
| name += " successful" | ||
| require.True(t, t.Run(name, func(t *testing.T) { | ||
| if expectSuccessfulAttack { | ||
| require.Equal(t, "cafebabe", content, "the content of /run/deadbeef.bin should be 'cafebabe' if the attack was successful") | ||
| } else { | ||
| require.Equal(t, "deadbeef", content, "the content of /run/deadbeef.bin should be 'deadbeef' if the attack was not successful") | ||
| } | ||
| })) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // Copyright 2026 Edgeless Systems GmbH | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
|
|
||
| //go:build e2e | ||
|
|
||
| package badamlvuln | ||
|
|
||
| import ( | ||
| "flag" | ||
| "os" | ||
| "testing" | ||
|
|
||
| "github.com/edgelesssys/contrast/e2e/internal/contrasttest" | ||
| ) | ||
|
|
||
| func TestBadAMLVulnerability(t *testing.T) { | ||
| BadAMLTest(t, true) | ||
| } | ||
|
|
||
| func TestMain(m *testing.M) { | ||
| contrasttest.RegisterFlags() | ||
| flag.Parse() | ||
| os.Exit(m.Run()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # Copyright 2026 Edgeless Systems GmbH | ||
| # SPDX-License-Identifier: BUSL-1.1 | ||
|
|
||
| # TODO(katexochen): This is currently a near-copy of badaml-vuln.nix, without the disabling of the AML sandbox in the image. | ||
| # Refactor it to reuse the code between both sets. | ||
|
|
||
| _final: prev: { | ||
| contrastPkgs = prev.contrastPkgs.overrideScope ( | ||
| contrastPkgsFinal: contrastPkgsPrev: { | ||
| kata = contrastPkgsPrev.kata.overrideScope ( | ||
| _kataFinal: kataPrev: { | ||
| kernel-uvm = kataPrev.kernel-uvm.override { | ||
| # Enable ACPI debug logging to make it easier to verify that the attack is working, | ||
| # or debug it if it isn't. | ||
| withACPIDebug = true; | ||
| }; | ||
| image = kataPrev.image.override { | ||
| withBadAMLTarget = true; | ||
| }; | ||
| } | ||
| ); | ||
| contrast = contrastPkgsPrev.contrast.overrideScope ( | ||
| _contrastFinal: contrastPrev: { | ||
| node-installer-image = contrastPrev.node-installer-image.override { | ||
| withExtraLayers = [ | ||
| (contrastPkgsFinal.ociLayerTar { | ||
| files = [ | ||
| { | ||
| # The wrapper script that replaces the original qemu binary. | ||
| source = "${contrastPkgsFinal.contrastPkgsStatic.qemu-badaml}/bin/qemu-system-x86_64"; | ||
| destination = "/opt/edgeless/bin/qemu-system-x86_64"; | ||
| } | ||
| { | ||
| # The actual qemu binary that is wrapped by qemu-badaml. | ||
| source = "${contrastPkgsFinal.contrastPkgsStatic.qemu-badaml}/bin/qemu-system-x86_64-wrapped"; | ||
| destination = "/opt/edgeless/bin/qemu-system-x86_64-wrapped"; | ||
| } | ||
| { | ||
| # The AML payload injected by the wrapper script. | ||
| source = "${contrastPkgsFinal.badaml-payload}/deadbeef-file.aml"; # Modify payload here. | ||
| destination = "/opt/edgeless/bin/payload.aml"; | ||
| } | ||
| ]; | ||
| }) | ||
| ]; | ||
| withExtraInstallFilesConfig = [ | ||
| { | ||
| # qemu-badaml is a wrapper script that invokes the real qemu-cc binary. | ||
| # The original install entry for qemu-cc will only install the wrapper scripts, | ||
| # so we need to add an additional step to install the actual, wrapped qemu binary. | ||
| url = "file:///opt/edgeless/bin/qemu-system-x86_64-wrapped"; | ||
| path = "/opt/edgeless/@@runtimeName@@/bin/qemu-system-x86_64-wrapped"; | ||
| executable = true; | ||
| } | ||
| { | ||
| # The AML payload injected by the wrapper script. | ||
| url = "file:///opt/edgeless/bin/payload.aml"; | ||
| path = "/opt/edgeless/@@runtimeName@@/bin/payload.aml"; | ||
| } | ||
| ]; | ||
| }; | ||
| } | ||
| ); | ||
| } | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.