2014-05-06 18:28:19 +00:00
|
|
|
diff -up libselinux-2.3/golang/Makefile.rhat libselinux-2.3/golang/Makefile
|
|
|
|
--- libselinux-2.3/golang/Makefile.rhat 2014-05-06 14:23:28.320639312 -0400
|
|
|
|
+++ libselinux-2.3/golang/Makefile 2014-05-06 14:23:28.320639312 -0400
|
2014-02-14 14:21:36 +00:00
|
|
|
@@ -0,0 +1,22 @@
|
2013-12-23 15:14:52 +00:00
|
|
|
+# Installation directories.
|
|
|
|
+PREFIX ?= $(DESTDIR)/usr
|
2014-01-24 16:10:54 +00:00
|
|
|
+LIBDIR ?= $(DESTDIR)/usr/lib
|
|
|
|
+GODIR ?= $(LIBDIR)/golang/src/pkg/github.com/selinux
|
2013-12-23 15:14:52 +00:00
|
|
|
+all:
|
|
|
|
+
|
|
|
|
+install:
|
|
|
|
+ [ -d $(GODIR) ] || mkdir -p $(GODIR)
|
|
|
|
+ install -m 644 selinux.go $(GODIR)
|
|
|
|
+
|
|
|
|
+test:
|
2014-02-14 14:21:36 +00:00
|
|
|
+ @mkdir selinux
|
|
|
|
+ @cp selinux.go selinux
|
|
|
|
+ GOPATH=$(pwd) go run test.go
|
|
|
|
+ @rm -rf selinux
|
2013-12-23 15:14:52 +00:00
|
|
|
+
|
|
|
|
+clean:
|
2014-02-14 14:21:36 +00:00
|
|
|
+ @rm -f *~
|
|
|
|
+ @rm -rf selinux
|
2013-12-23 15:14:52 +00:00
|
|
|
+indent:
|
|
|
|
+
|
|
|
|
+relabel:
|
2014-05-06 18:28:19 +00:00
|
|
|
diff -up libselinux-2.3/golang/selinux.go.rhat libselinux-2.3/golang/selinux.go
|
|
|
|
--- libselinux-2.3/golang/selinux.go.rhat 2014-05-06 14:23:28.321639313 -0400
|
|
|
|
+++ libselinux-2.3/golang/selinux.go 2014-05-06 14:23:28.321639313 -0400
|
2014-02-20 22:21:25 +00:00
|
|
|
@@ -0,0 +1,412 @@
|
2013-12-23 15:14:52 +00:00
|
|
|
+package selinux
|
|
|
|
+
|
|
|
|
+/*
|
|
|
|
+ The selinux package is a go bindings to libselinux required to add selinux
|
|
|
|
+ support to docker.
|
|
|
|
+
|
|
|
|
+ Author Dan Walsh <dwalsh@redhat.com>
|
|
|
|
+
|
|
|
|
+ Used some ideas/code from the go-ini packages https://github.com/vaughan0
|
|
|
|
+ By Vaughan Newton
|
|
|
|
+*/
|
|
|
|
+
|
|
|
|
+// #cgo pkg-config: libselinux
|
|
|
|
+// #include <selinux/selinux.h>
|
|
|
|
+// #include <stdlib.h>
|
|
|
|
+import "C"
|
|
|
|
+import (
|
2014-02-20 22:21:25 +00:00
|
|
|
+ "bufio"
|
2013-12-23 15:14:52 +00:00
|
|
|
+ "crypto/rand"
|
2014-02-20 22:21:25 +00:00
|
|
|
+ "encoding/binary"
|
2013-12-23 15:14:52 +00:00
|
|
|
+ "fmt"
|
|
|
|
+ "io"
|
|
|
|
+ "os"
|
2014-02-20 22:21:25 +00:00
|
|
|
+ "path"
|
|
|
|
+ "path/filepath"
|
|
|
|
+ "regexp"
|
2013-12-23 15:14:52 +00:00
|
|
|
+ "strings"
|
2014-02-20 22:21:25 +00:00
|
|
|
+ "unsafe"
|
2013-12-23 15:14:52 +00:00
|
|
|
+)
|
|
|
|
+
|
|
|
|
+var (
|
2014-02-20 22:21:25 +00:00
|
|
|
+ assignRegex = regexp.MustCompile(`^([^=]+)=(.*)$`)
|
|
|
|
+ mcsList = make(map[string]bool)
|
2013-12-23 15:14:52 +00:00
|
|
|
+)
|
|
|
|
+
|
2014-02-20 22:21:25 +00:00
|
|
|
+func Matchpathcon(path string, mode os.FileMode) (string, error) {
|
2013-12-23 15:14:52 +00:00
|
|
|
+ var con C.security_context_t
|
|
|
|
+ var scon string
|
2014-02-20 22:21:25 +00:00
|
|
|
+ rc, err := C.matchpathcon(C.CString(path), C.mode_t(mode), &con)
|
2013-12-23 15:14:52 +00:00
|
|
|
+ if rc == 0 {
|
|
|
|
+ scon = C.GoString(con)
|
|
|
|
+ C.free(unsafe.Pointer(con))
|
|
|
|
+ }
|
|
|
|
+ return scon, err
|
|
|
|
+}
|
|
|
|
+
|
2014-02-20 22:21:25 +00:00
|
|
|
+func Setfilecon(path, scon string) (int, error) {
|
|
|
|
+ rc, err := C.lsetfilecon(C.CString(path), C.CString(scon))
|
2013-12-23 15:14:52 +00:00
|
|
|
+ return int(rc), err
|
|
|
|
+}
|
|
|
|
+
|
2014-02-14 14:21:36 +00:00
|
|
|
+func Getfilecon(path string) (string, error) {
|
|
|
|
+ var scon C.security_context_t
|
|
|
|
+ var fcon string
|
2014-02-20 22:21:25 +00:00
|
|
|
+ rc, err := C.lgetfilecon(C.CString(path), &scon)
|
|
|
|
+ if rc >= 0 {
|
|
|
|
+ fcon = C.GoString(scon)
|
2014-02-14 14:21:36 +00:00
|
|
|
+ err = nil
|
|
|
|
+ }
|
|
|
|
+ return fcon, err
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func Setfscreatecon(scon string) (int, error) {
|
|
|
|
+ var (
|
2014-02-20 22:21:25 +00:00
|
|
|
+ rc C.int
|
2014-02-14 14:21:36 +00:00
|
|
|
+ err error
|
|
|
|
+ )
|
2014-02-20 22:21:25 +00:00
|
|
|
+ if scon != "" {
|
2014-02-14 14:21:36 +00:00
|
|
|
+ rc, err = C.setfscreatecon(C.CString(scon))
|
|
|
|
+ } else {
|
|
|
|
+ rc, err = C.setfscreatecon(nil)
|
|
|
|
+ }
|
|
|
|
+ return int(rc), err
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func Getfscreatecon() (string, error) {
|
|
|
|
+ var scon C.security_context_t
|
|
|
|
+ var fcon string
|
2014-02-20 22:21:25 +00:00
|
|
|
+ rc, err := C.getfscreatecon(&scon)
|
|
|
|
+ if rc >= 0 {
|
|
|
|
+ fcon = C.GoString(scon)
|
2014-02-14 14:21:36 +00:00
|
|
|
+ err = nil
|
|
|
|
+ C.freecon(scon)
|
|
|
|
+ }
|
|
|
|
+ return fcon, err
|
|
|
|
+}
|
|
|
|
+
|
2014-02-20 22:21:25 +00:00
|
|
|
+func Getcon() string {
|
2014-02-14 14:21:36 +00:00
|
|
|
+ var pcon C.security_context_t
|
|
|
|
+ C.getcon(&pcon)
|
|
|
|
+ scon := C.GoString(pcon)
|
|
|
|
+ C.freecon(pcon)
|
|
|
|
+ return scon
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func Getpidcon(pid int) (string, error) {
|
|
|
|
+ var pcon C.security_context_t
|
|
|
|
+ var scon string
|
|
|
|
+ rc, err := C.getpidcon(C.pid_t(pid), &pcon)
|
2014-02-20 22:21:25 +00:00
|
|
|
+ if rc >= 0 {
|
2014-02-14 14:21:36 +00:00
|
|
|
+ scon = C.GoString(pcon)
|
|
|
|
+ C.freecon(pcon)
|
|
|
|
+ err = nil
|
|
|
|
+ }
|
|
|
|
+ return scon, err
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func Getpeercon(socket int) (string, error) {
|
|
|
|
+ var pcon C.security_context_t
|
|
|
|
+ var scon string
|
|
|
|
+ rc, err := C.getpeercon(C.int(socket), &pcon)
|
2014-02-20 22:21:25 +00:00
|
|
|
+ if rc >= 0 {
|
2014-02-14 14:21:36 +00:00
|
|
|
+ scon = C.GoString(pcon)
|
|
|
|
+ C.freecon(pcon)
|
|
|
|
+ err = nil
|
|
|
|
+ }
|
|
|
|
+ return scon, err
|
|
|
|
+}
|
|
|
|
+
|
2014-02-20 22:21:25 +00:00
|
|
|
+func Setexeccon(scon string) error {
|
2013-12-23 15:14:52 +00:00
|
|
|
+ var val *C.char
|
2014-02-20 22:21:25 +00:00
|
|
|
+ if !SelinuxEnabled() {
|
|
|
|
+ return nil
|
2013-12-23 15:14:52 +00:00
|
|
|
+ }
|
|
|
|
+ if scon != "" {
|
|
|
|
+ val = C.CString(scon)
|
|
|
|
+ } else {
|
|
|
|
+ val = nil
|
|
|
|
+ }
|
2014-02-20 22:21:25 +00:00
|
|
|
+ _, err := C.setexeccon(val)
|
|
|
|
+ return err
|
2013-12-23 15:14:52 +00:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type Context struct {
|
|
|
|
+ con []string
|
|
|
|
+}
|
2014-02-20 22:21:25 +00:00
|
|
|
+
|
|
|
|
+func (c *Context) SetUser(user string) {
|
|
|
|
+ c.con[0] = user
|
2013-12-23 15:14:52 +00:00
|
|
|
+}
|
2014-02-20 22:21:25 +00:00
|
|
|
+func (c *Context) GetUser() string {
|
2013-12-23 15:14:52 +00:00
|
|
|
+ return c.con[0]
|
|
|
|
+}
|
2014-02-20 22:21:25 +00:00
|
|
|
+func (c *Context) SetRole(role string) {
|
|
|
|
+ c.con[1] = role
|
2013-12-23 15:14:52 +00:00
|
|
|
+}
|
2014-02-20 22:21:25 +00:00
|
|
|
+func (c *Context) GetRole() string {
|
2013-12-23 15:14:52 +00:00
|
|
|
+ return c.con[1]
|
|
|
|
+}
|
2014-02-20 22:21:25 +00:00
|
|
|
+func (c *Context) SetType(setype string) {
|
|
|
|
+ c.con[2] = setype
|
2013-12-23 15:14:52 +00:00
|
|
|
+}
|
2014-02-20 22:21:25 +00:00
|
|
|
+func (c *Context) GetType() string {
|
2013-12-23 15:14:52 +00:00
|
|
|
+ return c.con[2]
|
|
|
|
+}
|
2014-02-20 22:21:25 +00:00
|
|
|
+func (c *Context) SetLevel(mls string) {
|
|
|
|
+ c.con[3] = mls
|
2013-12-23 15:14:52 +00:00
|
|
|
+}
|
2014-02-20 22:21:25 +00:00
|
|
|
+func (c *Context) GetLevel() string {
|
2013-12-23 15:14:52 +00:00
|
|
|
+ return c.con[3]
|
|
|
|
+}
|
2014-02-20 22:21:25 +00:00
|
|
|
+func (c *Context) Get() string {
|
|
|
|
+ return strings.Join(c.con, ":")
|
2013-12-23 15:14:52 +00:00
|
|
|
+}
|
|
|
|
+func (c *Context) Set(scon string) {
|
2014-02-20 22:21:25 +00:00
|
|
|
+ c.con = strings.SplitN(scon, ":", 4)
|
2013-12-23 15:14:52 +00:00
|
|
|
+}
|
2014-02-20 22:21:25 +00:00
|
|
|
+func NewContext(scon string) Context {
|
2013-12-23 15:14:52 +00:00
|
|
|
+ var con Context
|
|
|
|
+ con.Set(scon)
|
|
|
|
+ return con
|
|
|
|
+}
|
|
|
|
+
|
2014-02-20 22:21:25 +00:00
|
|
|
+func SelinuxEnabled() bool {
|
2013-12-23 15:14:52 +00:00
|
|
|
+ b := C.is_selinux_enabled()
|
|
|
|
+ if b > 0 {
|
2014-02-20 22:21:25 +00:00
|
|
|
+ return true
|
2013-12-23 15:14:52 +00:00
|
|
|
+ }
|
|
|
|
+ return false
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+const (
|
2014-02-20 22:21:25 +00:00
|
|
|
+ Enforcing = 1
|
2013-12-23 15:14:52 +00:00
|
|
|
+ Permissive = 0
|
2014-02-20 22:21:25 +00:00
|
|
|
+ Disabled = -1
|
2013-12-23 15:14:52 +00:00
|
|
|
+)
|
|
|
|
+
|
2014-02-20 22:21:25 +00:00
|
|
|
+func SelinuxGetEnforce() int {
|
2013-12-23 15:14:52 +00:00
|
|
|
+ return int(C.security_getenforce())
|
|
|
|
+}
|
|
|
|
+
|
2014-02-20 22:21:25 +00:00
|
|
|
+func SelinuxGetEnforceMode() int {
|
2013-12-23 15:14:52 +00:00
|
|
|
+ var enforce C.int
|
|
|
|
+ C.selinux_getenforcemode(&enforce)
|
|
|
|
+ return int(enforce)
|
|
|
|
+}
|
|
|
|
+
|
2014-02-20 22:21:25 +00:00
|
|
|
+func mcsAdd(mcs string) {
|
|
|
|
+ mcsList[mcs] = true
|
2013-12-23 15:14:52 +00:00
|
|
|
+}
|
|
|
|
+
|
2014-02-20 22:21:25 +00:00
|
|
|
+func mcsDelete(mcs string) {
|
|
|
|
+ mcsList[mcs] = false
|
2013-12-23 15:14:52 +00:00
|
|
|
+}
|
|
|
|
+
|
2014-02-20 22:21:25 +00:00
|
|
|
+func mcsExists(mcs string) bool {
|
|
|
|
+ return mcsList[mcs]
|
2013-12-23 15:14:52 +00:00
|
|
|
+}
|
|
|
|
+
|
2014-02-20 22:21:25 +00:00
|
|
|
+func IntToMcs(id int, catRange uint32) string {
|
|
|
|
+ if (id < 1) || (id > 523776) {
|
|
|
|
+ return ""
|
|
|
|
+ }
|
2014-01-24 16:10:54 +00:00
|
|
|
+
|
2014-02-20 22:21:25 +00:00
|
|
|
+ SETSIZE := int(catRange)
|
|
|
|
+ TIER := SETSIZE
|
2014-01-24 16:10:54 +00:00
|
|
|
+
|
2014-02-20 22:21:25 +00:00
|
|
|
+ ORD := id
|
|
|
|
+ for ORD > TIER {
|
|
|
|
+ ORD = ORD - TIER
|
|
|
|
+ TIER -= 1
|
2014-01-24 16:10:54 +00:00
|
|
|
+ }
|
2014-02-20 22:21:25 +00:00
|
|
|
+ TIER = SETSIZE - TIER
|
|
|
|
+ ORD = ORD + TIER
|
|
|
|
+ return fmt.Sprintf("s0:c%d,c%d", TIER, ORD)
|
2014-01-24 16:10:54 +00:00
|
|
|
+}
|
|
|
|
+
|
2014-02-20 22:21:25 +00:00
|
|
|
+func uniqMcs(catRange uint32) string {
|
2013-12-23 15:14:52 +00:00
|
|
|
+ var n uint32
|
2014-02-20 22:21:25 +00:00
|
|
|
+ var c1, c2 uint32
|
2013-12-23 15:14:52 +00:00
|
|
|
+ var mcs string
|
2014-02-20 22:21:25 +00:00
|
|
|
+ for {
|
2013-12-23 15:14:52 +00:00
|
|
|
+ binary.Read(rand.Reader, binary.LittleEndian, &n)
|
|
|
|
+ c1 = n % catRange
|
|
|
|
+ binary.Read(rand.Reader, binary.LittleEndian, &n)
|
|
|
|
+ c2 = n % catRange
|
|
|
|
+ if c1 == c2 {
|
|
|
|
+ continue
|
|
|
|
+ } else {
|
|
|
|
+ if c1 > c2 {
|
|
|
|
+ t := c1
|
|
|
|
+ c1 = c2
|
|
|
|
+ c2 = t
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ mcs = fmt.Sprintf("s0:c%d,c%d", c1, c2)
|
2014-02-20 22:21:25 +00:00
|
|
|
+ if mcsExists(mcs) {
|
2013-12-23 15:14:52 +00:00
|
|
|
+ continue
|
|
|
|
+ }
|
2014-02-20 22:21:25 +00:00
|
|
|
+ mcsAdd(mcs)
|
2013-12-23 15:14:52 +00:00
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ return mcs
|
|
|
|
+}
|
2014-02-20 22:21:25 +00:00
|
|
|
+func freeContext(processLabel string) {
|
2013-12-23 15:14:52 +00:00
|
|
|
+ var scon Context
|
2014-02-20 22:21:25 +00:00
|
|
|
+ scon = NewContext(processLabel)
|
|
|
|
+ mcsDelete(scon.GetLevel())
|
2013-12-23 15:14:52 +00:00
|
|
|
+}
|
|
|
|
+
|
2014-02-20 22:21:25 +00:00
|
|
|
+func GetLxcContexts() (processLabel string, fileLabel string) {
|
2013-12-23 15:14:52 +00:00
|
|
|
+ var val, key string
|
|
|
|
+ var bufin *bufio.Reader
|
2014-02-20 22:21:25 +00:00
|
|
|
+ if !SelinuxEnabled() {
|
2013-12-23 15:14:52 +00:00
|
|
|
+ return
|
|
|
|
+ }
|
2014-02-20 22:21:25 +00:00
|
|
|
+ lxcPath := C.GoString(C.selinux_lxc_contexts_path())
|
|
|
|
+ fileLabel = "system_u:object_r:svirt_sandbox_file_t:s0"
|
|
|
|
+ processLabel = "system_u:system_r:svirt_lxc_net_t:s0"
|
2013-12-23 15:14:52 +00:00
|
|
|
+
|
2014-02-20 22:21:25 +00:00
|
|
|
+ in, err := os.Open(lxcPath)
|
2013-12-23 15:14:52 +00:00
|
|
|
+ if err != nil {
|
|
|
|
+ goto exit
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ defer in.Close()
|
|
|
|
+ bufin = bufio.NewReader(in)
|
|
|
|
+
|
|
|
|
+ for done := false; !done; {
|
|
|
|
+ var line string
|
|
|
|
+ if line, err = bufin.ReadString('\n'); err != nil {
|
|
|
|
+ if err == io.EOF {
|
|
|
|
+ done = true
|
|
|
|
+ } else {
|
|
|
|
+ goto exit
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ line = strings.TrimSpace(line)
|
|
|
|
+ if len(line) == 0 {
|
|
|
|
+ // Skip blank lines
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ if line[0] == ';' || line[0] == '#' {
|
|
|
|
+ // Skip comments
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ if groups := assignRegex.FindStringSubmatch(line); groups != nil {
|
|
|
|
+ key, val = strings.TrimSpace(groups[1]), strings.TrimSpace(groups[2])
|
|
|
|
+ if key == "process" {
|
2014-02-20 22:21:25 +00:00
|
|
|
+ processLabel = strings.Trim(val, "\"")
|
2013-12-23 15:14:52 +00:00
|
|
|
+ }
|
|
|
|
+ if key == "file" {
|
2014-02-20 22:21:25 +00:00
|
|
|
+ fileLabel = strings.Trim(val, "\"")
|
2013-12-23 15:14:52 +00:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+exit:
|
|
|
|
+ var scon Context
|
2014-02-20 22:21:25 +00:00
|
|
|
+ mcs := IntToMcs(os.Getpid(), 1024)
|
|
|
|
+ scon = NewContext(processLabel)
|
|
|
|
+ scon.SetLevel(mcs)
|
|
|
|
+ processLabel = scon.Get()
|
|
|
|
+ scon = NewContext(fileLabel)
|
|
|
|
+ scon.SetLevel(mcs)
|
|
|
|
+ fileLabel = scon.Get()
|
|
|
|
+ return processLabel, fileLabel
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func CopyLevel(src, dest string) (string, error) {
|
|
|
|
+ if !SelinuxEnabled() {
|
2013-12-23 15:14:52 +00:00
|
|
|
+ return "", nil
|
|
|
|
+ }
|
|
|
|
+ if src == "" {
|
|
|
|
+ return "", nil
|
|
|
|
+ }
|
|
|
|
+ rc, err := C.security_check_context(C.CString(src))
|
|
|
|
+ if rc != 0 {
|
|
|
|
+ return "", err
|
|
|
|
+ }
|
|
|
|
+ rc, err = C.security_check_context(C.CString(dest))
|
|
|
|
+ if rc != 0 {
|
|
|
|
+ return "", err
|
|
|
|
+ }
|
2014-02-20 22:21:25 +00:00
|
|
|
+ scon := NewContext(src)
|
|
|
|
+ tcon := NewContext(dest)
|
|
|
|
+ tcon.SetLevel(scon.GetLevel())
|
2013-12-23 15:14:52 +00:00
|
|
|
+ return tcon.Get(), nil
|
|
|
|
+}
|
|
|
|
+
|
2014-02-20 22:21:25 +00:00
|
|
|
+func RestoreCon(fpath string, recurse bool) error {
|
|
|
|
+ var flabel string
|
|
|
|
+ var err error
|
|
|
|
+ var fs os.FileInfo
|
|
|
|
+
|
|
|
|
+ if !SelinuxEnabled() {
|
|
|
|
+ return nil
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if recurse {
|
|
|
|
+ var paths []string
|
|
|
|
+ var err error
|
|
|
|
+
|
|
|
|
+ if paths, err = filepath.Glob(path.Join(fpath, "**", "*")); err != nil {
|
|
|
|
+ return fmt.Errorf("Unable to find directory %v: %v", fpath, err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for _, fpath := range paths {
|
|
|
|
+ if err = RestoreCon(fpath, false); err != nil {
|
|
|
|
+ return fmt.Errorf("Unable to restore selinux context for %v: %v", fpath, err)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return nil
|
|
|
|
+ }
|
|
|
|
+ if fs, err = os.Stat(fpath); err != nil {
|
|
|
|
+ return fmt.Errorf("Unable stat %v: %v", fpath, err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if flabel, err = Matchpathcon(fpath, fs.Mode()); flabel == "" {
|
|
|
|
+ return fmt.Errorf("Unable to get context for %v: %v", fpath, err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if rc, err := Setfilecon(fpath, flabel); rc != 0 {
|
|
|
|
+ return fmt.Errorf("Unable to set selinux context for %v: %v", fpath, err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return nil
|
|
|
|
+}
|
|
|
|
+
|
2013-12-23 15:14:52 +00:00
|
|
|
+func Test() {
|
2014-02-20 22:21:25 +00:00
|
|
|
+ var plabel, flabel string
|
|
|
|
+ if !SelinuxEnabled() {
|
2013-12-23 15:14:52 +00:00
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
2014-02-20 22:21:25 +00:00
|
|
|
+ plabel, flabel = GetLxcContexts()
|
2013-12-23 15:14:52 +00:00
|
|
|
+ fmt.Println(plabel)
|
|
|
|
+ fmt.Println(flabel)
|
2014-02-20 22:21:25 +00:00
|
|
|
+ freeContext(plabel)
|
|
|
|
+ plabel, flabel = GetLxcContexts()
|
2013-12-23 15:14:52 +00:00
|
|
|
+ fmt.Println(plabel)
|
|
|
|
+ fmt.Println(flabel)
|
2014-02-20 22:21:25 +00:00
|
|
|
+ freeContext(plabel)
|
|
|
|
+ if SelinuxEnabled() {
|
2013-12-23 15:14:52 +00:00
|
|
|
+ fmt.Println("Enabled")
|
|
|
|
+ } else {
|
|
|
|
+ fmt.Println("Disabled")
|
|
|
|
+ }
|
2014-02-20 22:21:25 +00:00
|
|
|
+ fmt.Println("getenforce ", SelinuxGetEnforce())
|
|
|
|
+ fmt.Println("getenforcemode ", SelinuxGetEnforceMode())
|
|
|
|
+ flabel, _ = Matchpathcon("/home/dwalsh/.emacs", 0)
|
2013-12-23 15:14:52 +00:00
|
|
|
+ fmt.Println(flabel)
|
2014-01-24 16:10:54 +00:00
|
|
|
+ pid := os.Getpid()
|
2014-02-20 22:21:25 +00:00
|
|
|
+ fmt.Printf("PID:%d MCS:%s\n", pid, IntToMcs(pid, 1023))
|
2014-02-14 14:21:36 +00:00
|
|
|
+ fmt.Println(Getcon())
|
|
|
|
+ fmt.Println(Getfilecon("/etc/passwd"))
|
|
|
|
+ fmt.Println(Getpidcon(1))
|
|
|
|
+ Setfscreatecon("unconfined_u:unconfined_r:unconfined_t:s0")
|
|
|
|
+ fmt.Println(Getfscreatecon())
|
|
|
|
+ Setfscreatecon("")
|
|
|
|
+ fmt.Println(Getfscreatecon())
|
|
|
|
+ fmt.Println(Getpidcon(1))
|
|
|
|
+}
|
2014-05-06 18:28:19 +00:00
|
|
|
diff -up libselinux-2.3/golang/test.go.rhat libselinux-2.3/golang/test.go
|
|
|
|
--- libselinux-2.3/golang/test.go.rhat 2014-05-06 14:23:28.321639313 -0400
|
|
|
|
+++ libselinux-2.3/golang/test.go 2014-05-06 14:23:28.321639313 -0400
|
2014-02-14 14:21:36 +00:00
|
|
|
@@ -0,0 +1,9 @@
|
|
|
|
+package main
|
|
|
|
+
|
|
|
|
+import (
|
|
|
|
+ "./selinux"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+func main() {
|
|
|
|
+ selinux.Test()
|
2013-12-23 15:14:52 +00:00
|
|
|
+}
|
2014-05-06 18:28:19 +00:00
|
|
|
diff -up libselinux-2.3/Makefile.rhat libselinux-2.3/Makefile
|
|
|
|
--- libselinux-2.3/Makefile.rhat 2014-05-06 14:21:26.000000000 -0400
|
|
|
|
+++ libselinux-2.3/Makefile 2014-05-06 14:23:28.319639311 -0400
|
|
|
|
@@ -1,4 +1,4 @@
|
|
|
|
-SUBDIRS = src include utils man
|
|
|
|
+SUBDIRS = src include utils man golang
|
|
|
|
|
|
|
|
DISABLE_AVC ?= n
|
|
|
|
DISABLE_SETRANS ?= n
|
|
|
|
diff -up libselinux-2.3/man/man3/getfscreatecon.3.rhat libselinux-2.3/man/man3/getfscreatecon.3
|
|
|
|
--- libselinux-2.3/man/man3/getfscreatecon.3.rhat 2014-05-06 14:21:26.000000000 -0400
|
|
|
|
+++ libselinux-2.3/man/man3/getfscreatecon.3 2014-05-06 14:23:28.321639313 -0400
|
2014-02-14 14:21:36 +00:00
|
|
|
@@ -49,6 +49,11 @@ Signal handlers that perform a
|
|
|
|
must take care to
|
|
|
|
save, reset, and restore the fscreate context to avoid unexpected behavior.
|
|
|
|
.
|
|
|
|
+
|
|
|
|
+.br
|
|
|
|
+.B Note:
|
|
|
|
+Contexts are thread specific.
|
|
|
|
+
|
|
|
|
.SH "RETURN VALUE"
|
|
|
|
On error \-1 is returned.
|
|
|
|
On success 0 is returned.
|
2014-05-06 18:28:19 +00:00
|
|
|
diff -up libselinux-2.3/man/man3/getkeycreatecon.3.rhat libselinux-2.3/man/man3/getkeycreatecon.3
|
|
|
|
--- libselinux-2.3/man/man3/getkeycreatecon.3.rhat 2014-05-06 14:21:26.000000000 -0400
|
|
|
|
+++ libselinux-2.3/man/man3/getkeycreatecon.3 2014-05-06 14:23:28.322639314 -0400
|
2014-02-14 14:21:36 +00:00
|
|
|
@@ -48,6 +48,10 @@ Signal handlers that perform a
|
|
|
|
.BR setkeycreatecon ()
|
|
|
|
must take care to
|
|
|
|
save, reset, and restore the keycreate context to avoid unexpected behavior.
|
|
|
|
+
|
|
|
|
+.br
|
|
|
|
+.B Note:
|
|
|
|
+Contexts are thread specific.
|
|
|
|
.
|
|
|
|
.SH "RETURN VALUE"
|
|
|
|
On error \-1 is returned.
|
2014-05-06 18:28:19 +00:00
|
|
|
diff -up libselinux-2.3/man/man3/getsockcreatecon.3.rhat libselinux-2.3/man/man3/getsockcreatecon.3
|
|
|
|
--- libselinux-2.3/man/man3/getsockcreatecon.3.rhat 2014-05-06 14:21:26.000000000 -0400
|
|
|
|
+++ libselinux-2.3/man/man3/getsockcreatecon.3 2014-05-06 14:23:28.322639314 -0400
|
2014-02-14 14:21:36 +00:00
|
|
|
@@ -49,6 +49,11 @@ Signal handlers that perform a
|
|
|
|
must take care to
|
|
|
|
save, reset, and restore the sockcreate context to avoid unexpected behavior.
|
|
|
|
.
|
|
|
|
+
|
|
|
|
+.br
|
|
|
|
+.B Note:
|
|
|
|
+Contexts are thread specific.
|
|
|
|
+
|
|
|
|
.SH "RETURN VALUE"
|
|
|
|
On error \-1 is returned.
|
|
|
|
On success 0 is returned.
|
2014-05-06 18:28:19 +00:00
|
|
|
diff -up libselinux-2.3/man/man8/selinux.8.rhat libselinux-2.3/man/man8/selinux.8
|
|
|
|
--- libselinux-2.3/man/man8/selinux.8.rhat 2014-05-06 14:21:26.000000000 -0400
|
|
|
|
+++ libselinux-2.3/man/man8/selinux.8 2014-05-06 14:23:28.322639314 -0400
|
|
|
|
@@ -74,7 +74,7 @@ The best way to relabel the file system
|
2014-02-24 21:30:52 +00:00
|
|
|
and reboot.
|
|
|
|
.BR system\-config\-selinux ,
|
|
|
|
also has this capability. The
|
|
|
|
-.BR restorcon / fixfiles
|
|
|
|
+.BR restorecon / fixfiles
|
|
|
|
commands are also available for relabeling files.
|
|
|
|
.
|
|
|
|
.SH AUTHOR
|
2014-05-06 18:28:19 +00:00
|
|
|
diff -up libselinux-2.3/src/avc_sidtab.c.rhat libselinux-2.3/src/avc_sidtab.c
|
|
|
|
--- libselinux-2.3/src/avc_sidtab.c.rhat 2014-05-06 14:21:26.000000000 -0400
|
|
|
|
+++ libselinux-2.3/src/avc_sidtab.c 2014-05-06 14:23:28.323639315 -0400
|
2014-01-24 16:10:54 +00:00
|
|
|
@@ -81,6 +81,11 @@ sidtab_context_to_sid(struct sidtab *s,
|
|
|
|
int hvalue, rc = 0;
|
|
|
|
struct sidtab_node *cur;
|
|
|
|
|
|
|
|
+ if (! ctx) {
|
|
|
|
+ errno=EINVAL;
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
*sid = NULL;
|
|
|
|
hvalue = sidtab_hash(ctx);
|
|
|
|
|
2014-05-06 18:28:19 +00:00
|
|
|
diff -up libselinux-2.3/src/canonicalize_context.c.rhat libselinux-2.3/src/canonicalize_context.c
|
|
|
|
--- libselinux-2.3/src/canonicalize_context.c.rhat 2014-05-06 14:21:26.000000000 -0400
|
|
|
|
+++ libselinux-2.3/src/canonicalize_context.c 2014-05-06 14:23:28.323639315 -0400
|
|
|
|
@@ -17,6 +17,11 @@ int security_canonicalize_context_raw(co
|
2014-01-24 16:10:54 +00:00
|
|
|
size_t size;
|
|
|
|
int fd, ret;
|
|
|
|
|
|
|
|
+ if (! con) {
|
|
|
|
+ errno=EINVAL;
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
if (!selinux_mnt) {
|
|
|
|
errno = ENOENT;
|
|
|
|
return -1;
|
2014-05-06 18:28:19 +00:00
|
|
|
diff -up libselinux-2.3/src/check_context.c.rhat libselinux-2.3/src/check_context.c
|
|
|
|
--- libselinux-2.3/src/check_context.c.rhat 2014-05-06 14:21:26.000000000 -0400
|
|
|
|
+++ libselinux-2.3/src/check_context.c 2014-05-06 14:23:28.324639316 -0400
|
|
|
|
@@ -14,6 +14,11 @@ int security_check_context_raw(const cha
|
2014-01-24 16:10:54 +00:00
|
|
|
char path[PATH_MAX];
|
|
|
|
int fd, ret;
|
|
|
|
|
|
|
|
+ if (! con) {
|
|
|
|
+ errno=EINVAL;
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
if (!selinux_mnt) {
|
|
|
|
errno = ENOENT;
|
|
|
|
return -1;
|
2014-05-06 18:28:19 +00:00
|
|
|
diff -up libselinux-2.3/src/compute_av.c.rhat libselinux-2.3/src/compute_av.c
|
|
|
|
--- libselinux-2.3/src/compute_av.c.rhat 2014-05-06 14:21:26.000000000 -0400
|
|
|
|
+++ libselinux-2.3/src/compute_av.c 2014-05-06 14:23:28.324639316 -0400
|
|
|
|
@@ -26,6 +26,11 @@ int security_compute_av_flags_raw(const
|
2014-01-24 16:10:54 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ if ((! scon) || (! tcon)) {
|
|
|
|
+ errno=EINVAL;
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
snprintf(path, sizeof path, "%s/access", selinux_mnt);
|
|
|
|
fd = open(path, O_RDWR);
|
|
|
|
if (fd < 0)
|
2014-05-06 18:28:19 +00:00
|
|
|
diff -up libselinux-2.3/src/compute_create.c.rhat libselinux-2.3/src/compute_create.c
|
|
|
|
--- libselinux-2.3/src/compute_create.c.rhat 2014-05-06 14:21:26.000000000 -0400
|
|
|
|
+++ libselinux-2.3/src/compute_create.c 2014-05-06 14:23:28.324639316 -0400
|
|
|
|
@@ -64,6 +64,11 @@ int security_compute_create_name_raw(con
|
2014-01-24 16:10:54 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ if ((! scon) || (! tcon)) {
|
|
|
|
+ errno=EINVAL;
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
snprintf(path, sizeof path, "%s/create", selinux_mnt);
|
|
|
|
fd = open(path, O_RDWR);
|
|
|
|
if (fd < 0)
|
2014-05-06 18:28:19 +00:00
|
|
|
diff -up libselinux-2.3/src/compute_member.c.rhat libselinux-2.3/src/compute_member.c
|
|
|
|
--- libselinux-2.3/src/compute_member.c.rhat 2014-05-06 14:21:26.000000000 -0400
|
|
|
|
+++ libselinux-2.3/src/compute_member.c 2014-05-06 14:23:28.325639317 -0400
|
|
|
|
@@ -25,6 +25,11 @@ int security_compute_member_raw(const ch
|
2014-01-24 16:10:54 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ if ((! scon) || (! tcon)) {
|
|
|
|
+ errno=EINVAL;
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
snprintf(path, sizeof path, "%s/member", selinux_mnt);
|
|
|
|
fd = open(path, O_RDWR);
|
|
|
|
if (fd < 0)
|
2014-05-06 18:28:19 +00:00
|
|
|
diff -up libselinux-2.3/src/compute_relabel.c.rhat libselinux-2.3/src/compute_relabel.c
|
|
|
|
--- libselinux-2.3/src/compute_relabel.c.rhat 2014-05-06 14:21:26.000000000 -0400
|
|
|
|
+++ libselinux-2.3/src/compute_relabel.c 2014-05-06 14:23:28.325639317 -0400
|
|
|
|
@@ -25,6 +25,11 @@ int security_compute_relabel_raw(const c
|
2014-01-24 16:10:54 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ if ((! scon) || (! tcon)) {
|
|
|
|
+ errno=EINVAL;
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
snprintf(path, sizeof path, "%s/relabel", selinux_mnt);
|
|
|
|
fd = open(path, O_RDWR);
|
|
|
|
if (fd < 0)
|
2014-05-06 18:28:19 +00:00
|
|
|
diff -up libselinux-2.3/src/compute_user.c.rhat libselinux-2.3/src/compute_user.c
|
|
|
|
--- libselinux-2.3/src/compute_user.c.rhat 2014-05-06 14:21:26.000000000 -0400
|
|
|
|
+++ libselinux-2.3/src/compute_user.c 2014-05-06 14:23:28.325639317 -0400
|
|
|
|
@@ -24,6 +24,11 @@ int security_compute_user_raw(const char
|
2014-01-24 16:10:54 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ if (! scon) {
|
|
|
|
+ errno=EINVAL;
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
snprintf(path, sizeof path, "%s/user", selinux_mnt);
|
|
|
|
fd = open(path, O_RDWR);
|
|
|
|
if (fd < 0)
|
2014-05-06 18:28:19 +00:00
|
|
|
diff -up libselinux-2.3/src/fsetfilecon.c.rhat libselinux-2.3/src/fsetfilecon.c
|
|
|
|
--- libselinux-2.3/src/fsetfilecon.c.rhat 2014-05-06 14:23:28.326639318 -0400
|
|
|
|
+++ libselinux-2.3/src/fsetfilecon.c 2014-05-06 14:26:40.740860532 -0400
|
2014-01-06 15:15:40 +00:00
|
|
|
@@ -9,8 +9,12 @@
|
|
|
|
|
2014-05-06 18:28:19 +00:00
|
|
|
int fsetfilecon_raw(int fd, const char * context)
|
2014-01-06 15:15:40 +00:00
|
|
|
{
|
|
|
|
- int rc = fsetxattr(fd, XATTR_NAME_SELINUX, context, strlen(context) + 1,
|
|
|
|
- 0);
|
|
|
|
+ int rc;
|
|
|
|
+ if (! context) {
|
|
|
|
+ errno=EINVAL;
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+ rc = fsetxattr(fd, XATTR_NAME_SELINUX, context, strlen(context) + 1, 0);
|
|
|
|
if (rc < 0 && errno == ENOTSUP) {
|
2014-05-06 18:28:19 +00:00
|
|
|
char * ccontext = NULL;
|
2014-01-06 15:15:40 +00:00
|
|
|
int err = errno;
|
2014-05-06 18:28:19 +00:00
|
|
|
diff -up libselinux-2.3/src/load_policy.c.rhat libselinux-2.3/src/load_policy.c
|
|
|
|
--- libselinux-2.3/src/load_policy.c.rhat 2014-05-06 14:21:26.000000000 -0400
|
|
|
|
+++ libselinux-2.3/src/load_policy.c 2014-05-06 14:23:28.327639319 -0400
|
2013-11-25 20:24:16 +00:00
|
|
|
@@ -16,6 +16,82 @@
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#include "policy.h"
|
|
|
|
#include <limits.h>
|
|
|
|
+#include <lzma.h>
|
|
|
|
+
|
|
|
|
+static char *lzmaread(int fd, size_t *rsize) {
|
|
|
|
+ int capacity = 64*1024;
|
|
|
|
+ char *buf = NULL;
|
|
|
|
+ int tmpsize = 8 * 1024;
|
|
|
|
+ unsigned char tmp[tmpsize];
|
|
|
|
+ unsigned char tmp_out[tmpsize];
|
|
|
|
+ size_t size = 0;
|
|
|
|
+ lzma_stream strm = LZMA_STREAM_INIT;
|
|
|
|
+ lzma_action action = LZMA_RUN;
|
|
|
|
+ lzma_ret ret;
|
|
|
|
+
|
|
|
|
+ FILE *stream = fdopen (fd, "r");
|
|
|
|
+ if (!stream) {
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
|
|
+ ret = lzma_stream_decoder(&strm, UINT64_MAX,
|
|
|
|
+ LZMA_CONCATENATED);
|
|
|
|
+
|
|
|
|
+ strm.avail_in = 0;
|
|
|
|
+ strm.next_out = tmp_out;
|
|
|
|
+ strm.avail_out = tmpsize;
|
|
|
|
+
|
|
|
|
+ buf = (char *) malloc (capacity);
|
|
|
|
+ if (!buf)
|
|
|
|
+ goto err;
|
|
|
|
+
|
|
|
|
+ while (1) {
|
|
|
|
+ if (strm.avail_in == 0) {
|
|
|
|
+ strm.next_in = tmp;
|
|
|
|
+ strm.avail_in = fread(tmp, 1, tmpsize, stream);
|
|
|
|
+
|
|
|
|
+ if (ferror(stream)) {
|
|
|
|
+ // POSIX says that fread() sets errno if
|
|
|
|
+ // an error occurred. ferror() doesn't
|
|
|
|
+ // touch errno.
|
|
|
|
+ goto err;
|
|
|
|
+ }
|
|
|
|
+ if (feof(stream)) action = LZMA_FINISH;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ret = lzma_code(&strm, action);
|
|
|
|
+
|
|
|
|
+ // Write and check write error before checking decoder error.
|
|
|
|
+ // This way as much data as possible gets written to output
|
|
|
|
+ // even if decoder detected an error.
|
|
|
|
+ if (strm.avail_out == 0 || ret != LZMA_OK) {
|
|
|
|
+ const size_t num = tmpsize - strm.avail_out;
|
|
|
|
+ if (num > capacity) {
|
|
|
|
+ buf = (char*) realloc (buf, size*2);
|
|
|
|
+ capacity = size;
|
|
|
|
+ }
|
|
|
|
+ memcpy (buf+size, tmp_out, num);
|
|
|
|
+ capacity -= num;
|
|
|
|
+ size += num;
|
|
|
|
+ strm.next_out = tmp_out;
|
|
|
|
+ strm.avail_out = tmpsize;
|
|
|
|
+ }
|
|
|
|
+ if (ret != LZMA_OK) {
|
|
|
|
+ if (ret == LZMA_STREAM_END) {
|
|
|
|
+ break;
|
|
|
|
+ } else {
|
|
|
|
+ goto err;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ *rsize = size;
|
|
|
|
+
|
|
|
|
+ goto exit;
|
|
|
|
+err:
|
|
|
|
+ free(buf); buf = NULL;
|
|
|
|
+exit:
|
|
|
|
+ lzma_end(&strm);
|
|
|
|
+ return buf;
|
|
|
|
+}
|
|
|
|
|
|
|
|
int security_load_policy(void *data, size_t len)
|
|
|
|
{
|
2014-05-06 18:28:19 +00:00
|
|
|
@@ -55,7 +131,7 @@ int selinux_mkload_policy(int preservebo
|
2013-11-25 20:24:16 +00:00
|
|
|
struct stat sb;
|
|
|
|
struct utsname uts;
|
|
|
|
size_t size;
|
|
|
|
- void *map, *data;
|
|
|
|
+ void *map = NULL, *data=NULL;
|
|
|
|
int fd, rc = -1, prot;
|
|
|
|
sepol_policydb_t *policydb;
|
|
|
|
sepol_policy_file_t *pf;
|
|
|
|
@@ -181,24 +257,28 @@ checkbool:
|
|
|
|
goto dlclose;
|
|
|
|
}
|
|
|
|
|
|
|
|
- if (fstat(fd, &sb) < 0) {
|
|
|
|
- fprintf(stderr,
|
|
|
|
- "SELinux: Could not stat policy file %s: %s\n",
|
|
|
|
- path, strerror(errno));
|
|
|
|
- goto close;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- prot = PROT_READ;
|
|
|
|
- if (setlocaldefs || preservebools)
|
|
|
|
- prot |= PROT_WRITE;
|
|
|
|
+ data = lzmaread(fd,&size);
|
|
|
|
|
|
|
|
- size = sb.st_size;
|
|
|
|
- data = map = mmap(NULL, size, prot, MAP_PRIVATE, fd, 0);
|
|
|
|
- if (map == MAP_FAILED) {
|
|
|
|
- fprintf(stderr,
|
|
|
|
- "SELinux: Could not map policy file %s: %s\n",
|
|
|
|
+ if (!data) {
|
|
|
|
+ if (fstat(fd, &sb) < 0) {
|
|
|
|
+ fprintf(stderr,
|
|
|
|
+ "SELinux: Could not stat policy file %s: %s\n",
|
|
|
|
path, strerror(errno));
|
|
|
|
- goto close;
|
|
|
|
+ goto close;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ prot = PROT_READ;
|
|
|
|
+ if (setlocaldefs || preservebools)
|
|
|
|
+ prot |= PROT_WRITE;
|
|
|
|
+
|
|
|
|
+ size = sb.st_size;
|
|
|
|
+ data = map = mmap(NULL, size, prot, MAP_PRIVATE, fd, 0);
|
|
|
|
+ if (map == MAP_FAILED) {
|
|
|
|
+ fprintf(stderr,
|
|
|
|
+ "SELinux: Could not map policy file %s: %s\n",
|
|
|
|
+ path, strerror(errno));
|
|
|
|
+ goto close;
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vers > kernvers && usesepol) {
|
|
|
|
@@ -210,6 +290,8 @@ checkbool:
|
|
|
|
goto unmap;
|
|
|
|
}
|
|
|
|
policy_file_set_mem(pf, data, size);
|
|
|
|
+ if (!map)
|
|
|
|
+ free(data);
|
|
|
|
if (policydb_read(policydb, pf)) {
|
|
|
|
policy_file_free(pf);
|
|
|
|
policydb_free(policydb);
|
|
|
|
@@ -223,7 +305,8 @@ checkbool:
|
|
|
|
path);
|
|
|
|
policy_file_free(pf);
|
|
|
|
policydb_free(policydb);
|
|
|
|
- munmap(map, sb.st_size);
|
|
|
|
+ if (map)
|
|
|
|
+ munmap(map, sb.st_size);
|
|
|
|
close(fd);
|
|
|
|
vers--;
|
|
|
|
goto search;
|
|
|
|
@@ -275,7 +358,7 @@ checkbool:
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
+
|
|
|
|
rc = security_load_policy(data, size);
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
@@ -286,7 +369,8 @@ checkbool:
|
|
|
|
unmap:
|
|
|
|
if (data != map)
|
|
|
|
free(data);
|
|
|
|
- munmap(map, sb.st_size);
|
|
|
|
+ if (map)
|
|
|
|
+ munmap(map, sb.st_size);
|
|
|
|
close:
|
|
|
|
close(fd);
|
|
|
|
dlclose:
|
2014-05-06 18:28:19 +00:00
|
|
|
diff -up libselinux-2.3/src/lsetfilecon.c.rhat libselinux-2.3/src/lsetfilecon.c
|
|
|
|
--- libselinux-2.3/src/lsetfilecon.c.rhat 2014-05-06 14:23:28.327639319 -0400
|
|
|
|
+++ libselinux-2.3/src/lsetfilecon.c 2014-05-06 14:26:36.094854847 -0400
|
|
|
|
@@ -9,8 +9,12 @@
|
2013-12-23 14:53:25 +00:00
|
|
|
|
2014-05-06 18:28:19 +00:00
|
|
|
int lsetfilecon_raw(const char *path, const char * context)
|
2013-12-23 14:53:25 +00:00
|
|
|
{
|
|
|
|
- int rc = lsetxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1,
|
2014-01-06 15:15:40 +00:00
|
|
|
- 0);
|
2013-12-23 14:53:25 +00:00
|
|
|
+ int rc;
|
|
|
|
+ if (! context) {
|
|
|
|
+ errno=EINVAL;
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
2014-01-06 15:15:40 +00:00
|
|
|
+ rc = lsetxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1, 0);
|
2013-12-23 14:53:25 +00:00
|
|
|
if (rc < 0 && errno == ENOTSUP) {
|
2014-05-06 18:28:19 +00:00
|
|
|
char * ccontext = NULL;
|
2014-01-06 15:15:40 +00:00
|
|
|
int err = errno;
|
2014-05-06 18:28:19 +00:00
|
|
|
diff -up libselinux-2.3/src/Makefile.rhat libselinux-2.3/src/Makefile
|
|
|
|
--- libselinux-2.3/src/Makefile.rhat 2014-05-06 14:21:26.000000000 -0400
|
|
|
|
+++ libselinux-2.3/src/Makefile 2014-05-06 14:23:28.323639315 -0400
|
|
|
|
@@ -111,7 +111,7 @@ $(LIBA): $(OBJS)
|
|
|
|
$(RANLIB) $@
|
|
|
|
|
|
|
|
$(LIBSO): $(LOBJS)
|
|
|
|
- $(CC) $(CFLAGS) -shared -o $@ $^ -lpcre -ldl $(LDFLAGS) -L$(LIBDIR) -Wl,-soname,$(LIBSO),-z,defs,-z,relro
|
|
|
|
+ $(CC) $(CFLAGS) -shared -o $@ $^ -lpcre -llzma -ldl $(LDFLAGS) -L$(LIBDIR) -Wl,-soname,$(LIBSO),-z,defs,-z,relro
|
|
|
|
ln -sf $@ $(TARGET)
|
|
|
|
|
|
|
|
$(LIBPC): $(LIBPC).in ../VERSION
|
|
|
|
diff -up libselinux-2.3/src/matchpathcon.c.rhat libselinux-2.3/src/matchpathcon.c
|
|
|
|
--- libselinux-2.3/src/matchpathcon.c.rhat 2014-05-06 14:21:26.000000000 -0400
|
|
|
|
+++ libselinux-2.3/src/matchpathcon.c 2014-05-06 14:23:28.328639320 -0400
|
2011-08-30 15:08:49 +00:00
|
|
|
@@ -2,6 +2,7 @@
|
2009-03-27 18:25:16 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
+#include <syslog.h>
|
|
|
|
#include "selinux_internal.h"
|
|
|
|
#include "label_internal.h"
|
|
|
|
#include "callbacks.h"
|
2011-08-30 15:08:49 +00:00
|
|
|
@@ -62,7 +63,7 @@ static void
|
2009-03-27 18:25:16 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
- vfprintf(stderr, fmt, ap);
|
|
|
|
+ vsyslog(LOG_ERR, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
2009-01-27 20:00:47 +00:00
|
|
|
|
2014-05-06 18:28:19 +00:00
|
|
|
diff -up libselinux-2.3/src/setfilecon.c.rhat libselinux-2.3/src/setfilecon.c
|
|
|
|
--- libselinux-2.3/src/setfilecon.c.rhat 2014-05-06 14:23:28.328639320 -0400
|
|
|
|
+++ libselinux-2.3/src/setfilecon.c 2014-05-06 14:26:47.670869020 -0400
|
2014-01-06 15:15:40 +00:00
|
|
|
@@ -9,8 +9,12 @@
|
|
|
|
|
2014-05-06 18:28:19 +00:00
|
|
|
int setfilecon_raw(const char *path, const char * context)
|
2014-01-06 15:15:40 +00:00
|
|
|
{
|
|
|
|
- int rc = setxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1,
|
|
|
|
- 0);
|
|
|
|
+ int rc;
|
|
|
|
+ if (! context) {
|
|
|
|
+ errno=EINVAL;
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+ rc = setxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1, 0);
|
|
|
|
if (rc < 0 && errno == ENOTSUP) {
|
2014-05-06 18:28:19 +00:00
|
|
|
char * ccontext = NULL;
|
2014-01-06 15:15:40 +00:00
|
|
|
int err = errno;
|