Skip to content

Commit 98a49cf

Browse files
haircommanderopenshift-cherrypick-robot
authored andcommitted
server: fail if HOME variable has a newline
to prevent CVE-2022-4318 Signed-off-by: Peter Hunt~ <[email protected]>
1 parent d1fccc9 commit 98a49cf

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

server/container_create.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ func setupContainerUser(ctx context.Context, specgen *generate.Generator, rootfs
195195
for _, env := range specgen.Config.Process.Env {
196196
if strings.HasPrefix(env, "HOME=") {
197197
homedir = strings.TrimPrefix(env, "HOME=")
198+
if idx := strings.Index(homedir, `\n`); idx > -1 {
199+
return fmt.Errorf("invalid HOME environment; newline not allowed")
200+
}
198201
break
199202
}
200203
}

test/ctr.bats

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,3 +1025,11 @@ function check_oci_annotation() {
10251025
! ps -p "$process" o pid=,stat= | grep -v 'Z'
10261026
done
10271027
}
1028+
1029+
@test "ctr HOME env newline invalid" {
1030+
start_crio
1031+
jq ' .envs = [{"key": "HOME=", "value": "/root:/sbin/nologin\\ntest::0:0::/:/bin/bash"}]' \
1032+
"$TESTDATA"/container_config.json > "$newconfig"
1033+
1034+
! crictl run "$newconfig" "$TESTDATA"/sandbox_config.json
1035+
}

0 commit comments

Comments
 (0)