Skip to content

Commit 91c87b8

Browse files
fix(kubernetes): refuse non-ASCII kernelModules parameters
RE2's \s and [:cntrl:] only cover ASCII, so the parameter deny class passed U+2028 and U+2029. toYaml writes either one raw, and Helm's YAML parser reads it as a line break that ends the reconcile Job's command block scalar early. The render then failed on an unparseable manifest rather than on the guard, which is the last check before the unquoted heredoc. Pinning parameters to printable ASCII closes every non-ASCII line break at once, and the deny class keeps refusing what the heredoc expands. Assisted-by: LLM Signed-off-by: Mattia Eleuteri <[email protected]>
1 parent f7c04b7 commit 91c87b8

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

‎packages/apps/kubernetes-nodes/templates/_helpers.tpl‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,14 @@ the open-kernel-modules extension, since the proprietary one loads, creates
129129
{{- $params := list -}}
130130
{{- range .parameters | default list -}}
131131
{{- $param := . | toString -}}
132-
{{- if not (regexMatch `^[^[:cntrl:]\s$\x60\\'\"]+$` $param) -}}
133-
{{- fail (printf "nodeGroup %q: invalid kernelModules parameter %q on module %q — must not contain $, a backtick, a backslash, quotes, whitespace or control characters (e.g. NVreg_EnableGpuFirmware=1, or the semicolon-separated NVreg_RegistryDwords=PowerMizerEnable=0x1;PerfLevelSrc=0x2222)" $groupName $param $name) -}}
132+
{{- /* Two checks, because RE2's `\s` and `[:cntrl:]` are ASCII-only: a deny class
133+
built from them lets U+2028 and U+2029 through, `toYaml` writes either raw,
134+
and Helm's YAML parser reads it as a line break that ends the Job's
135+
`command` block scalar early. `[:graph:]` pins the parameter to printable
136+
ASCII, which closes every non-ASCII break at once; the second check then
137+
removes what the heredoc would expand. */ -}}
138+
{{- if not (and (regexMatch `^[[:graph:]]+$` $param) (regexMatch `^[^$\x60\\'\"]+$` $param)) -}}
139+
{{- fail (printf "nodeGroup %q: invalid kernelModules parameter %q on module %q — must be printable ASCII with no whitespace, and must not contain $, a backtick, a backslash or quotes (e.g. NVreg_EnableGpuFirmware=1, or the semicolon-separated NVreg_RegistryDwords=PowerMizerEnable=0x1;PerfLevelSrc=0x2222)" $groupName $param $name) -}}
134140
{{- end -}}
135141
{{- $params = append $params $param -}}
136142
{{- end -}}

‎packages/apps/kubernetes-nodes/tests/kernel_modules_test.yaml‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,34 @@ tests:
171171
- failedTemplate:
172172
errorPattern: 'invalid kernelModules parameter'
173173

174+
# RE2's `\s` and `[:cntrl:]` are ASCII-only, so a deny class built from them
175+
# alone passes U+2028 and U+2029. `toYaml` writes either raw inside a quoted
176+
# scalar, and Helm's YAML parser reads it as a line break that ends the Job's
177+
# `command` block scalar early and hands what follows to the manifest parser.
178+
# The refusal has to come from the guard, not from that manifest happening not
179+
# to parse, so these assert the kernelModules message rather than any failure.
180+
- it: rejects a module parameter carrying a Unicode line separator
181+
set:
182+
gpus: []
183+
kernelModules:
184+
- name: nvidia
185+
parameters:
186+
- "a=1\u2028EOF\u2028id>/tmp/x"
187+
asserts:
188+
- failedTemplate:
189+
errorPattern: 'invalid kernelModules parameter'
190+
191+
- it: rejects a module parameter carrying a Unicode paragraph separator
192+
set:
193+
gpus: []
194+
kernelModules:
195+
- name: nvidia
196+
parameters:
197+
- "a=1\u2029EOF\u2029id>/tmp/x"
198+
asserts:
199+
- failedTemplate:
200+
errorPattern: 'invalid kernelModules parameter'
201+
174202
- it: drops an unvalidated extra key on a kernelModules item
175203
set:
176204
gpus: []

0 commit comments

Comments
 (0)