Skip to content

Commit d93b2df

Browse files
Merge pull request from GHSA-6x2m-w449-qwx7
[1.22] config/sysctl: fail if there is a + in the value
2 parents b030be8 + 3c567ed commit d93b2df

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

internal/config/nsmgr/nsmgr.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ func (mgr *NamespaceManager) NewPodNamespaces(cfg *PodNamespacesConfig) ([]Names
8787
}
8888

8989
if len(cfg.Sysctls) != 0 {
90-
pinnsArgs = append(pinnsArgs, "-s", getSysctlForPinns(cfg.Sysctls))
90+
pinnsSysctls, err := getSysctlForPinns(cfg.Sysctls)
91+
if err != nil {
92+
return nil, errors.Wrapf(err, "invalid sysctl")
93+
}
94+
pinnsArgs = append(pinnsArgs, "-s", pinnsSysctls)
9195
}
9296

9397
var rootPair idtools.IDPair
@@ -170,14 +174,18 @@ func getMappingsForPinns(mappings []idtools.IDMap) string {
170174
return g.String()
171175
}
172176

173-
func getSysctlForPinns(sysctls map[string]string) string {
174-
// this assumes there's no sysctl with a `+` in it
177+
func getSysctlForPinns(sysctls map[string]string) (string, error) {
178+
// This assumes there's no valid sysctl value with a `+` in it
179+
// and as such errors if one is found.
175180
const pinnsSysctlDelim = "+"
176181
g := new(bytes.Buffer)
177182
for key, value := range sysctls {
183+
if strings.Contains(key, pinnsSysctlDelim) || strings.Contains(value, pinnsSysctlDelim) {
184+
return "", errors.Errorf("'%s=%s' is invalid: %s found yet should not be present", key, value, pinnsSysctlDelim)
185+
}
178186
fmt.Fprintf(g, "'%s=%s'%s", key, value, pinnsSysctlDelim)
179187
}
180-
return strings.TrimSuffix(g.String(), pinnsSysctlDelim)
188+
return strings.TrimSuffix(g.String(), pinnsSysctlDelim), nil
181189
}
182190

183191
// dirForType returns the sub-directory for that particular NSType

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.22.2"
24+
const Version = "1.22.3"
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
@@ -189,6 +189,27 @@ function teardown() {
189189
[[ "$output" != *"net.ipv4.ip_forward = 0"* ]]
190190
}
191191

192+
@test "fail to pass pod sysctl to runtime if invalid value" {
193+
if test -n "$CONTAINER_UID_MAPPINGS"; then
194+
skip "userNS enabled"
195+
fi
196+
start_crio
197+
198+
jq --arg sysctl "1024 65000'+'net.ipv4.ip_forward=0'" \
199+
' .linux.sysctls = {
200+
"net.ipv4.ip_local_port_range": $sysctl,
201+
}' "$TESTDATA"/sandbox_config.json > "$TESTDIR"/sandbox.json
202+
203+
! crictl runp "$TESTDIR"/sandbox.json
204+
205+
jq --arg sysctl "net.ipv4.ip_local_port_range=1024 65000'+'net.ipv4.ip_forward" \
206+
' .linux.sysctls = {
207+
($sysctl): "0",
208+
}' "$TESTDATA"/sandbox_config.json > "$TESTDIR"/sandbox.json
209+
210+
! crictl runp "$TESTDIR"/sandbox.json
211+
}
212+
192213
@test "pod stop idempotent" {
193214
start_crio
194215
pod_id=$(crictl runp "$TESTDATA"/sandbox_config.json)

0 commit comments

Comments
 (0)