Skip to content

Commit 1ff68bd

Browse files
committed
fix(charts): pin grubUseUKICmdline=false so nested-virt args apply on v1.12+
Talos >1.11 defaults machine.install.grubUseUKICmdline to true (UKI cmdline) and rejects machine.install.extraKernelArgs alongside it ("install.extraKernelArgs and install.grubUseUKICmdline can't be used together"). The generated base config carries that default, so the kvm_intel/kvm_amd nested-virt args on their own rendered a config Talos refused on apply for every v1.12+ node. Pin grubUseUKICmdline=false in both presets wherever the base bundle would set it true (no --talos-version, or >=1.12), so the args land on the Talos-built kernel command line. The kvm modules are built into the Talos kernel, so the nested= parameter is settable only via the command line -- a modprobe.d drop-in or a read-only /sys write cannot set it. Add contract tests that render the full apply config (base bundle + preset patch) and run Talos validation, pinning the mitigation and guarding against the UKI conflict regressing. Assisted-By: Claude <[email protected]> Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent 6b58604 commit 1ff68bd

3 files changed

Lines changed: 198 additions & 0 deletions

File tree

‎charts/cozystack/templates/_helpers.tpl‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,25 @@ machine:
165165
{{- end }}
166166
{{- (include "talm.discovered.disks_info" .) | nindent 4 }}
167167
disk: {{ include "talm.discovered.system_disk_name" . | quote }}
168+
{{- /* CVE-2026-53359: disable KVM nested virtualization (guest-to-host
169+
escape mitigation). kvm_intel/kvm_amd are built into the Talos
170+
kernel, so the nested= parameter takes effect only from the
171+
kernel command line — a modprobe.d drop-in or a runtime /sys
172+
write cannot set it (the sysfs knob is read-only post-boot).
173+
Both modules are listed so one config works on Intel and AMD;
174+
the non-matching module silently ignores its arg.
175+
176+
On Talos >1.11 the generated base config defaults
177+
machine.install.grubUseUKICmdline to true (UKI cmdline), and
178+
Talos rejects extraKernelArgs alongside it ("install.extraKernelArgs
179+
and install.grubUseUKICmdline can't be used together"). Pin it
180+
false so the args land on the Talos-built cmdline. The guard
181+
matches the base default exactly: emit the field only where the
182+
base bundle would set it true, so we never surface a key on a
183+
node whose schema predates grubUseUKICmdline. */ -}}
184+
{{- if or (not .TalosVersion) (not (semverCompare "<1.12.0-0" .TalosVersion)) }}
185+
grubUseUKICmdline: false
186+
{{- end }}
168187
extraKernelArgs:
169188
# CVE-2026-53359: disable KVM nested virtualization (guest-to-host escape mitigation)
170189
- kvm_intel.nested=0

‎charts/generic/templates/_helpers.tpl‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,25 @@ machine:
5858
install:
5959
{{- (include "talm.discovered.disks_info" .) | nindent 4 }}
6060
disk: {{ include "talm.discovered.system_disk_name" . | quote }}
61+
{{- /* CVE-2026-53359: disable KVM nested virtualization (guest-to-host
62+
escape mitigation). kvm_intel/kvm_amd are built into the Talos
63+
kernel, so the nested= parameter takes effect only from the
64+
kernel command line — a modprobe.d drop-in or a runtime /sys
65+
write cannot set it (the sysfs knob is read-only post-boot).
66+
Both modules are listed so one config works on Intel and AMD;
67+
the non-matching module silently ignores its arg.
68+
69+
On Talos >1.11 the generated base config defaults
70+
machine.install.grubUseUKICmdline to true (UKI cmdline), and
71+
Talos rejects extraKernelArgs alongside it ("install.extraKernelArgs
72+
and install.grubUseUKICmdline can't be used together"). Pin it
73+
false so the args land on the Talos-built cmdline. The guard
74+
matches the base default exactly: emit the field only where the
75+
base bundle would set it true, so we never surface a key on a
76+
node whose schema predates grubUseUKICmdline. */ -}}
77+
{{- if or (not .TalosVersion) (not (semverCompare "<1.12.0-0" .TalosVersion)) }}
78+
grubUseUKICmdline: false
79+
{{- end }}
6180
extraKernelArgs:
6281
# CVE-2026-53359: disable KVM nested virtualization (guest-to-host escape mitigation)
6382
- kvm_intel.nested=0
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
// Copyright Cozystack Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Contract: CVE-2026-53359 KVM-nested-virtualization mitigation in the
16+
// cozystack and generic presets. kvm_intel/kvm_amd are built into the
17+
// Talos kernel, so nested= is settable only from the kernel command
18+
// line; both presets pin it via machine.install.extraKernelArgs.
19+
//
20+
// On Talos >1.11 the generated base config defaults
21+
// machine.install.grubUseUKICmdline to true (UKI cmdline), and Talos
22+
// rejects extraKernelArgs alongside it. The presets therefore pin
23+
// grubUseUKICmdline:false wherever the base would set it true. The
24+
// full-pipeline test below renders through engine.Render (base bundle +
25+
// preset patch) and runs Talos's own validation to prove the merged
26+
// config the operator applies does not trip the UKI conflict.
27+
28+
package engine
29+
30+
import (
31+
"context"
32+
"strings"
33+
"testing"
34+
35+
helmEngine "github.com/cozystack/talm/pkg/engine/helm"
36+
"github.com/siderolabs/talos/pkg/machinery/config/configloader"
37+
)
38+
39+
// kvmNestedRuntimeMode is a minimal validation.RuntimeMode implementation.
40+
// RequiresInstall() true selects the install-mode validation branch that
41+
// enforces the extraKernelArgs/grubUseUKICmdline mutual exclusion.
42+
type kvmNestedRuntimeMode struct{ requiresInstall bool }
43+
44+
func (m kvmNestedRuntimeMode) String() string { return "kvm-nested-contract" }
45+
func (m kvmNestedRuntimeMode) RequiresInstall() bool { return m.requiresInstall }
46+
func (kvmNestedRuntimeMode) InContainer() bool { return false }
47+
48+
// Contract: both presets always emit the KVM nested-virt kernel args
49+
// under machine.install, for every chart × schema × machineType cell.
50+
// A regression that drops them silently re-exposes the guest-to-host
51+
// escape on every node the preset installs.
52+
func TestContract_Machine_Install_KVMNestedArgs(t *testing.T) {
53+
for _, cell := range allCells() {
54+
t.Run(cell.name, func(t *testing.T) {
55+
out := renderChartTemplate(t, cell.chartPath, cell.templateFile, cell.talosVersion)
56+
assertContains(t, out, "extraKernelArgs:")
57+
assertContains(t, out, "kvm_intel.nested=0")
58+
assertContains(t, out, "kvm_amd.nested=0")
59+
})
60+
}
61+
}
62+
63+
// Contract: grubUseUKICmdline:false is emitted exactly where the
64+
// generated base config would default it to true — i.e. when no
65+
// --talos-version is pinned (the bundle falls back to the current
66+
// contract, >1.11) or when the pinned version is >=1.12. For an
67+
// explicit pre-1.12 version the field is omitted, both because the base
68+
// does not set it and because older Talos schemas reject the key.
69+
func TestContract_Machine_Install_GrubUKICmdlineGate(t *testing.T) {
70+
for _, tc := range []struct {
71+
talosVersion string
72+
wantField bool
73+
}{
74+
{"", true}, // empty → base uses current contract (>1.11) → pin false
75+
{"v1.12.0", true}, // >=1.12 → base defaults true → pin false
76+
{"v1.13.0", true}, // >=1.12 → base defaults true → pin false
77+
{"v1.11.0", false}, // <1.12 → base leaves it unset → do not emit
78+
} {
79+
name := tc.talosVersion
80+
if name == "" {
81+
name = "empty"
82+
}
83+
t.Run(name, func(t *testing.T) {
84+
out := renderChartTemplate(t, cozystackChartPath, controlplaneTpl, tc.talosVersion)
85+
if tc.wantField {
86+
assertContains(t, out, "grubUseUKICmdline: false")
87+
} else {
88+
assertNotContains(t, out, "grubUseUKICmdline")
89+
}
90+
})
91+
}
92+
}
93+
94+
// Contract: the FULL config an operator applies — base bundle merged
95+
// with the preset patch, exactly what `talm apply` serialises (Full:
96+
// true) — passes Talos validation without the UKI/extraKernelArgs
97+
// conflict, for both presets and both machine types on v1.12+.
98+
//
99+
// This is the regression guard for the whole mitigation: the raw Helm
100+
// output above never carries grubUseUKICmdline (the base bundle injects
101+
// it), so only a full-pipeline render surfaces the collision. Offline
102+
// discovery leaves install.disk empty, which trips a separate
103+
// validation error, so the assertion is scoped to the UKI conflict
104+
// specifically rather than "no errors at all".
105+
func TestContract_Machine_Install_FullConfigValidates_NoUKIConflict(t *testing.T) {
106+
// Offline render still consults the Helm `lookup`; reset it to the
107+
// empty stub so no live discovery is attempted.
108+
helmEngine.LookupFunc = func(string, string, string) (map[string]any, error) {
109+
return map[string]any{}, nil
110+
}
111+
112+
const ukiConflict = "grubUseUKICmdline"
113+
114+
cells := []struct {
115+
name string
116+
chartPath string
117+
templateFile string
118+
}{
119+
{"cozystack/controlplane", cozystackChartPath, controlplaneTpl},
120+
{"cozystack/worker", cozystackChartPath, workerTpl},
121+
{"generic/controlplane", genericChartPath, controlplaneTpl},
122+
{"generic/worker", genericChartPath, workerTpl},
123+
}
124+
125+
for _, cell := range cells {
126+
t.Run(cell.name, func(t *testing.T) {
127+
out, err := Render(context.Background(), nil, Options{
128+
Offline: true,
129+
Full: true,
130+
Root: cell.chartPath,
131+
TalosVersion: "v1.12.0",
132+
TemplateFiles: []string{cell.templateFile},
133+
Values: []string{
134+
"endpoint=" + testEndpoint,
135+
"advertisedSubnets={" + testAdvertisedSubnet + "}",
136+
},
137+
})
138+
if err != nil {
139+
t.Fatalf("full render failed: %v", err)
140+
}
141+
142+
got := string(out)
143+
assertContains(t, got, "grubUseUKICmdline: false")
144+
assertContains(t, got, "kvm_intel.nested=0")
145+
if strings.Contains(got, "grubUseUKICmdline: true") {
146+
t.Fatalf("full config still carries grubUseUKICmdline: true — UKI cmdline not disabled:\n%s", got)
147+
}
148+
149+
cfg, lerr := configloader.NewFromBytes(out)
150+
if lerr != nil {
151+
t.Fatalf("config loader rejected the rendered config: %v", lerr)
152+
}
153+
154+
_, verr := cfg.Validate(kvmNestedRuntimeMode{requiresInstall: true})
155+
if verr != nil && strings.Contains(verr.Error(), ukiConflict) {
156+
t.Fatalf("Talos validation reports the UKI/extraKernelArgs conflict — apply would fail: %v", verr)
157+
}
158+
})
159+
}
160+
}

0 commit comments

Comments
 (0)