Merge pull request #11524 from containers/dependabot/go_modules/github.com/opencontainers/selinux-1.8.5

Bump github.com/opencontainers/selinux from 1.8.4 to 1.8.5
This commit is contained in:
OpenShift Merge Robot
2021-09-11 04:56:18 -04:00
committed by GitHub
6 changed files with 76 additions and 52 deletions

2
go.mod
View File

@ -50,7 +50,7 @@ require (
github.com/opencontainers/runc v1.0.2 github.com/opencontainers/runc v1.0.2
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417
github.com/opencontainers/runtime-tools v0.9.0 github.com/opencontainers/runtime-tools v0.9.0
github.com/opencontainers/selinux v1.8.4 github.com/opencontainers/selinux v1.8.5
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/pmezard/go-difflib v1.0.0 github.com/pmezard/go-difflib v1.0.0
github.com/rootless-containers/rootlesskit v0.14.5 github.com/rootless-containers/rootlesskit v0.14.5

3
go.sum
View File

@ -756,8 +756,9 @@ github.com/opencontainers/selinux v1.5.1/go.mod h1:yTcKuYAh6R95iDpefGLQaPaRwJFwy
github.com/opencontainers/selinux v1.6.0/go.mod h1:VVGKuOLlE7v4PJyT6h7mNWvq1rzqiriPsEqVhc+svHE= github.com/opencontainers/selinux v1.6.0/go.mod h1:VVGKuOLlE7v4PJyT6h7mNWvq1rzqiriPsEqVhc+svHE=
github.com/opencontainers/selinux v1.8.0/go.mod h1:RScLhm78qiWa2gbVCcGkC7tCGdgk3ogry1nUQF8Evvo= github.com/opencontainers/selinux v1.8.0/go.mod h1:RScLhm78qiWa2gbVCcGkC7tCGdgk3ogry1nUQF8Evvo=
github.com/opencontainers/selinux v1.8.2/go.mod h1:MUIHuUEvKB1wtJjQdOyYRgOnLD2xAPP8dBsCoU0KuF8= github.com/opencontainers/selinux v1.8.2/go.mod h1:MUIHuUEvKB1wtJjQdOyYRgOnLD2xAPP8dBsCoU0KuF8=
github.com/opencontainers/selinux v1.8.4 h1:krlgQ6/j9CkCXT5oW0yVXdQFOME3NjKuuAZXuR6O7P4=
github.com/opencontainers/selinux v1.8.4/go.mod h1:HTvjPFoGMbpQsG886e3lQwnsRWtE4TC1OF3OUvG9FAo= github.com/opencontainers/selinux v1.8.4/go.mod h1:HTvjPFoGMbpQsG886e3lQwnsRWtE4TC1OF3OUvG9FAo=
github.com/opencontainers/selinux v1.8.5 h1:OkT6bMHOQ1JQQO4ihjQ49sj0+wciDcjziSVTRn8VeTA=
github.com/opencontainers/selinux v1.8.5/go.mod h1:HTvjPFoGMbpQsG886e3lQwnsRWtE4TC1OF3OUvG9FAo=
github.com/openshift/imagebuilder v1.2.2-0.20210415181909-87f3e48c2656 h1:WaxyNFpmIDu4i6so9r6LVFIbSaXqsj8oitMitt86ae4= github.com/openshift/imagebuilder v1.2.2-0.20210415181909-87f3e48c2656 h1:WaxyNFpmIDu4i6so9r6LVFIbSaXqsj8oitMitt86ae4=
github.com/openshift/imagebuilder v1.2.2-0.20210415181909-87f3e48c2656/go.mod h1:9aJRczxCH0mvT6XQ+5STAQaPWz7OsWcU5/mRkt8IWeo= github.com/openshift/imagebuilder v1.2.2-0.20210415181909-87f3e48c2656/go.mod h1:9aJRczxCH0mvT6XQ+5STAQaPWz7OsWcU5/mRkt8IWeo=
github.com/ostreedev/ostree-go v0.0.0-20190702140239-759a8c1ac913 h1:TnbXhKzrTOyuvWrjI8W6pcoI9XPbLHFXCdN2dtUw7Rw= github.com/ostreedev/ostree-go v0.0.0-20190702140239-759a8c1ac913 h1:TnbXhKzrTOyuvWrjI8W6pcoI9XPbLHFXCdN2dtUw7Rw=

View File

@ -38,6 +38,8 @@ var (
// CategoryRange allows the upper bound on the category range to be adjusted // CategoryRange allows the upper bound on the category range to be adjusted
CategoryRange = DefaultCategoryRange CategoryRange = DefaultCategoryRange
privContainerMountLabel string
) )
// Context is a representation of the SELinux label broken into 4 parts // Context is a representation of the SELinux label broken into 4 parts
@ -280,5 +282,7 @@ func GetDefaultContextWithLevel(user, level, scon string) (string, error) {
// PrivContainerMountLabel returns mount label for privileged containers // PrivContainerMountLabel returns mount label for privileged containers
func PrivContainerMountLabel() string { func PrivContainerMountLabel() string {
// Make sure label is initialized.
_ = label("")
return privContainerMountLabel return privContainerMountLabel
} }

View File

@ -12,7 +12,6 @@ import (
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
"regexp"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
@ -34,8 +33,6 @@ const (
xattrNameSelinux = "security.selinux" xattrNameSelinux = "security.selinux"
) )
var policyRoot = filepath.Join(selinuxDir, readConfig(selinuxTypeTag))
type selinuxState struct { type selinuxState struct {
enabledSet bool enabledSet bool
enabled bool enabled bool
@ -70,7 +67,6 @@ const (
) )
var ( var (
assignRegex = regexp.MustCompile(`^([^=]+)=(.*)$`)
readOnlyFileLabel string readOnlyFileLabel string
state = selinuxState{ state = selinuxState{
mcsList: make(map[string]bool), mcsList: make(map[string]bool),
@ -79,8 +75,24 @@ var (
// for attrPath() // for attrPath()
attrPathOnce sync.Once attrPathOnce sync.Once
haveThreadSelf bool haveThreadSelf bool
// for policyRoot()
policyRootOnce sync.Once
policyRootVal string
// for label()
loadLabelsOnce sync.Once
labels map[string]string
) )
func policyRoot() string {
policyRootOnce.Do(func() {
policyRootVal = filepath.Join(selinuxDir, readConfig(selinuxTypeTag))
})
return policyRootVal
}
func (s *selinuxState) setEnable(enabled bool) bool { func (s *selinuxState) setEnable(enabled bool) bool {
s.Lock() s.Lock()
defer s.Unlock() defer s.Unlock()
@ -222,7 +234,7 @@ func readConfig(target string) string {
scanner := bufio.NewScanner(in) scanner := bufio.NewScanner(in)
for scanner.Scan() { for scanner.Scan() {
line := strings.TrimSpace(scanner.Text()) line := bytes.TrimSpace(scanner.Bytes())
if len(line) == 0 { if len(line) == 0 {
// Skip blank lines // Skip blank lines
continue continue
@ -231,11 +243,12 @@ func readConfig(target string) string {
// Skip comments // Skip comments
continue continue
} }
if groups := assignRegex.FindStringSubmatch(line); groups != nil { fields := bytes.SplitN(line, []byte{'='}, 2)
key, val := strings.TrimSpace(groups[1]), strings.TrimSpace(groups[2]) if len(fields) != 2 {
if key == target { continue
return strings.Trim(val, "\"") }
} if bytes.Equal(fields[0], []byte(target)) {
return string(bytes.Trim(fields[1], `"`))
} }
} }
return "" return ""
@ -274,12 +287,15 @@ func readCon(fpath string) (string, error) {
if err := isProcHandle(in); err != nil { if err := isProcHandle(in); err != nil {
return "", err return "", err
} }
return readConFd(in)
}
var retval string func readConFd(in *os.File) (string, error) {
if _, err := fmt.Fscanf(in, "%s", &retval); err != nil { data, err := ioutil.ReadAll(in)
if err != nil {
return "", err return "", err
} }
return strings.Trim(retval, "\x00"), nil return string(bytes.TrimSuffix(data, []byte{0})), nil
} }
// classIndex returns the int index for an object class in the loaded policy, // classIndex returns the int index for an object class in the loaded policy,
@ -389,7 +405,7 @@ func writeCon(fpath, val string) error {
_, err = out.Write(nil) _, err = out.Write(nil)
} }
if err != nil { if err != nil {
return &os.PathError{Op: "write", Path: fpath, Err: err} return err
} }
return nil return nil
} }
@ -664,11 +680,7 @@ func readWriteCon(fpath string, val string) (string, error) {
return "", err return "", err
} }
var retval string return readConFd(f)
if _, err := fmt.Fscanf(f, "%s", &retval); err != nil {
return "", err
}
return strings.Trim(retval, "\x00"), nil
} }
// setExecLabel sets the SELinux label that the kernel will use for any programs // setExecLabel sets the SELinux label that the kernel will use for any programs
@ -723,10 +735,10 @@ func keyLabel() (string, error) {
// get returns the Context as a string // get returns the Context as a string
func (c Context) get() string { func (c Context) get() string {
if c["level"] != "" { if level := c["level"]; level != "" {
return fmt.Sprintf("%s:%s:%s:%s", c["user"], c["role"], c["type"], c["level"]) return c["user"] + ":" + c["role"] + ":" + c["type"] + ":" + level
} }
return fmt.Sprintf("%s:%s:%s", c["user"], c["role"], c["type"]) return c["user"] + ":" + c["role"] + ":" + c["type"]
} }
// newContext creates a new Context struct from the specified label // newContext creates a new Context struct from the specified label
@ -891,24 +903,21 @@ func openContextFile() (*os.File, error) {
if f, err := os.Open(contextFile); err == nil { if f, err := os.Open(contextFile); err == nil {
return f, nil return f, nil
} }
lxcPath := filepath.Join(policyRoot, "/contexts/lxc_contexts") return os.Open(filepath.Join(policyRoot(), "/contexts/lxc_contexts"))
return os.Open(lxcPath)
} }
var labels, privContainerMountLabel = loadLabels() func loadLabels() {
labels = make(map[string]string)
func loadLabels() (map[string]string, string) {
labels := make(map[string]string)
in, err := openContextFile() in, err := openContextFile()
if err != nil { if err != nil {
return labels, "" return
} }
defer in.Close() defer in.Close()
scanner := bufio.NewScanner(in) scanner := bufio.NewScanner(in)
for scanner.Scan() { for scanner.Scan() {
line := strings.TrimSpace(scanner.Text()) line := bytes.TrimSpace(scanner.Bytes())
if len(line) == 0 { if len(line) == 0 {
// Skip blank lines // Skip blank lines
continue continue
@ -917,38 +926,47 @@ func loadLabels() (map[string]string, string) {
// Skip comments // Skip comments
continue continue
} }
if groups := assignRegex.FindStringSubmatch(line); groups != nil { fields := bytes.SplitN(line, []byte{'='}, 2)
key, val := strings.TrimSpace(groups[1]), strings.TrimSpace(groups[2]) if len(fields) != 2 {
labels[key] = strings.Trim(val, "\"") continue
} }
key, val := bytes.TrimSpace(fields[0]), bytes.TrimSpace(fields[1])
labels[string(key)] = string(bytes.Trim(val, `"`))
} }
con, _ := NewContext(labels["file"]) con, _ := NewContext(labels["file"])
con["level"] = fmt.Sprintf("s0:c%d,c%d", maxCategory-2, maxCategory-1) con["level"] = fmt.Sprintf("s0:c%d,c%d", maxCategory-2, maxCategory-1)
reserveLabel(con.get()) privContainerMountLabel = con.get()
return labels, con.get() reserveLabel(privContainerMountLabel)
}
func label(key string) string {
loadLabelsOnce.Do(func() {
loadLabels()
})
return labels[key]
} }
// kvmContainerLabels returns the default processLabel and mountLabel to be used // kvmContainerLabels returns the default processLabel and mountLabel to be used
// for kvm containers by the calling process. // for kvm containers by the calling process.
func kvmContainerLabels() (string, string) { func kvmContainerLabels() (string, string) {
processLabel := labels["kvm_process"] processLabel := label("kvm_process")
if processLabel == "" { if processLabel == "" {
processLabel = labels["process"] processLabel = label("process")
} }
return addMcs(processLabel, labels["file"]) return addMcs(processLabel, label("file"))
} }
// initContainerLabels returns the default processLabel and file labels to be // initContainerLabels returns the default processLabel and file labels to be
// used for containers running an init system like systemd by the calling process. // used for containers running an init system like systemd by the calling process.
func initContainerLabels() (string, string) { func initContainerLabels() (string, string) {
processLabel := labels["init_process"] processLabel := label("init_process")
if processLabel == "" { if processLabel == "" {
processLabel = labels["process"] processLabel = label("process")
} }
return addMcs(processLabel, labels["file"]) return addMcs(processLabel, label("file"))
} }
// containerLabels returns an allocated processLabel and fileLabel to be used for // containerLabels returns an allocated processLabel and fileLabel to be used for
@ -958,9 +976,9 @@ func containerLabels() (processLabel string, fileLabel string) {
return "", "" return "", ""
} }
processLabel = labels["process"] processLabel = label("process")
fileLabel = labels["file"] fileLabel = label("file")
readOnlyFileLabel = labels["ro_file"] readOnlyFileLabel = label("ro_file")
if processLabel == "" || fileLabel == "" { if processLabel == "" || fileLabel == "" {
return "", fileLabel return "", fileLabel
@ -1180,15 +1198,14 @@ func getDefaultContextFromReaders(c *defaultSECtx) (string, error) {
} }
func getDefaultContextWithLevel(user, level, scon string) (string, error) { func getDefaultContextWithLevel(user, level, scon string) (string, error) {
userPath := filepath.Join(policyRoot, selinuxUsersDir, user) userPath := filepath.Join(policyRoot(), selinuxUsersDir, user)
defaultPath := filepath.Join(policyRoot, defaultContexts)
fu, err := os.Open(userPath) fu, err := os.Open(userPath)
if err != nil { if err != nil {
return "", err return "", err
} }
defer fu.Close() defer fu.Close()
defaultPath := filepath.Join(policyRoot(), defaultContexts)
fd, err := os.Open(defaultPath) fd, err := os.Open(defaultPath)
if err != nil { if err != nil {
return "", err return "", err

View File

@ -2,8 +2,6 @@
package selinux package selinux
const privContainerMountLabel = ""
func setDisabled() { func setDisabled() {
} }
@ -152,3 +150,7 @@ func disableSecOpt() []string {
func getDefaultContextWithLevel(user, level, scon string) (string, error) { func getDefaultContextWithLevel(user, level, scon string) (string, error) {
return "", nil return "", nil
} }
func label(_ string) string {
return ""
}

2
vendor/modules.txt vendored
View File

@ -524,7 +524,7 @@ github.com/opencontainers/runtime-tools/generate
github.com/opencontainers/runtime-tools/generate/seccomp github.com/opencontainers/runtime-tools/generate/seccomp
github.com/opencontainers/runtime-tools/specerror github.com/opencontainers/runtime-tools/specerror
github.com/opencontainers/runtime-tools/validate github.com/opencontainers/runtime-tools/validate
# github.com/opencontainers/selinux v1.8.4 # github.com/opencontainers/selinux v1.8.5
github.com/opencontainers/selinux/go-selinux github.com/opencontainers/selinux/go-selinux
github.com/opencontainers/selinux/go-selinux/label github.com/opencontainers/selinux/go-selinux/label
github.com/opencontainers/selinux/pkg/pwalk github.com/opencontainers/selinux/pkg/pwalk