From f8b34352fe0ffe61824200ad1595f5091556cb3b Mon Sep 17 00:00:00 2001 From: Dan Walsh Date: Tue, 6 Oct 2015 08:51:54 -0400 Subject: [PATCH] Validate label options Only valid options to --security-opt for label should be disable, user, role, type, level. Return error on invalid entry Signed-off-by: Dan Walsh --- libcontainer/label/label_selinux.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libcontainer/label/label_selinux.go b/libcontainer/label/label_selinux.go index e21b2fbb..ea701319 100644 --- a/libcontainer/label/label_selinux.go +++ b/libcontainer/label/label_selinux.go @@ -9,6 +9,15 @@ import ( "github.com/opencontainers/runc/libcontainer/selinux" ) +// Valid Label Options +var validOptions = map[string]bool{ + "disable": true, + "type": true, + "user": true, + "role": true, + "level": true, +} + var ErrIncompatibleLabel = fmt.Errorf("Bad SELinux option z and Z can not be used together") // InitLabels returns the process label and file labels to be used within @@ -28,9 +37,13 @@ func InitLabels(options []string) (string, string, error) { return "", "", nil } if i := strings.Index(opt, ":"); i == -1 { - return "", "", fmt.Errorf("Bad SELinux Option") + return "", "", fmt.Errorf("Bad label option %q, valid options 'disable' or \n'user, role, level, type' followed by ':' and a value", opt) } con := strings.SplitN(opt, ":", 2) + if !validOptions[con[0]] { + return "", "", fmt.Errorf("Bad label option %q, valid options 'disable, user, role, level, type'", con[0]) + + } pcon[con[0]] = con[1] if con[0] == "level" || con[0] == "user" { mcon[con[0]] = con[1]