Skip to content

Commit c12bb21

Browse files
Merge pull request from GHSA-6x2m-w449-qwx7
[1.19] config/sysctl: fail if there is a + in the value
2 parents 91f8458 + 4230738 commit c12bb21

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

internal/lib/sandbox/namespaces_linux.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ func pinNamespaces(nsTypes []NSType, cfg *config.Config, sysctls map[string]stri
7171
}
7272

7373
if len(sysctls) != 0 {
74-
pinnsArgs = append(pinnsArgs, "-s", getSysctlForPinns(sysctls))
74+
pinnsSysctls, err := getSysctlForPinns(sysctls)
75+
if err != nil {
76+
return nil, errors.Wrapf(err, "invalid sysctl")
77+
}
78+
pinnsArgs = append(pinnsArgs, "-s", pinnsSysctls)
7579
}
7680

7781
type namespaceInfo struct {
@@ -128,14 +132,18 @@ func pinNamespaces(nsTypes []NSType, cfg *config.Config, sysctls map[string]stri
128132
return returnedNamespaces, nil
129133
}
130134

131-
func getSysctlForPinns(sysctls map[string]string) string {
132-
// this assumes there's no sysctl with a `+` in it
135+
func getSysctlForPinns(sysctls map[string]string) (string, error) {
136+
// This assumes there's no valid sysctl value with a `+` in it
137+
// and as such errors if one is found.
133138
const pinnsSysctlDelim = "+"
134139
g := new(bytes.Buffer)
135140
for key, value := range sysctls {
141+
if strings.Contains(key, pinnsSysctlDelim) || strings.Contains(value, pinnsSysctlDelim) {
142+
return "", errors.Errorf("'%s=%s' is invalid: %s found yet should not be present", key, value, pinnsSysctlDelim)
143+
}
136144
fmt.Fprintf(g, "'%s=%s'%s", key, value, pinnsSysctlDelim)
137145
}
138-
return strings.TrimSuffix(g.String(), pinnsSysctlDelim)
146+
return strings.TrimSuffix(g.String(), pinnsSysctlDelim), nil
139147
}
140148

141149
// getNamespace takes a path, checks if it is a namespace, and if so

internal/version/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
)
2222

2323
// Version is the version of the build.
24-
const Version = "1.19.5"
24+
const Version = "1.19.6"
2525

2626
// Variables injected during build-time
2727
var (

test/pod.bats

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,27 @@ function teardown() {
264264
[[ "$output" != *"net.ipv4.ip_forward = 0"* ]]
265265
}
266266

267+
@test "fail to pass pod sysctl to runtime if invalid value" {
268+
if test -n "$CONTAINER_UID_MAPPINGS"; then
269+
skip "userNS enabled"
270+
fi
271+
start_crio
272+
273+
jq --arg sysctl "1024 65000'+'net.ipv4.ip_forward=0'" \
274+
' .linux.sysctls = {
275+
"net.ipv4.ip_local_port_range": $sysctl,
276+
}' "$TESTDATA"/sandbox_config.json > "$TESTDIR"/sandbox.json
277+
278+
! crictl runp "$TESTDIR"/sandbox.json
279+
280+
jq --arg sysctl "net.ipv4.ip_local_port_range=1024 65000'+'net.ipv4.ip_forward" \
281+
' .linux.sysctls = {
282+
($sysctl): "0",
283+
}' "$TESTDATA"/sandbox_config.json > "$TESTDIR"/sandbox.json
284+
285+
! crictl runp "$TESTDIR"/sandbox.json
286+
}
287+
267288
@test "pod stop idempotent" {
268289
start_crio
269290
run crictl runp "$TESTDATA"/sandbox_config.json

0 commit comments

Comments
 (0)