diff options
| author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-05-11 10:36:54 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-11 10:36:54 -0400 |
| commit | 8dcd5b893feb8b3b34386e6688d20b7ef098228b (patch) | |
| tree | d8faac5bbd3c5dd91c0de0e94c5d9252c5485d0d /vendor/github.com/opencontainers/runc/libcontainer/apparmor | |
| parent | 58915f2974c6f14ff2aa34004e7d581d1a05a148 (diff) | |
| parent | d71672c57b5e9e41cb526b290b8b3704232e814a (diff) | |
| download | podman-8dcd5b893feb8b3b34386e6688d20b7ef098228b.tar.gz podman-8dcd5b893feb8b3b34386e6688d20b7ef098228b.tar.bz2 podman-8dcd5b893feb8b3b34386e6688d20b7ef098228b.zip | |
Merge pull request #10304 from containers/dependabot/go_modules/github.com/opencontainers/runc-1.0.0-rc94
Bump github.com/opencontainers/runc from 1.0.0-rc93 to 1.0.0-rc94
Diffstat (limited to 'vendor/github.com/opencontainers/runc/libcontainer/apparmor')
| -rw-r--r-- | vendor/github.com/opencontainers/runc/libcontainer/apparmor/apparmor_linux.go | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/vendor/github.com/opencontainers/runc/libcontainer/apparmor/apparmor_linux.go b/vendor/github.com/opencontainers/runc/libcontainer/apparmor/apparmor_linux.go index 73965f12d..5da14fb3b 100644 --- a/vendor/github.com/opencontainers/runc/libcontainer/apparmor/apparmor_linux.go +++ b/vendor/github.com/opencontainers/runc/libcontainer/apparmor/apparmor_linux.go @@ -1,27 +1,41 @@ package apparmor import ( - "bytes" + "errors" "fmt" "io/ioutil" "os" + "sync" "github.com/opencontainers/runc/libcontainer/utils" ) +var ( + appArmorEnabled bool + checkAppArmor sync.Once +) + // IsEnabled returns true if apparmor is enabled for the host. func IsEnabled() bool { - if _, err := os.Stat("/sys/kernel/security/apparmor"); err == nil { - buf, err := ioutil.ReadFile("/sys/module/apparmor/parameters/enabled") - return err == nil && bytes.HasPrefix(buf, []byte("Y")) - } - return false + checkAppArmor.Do(func() { + if _, err := os.Stat("/sys/kernel/security/apparmor"); err == nil { + buf, err := ioutil.ReadFile("/sys/module/apparmor/parameters/enabled") + appArmorEnabled = err == nil && len(buf) > 1 && buf[0] == 'Y' + } + }) + return appArmorEnabled } func setProcAttr(attr, value string) error { // Under AppArmor you can only change your own attr, so use /proc/self/ // instead of /proc/<tid>/ like libapparmor does - f, err := os.OpenFile("/proc/self/attr/"+attr, os.O_WRONLY, 0) + attrPath := "/proc/self/attr/apparmor/" + attr + if _, err := os.Stat(attrPath); errors.Is(err, os.ErrNotExist) { + // fall back to the old convention + attrPath = "/proc/self/attr/" + attr + } + + f, err := os.OpenFile(attrPath, os.O_WRONLY, 0) if err != nil { return err } |
