Skip to content

Commit

Permalink
Merge pull request #3254 from kolyshkin/sysctl-slash
Browse files Browse the repository at this point in the history
libct/configs/validate: allow / in sysctl names
  • Loading branch information
Mrunal Patel authored Oct 29, 2021
2 parents fac268b + 972aea3 commit a9761c4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions libcontainer/configs/validate/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func (v *ConfigValidator) sysctl(config *configs.Config) error {
)

for s := range config.Sysctl {
s := strings.Replace(s, "/", ".", -1)
if validSysctlMap[s] || strings.HasPrefix(s, "fs.mqueue.") {
if config.Namespaces.Contains(configs.NEWIPC) {
continue
Expand Down
6 changes: 6 additions & 0 deletions libcontainer/configs/validate/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,11 @@ func TestValidateUsernamespaceWithoutUserNS(t *testing.T) {
func TestValidateSysctl(t *testing.T) {
sysctl := map[string]string{
"fs.mqueue.ctl": "ctl",
"fs/mqueue/ctl": "ctl",
"net.ctl": "ctl",
"net/ctl": "ctl",
"kernel.ctl": "ctl",
"kernel/ctl": "ctl",
}

for k, v := range sysctl {
Expand All @@ -209,8 +212,11 @@ func TestValidateSysctl(t *testing.T) {
func TestValidateValidSysctl(t *testing.T) {
sysctl := map[string]string{
"fs.mqueue.ctl": "ctl",
"fs/mqueue/ctl": "ctl",
"net.ctl": "ctl",
"net/ctl": "ctl",
"kernel.msgmax": "ctl",
"kernel/msgmax": "ctl",
}

for k, v := range sysctl {
Expand Down
15 changes: 10 additions & 5 deletions libcontainer/integration/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,16 +897,21 @@ func TestSysctl(t *testing.T) {
config := newTemplateConfig(t, nil)
config.Sysctl = map[string]string{
"kernel.shmmni": "8192",
"kernel/shmmax": "4194304",
}
const (
cmd = "cat shmmni shmmax"
exp = "8192\n4194304\n"
)

container, err := newContainer(t, config)
ok(t, err)
defer destroyContainer(container)

var stdout bytes.Buffer
pconfig := libcontainer.Process{
Cwd: "/",
Args: []string{"sh", "-c", "cat /proc/sys/kernel/shmmni"},
Cwd: "/proc/sys/kernel",
Args: []string{"sh", "-c", cmd},
Env: standardEnvironment,
Stdin: nil,
Stdout: &stdout,
Expand All @@ -918,9 +923,9 @@ func TestSysctl(t *testing.T) {
// Wait for process
waitProcess(&pconfig, t)

shmmniOutput := strings.TrimSpace(stdout.String())
if shmmniOutput != "8192" {
t.Fatalf("kernel.shmmni property expected to be 8192, but is %s", shmmniOutput)
out := stdout.String()
if out != exp {
t.Fatalf("expected %s, got %s", exp, out)
}
}

Expand Down

0 comments on commit a9761c4

Please sign in to comment.