Skip to content

Commit 3abefdf

Browse files
author
Mrunal Patel
authored
Merge pull request #1109 from rhatdan/dupsec
DupSecOpt needs to match InitLabels
2 parents d186a75 + 491cada commit 3abefdf

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

libcontainer/label/label_selinux.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,19 @@ func InitLabels(options []string) (string, string, error) {
3333
pcon := selinux.NewContext(processLabel)
3434
mcon := selinux.NewContext(mountLabel)
3535
for _, opt := range options {
36-
if opt == "disable" {
37-
return "", "", nil
36+
val := strings.SplitN(opt, "=", 2)
37+
if val[0] != "label" {
38+
continue
39+
}
40+
if len(val) < 2 {
41+
return "", "", fmt.Errorf("bad label option %q, valid options 'disable' or \n'user, role, level, type' followed by ':' and a value", opt)
3842
}
39-
if i := strings.Index(opt, ":"); i == -1 {
40-
return "", "", fmt.Errorf("Bad label option %q, valid options 'disable' or \n'user, role, level, type' followed by ':' and a value", opt)
43+
if val[1] == "disable" {
44+
return "", "", nil
4145
}
42-
con := strings.SplitN(opt, ":", 2)
43-
if !validOptions[con[0]] {
44-
return "", "", fmt.Errorf("Bad label option %q, valid options 'disable, user, role, level, type'", con[0])
46+
con := strings.SplitN(val[1], ":", 2)
47+
if len(con) < 2 || !validOptions[con[0]] {
48+
return "", "", fmt.Errorf("bad label option %q, valid options 'disable, user, role, level, type'", con[0])
4549

4650
}
4751
pcon[con[0]] = con[1]

libcontainer/label/label_selinux_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestInit(t *testing.T) {
1818
t.Log("InitLabels Failed")
1919
t.Fatal(err)
2020
}
21-
testDisabled := []string{"disable"}
21+
testDisabled := []string{"label=disable"}
2222
plabel, mlabel, err = InitLabels(testDisabled)
2323
if err != nil {
2424
t.Log("InitLabels Disabled Failed")
@@ -28,7 +28,7 @@ func TestInit(t *testing.T) {
2828
t.Log("InitLabels Disabled Failed")
2929
t.FailNow()
3030
}
31-
testUser := []string{"user:user_u", "role:user_r", "type:user_t", "level:s0:c1,c15"}
31+
testUser := []string{"label=user:user_u", "label=role:user_r", "label=type:user_t", "label=level:s0:c1,c15"}
3232
plabel, mlabel, err = InitLabels(testUser)
3333
if err != nil {
3434
t.Log("InitLabels User Failed")
@@ -40,7 +40,7 @@ func TestInit(t *testing.T) {
4040
t.Fatal(err)
4141
}
4242

43-
testBadData := []string{"user", "role:user_r", "type:user_t", "level:s0:c1,c15"}
43+
testBadData := []string{"label=user", "label=role:user_r", "label=type:user_t", "label=level:s0:c1,c15"}
4444
if _, _, err = InitLabels(testBadData); err == nil {
4545
t.Log("InitLabels Bad Failed")
4646
t.Fatal(err)
@@ -94,7 +94,7 @@ func TestRelabel(t *testing.T) {
9494
t.Fatal(err)
9595
}
9696
defer os.RemoveAll(testdir)
97-
label := "system_u:system_r:svirt_sandbox_file_t:s0:c1,c2"
97+
label := "system_u:object_r:svirt_sandbox_file_t:s0:c1,c2"
9898
if err := Relabel(testdir, "", true); err != nil {
9999
t.Fatalf("Relabel with no label failed: %v", err)
100100
}

0 commit comments

Comments
 (0)