Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions go-selinux/selinux_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ const (

type selinuxState struct {
mcsList map[string]bool
cond *sync.Cond
selinuxfs string
maxMCSCount int
selinuxfsOnce sync.Once
enabledSet bool
enabled bool
mu sync.Mutex
sync.Mutex
enabledSet bool
enabled bool
}

type level struct {
cats *big.Int
sens int
Expand Down Expand Up @@ -936,6 +938,18 @@ func mcsAdd(mcs string) error {
if mcs == "" {
return nil
}
state.mu.Lock()
if state.maxMCSCount == 0 {
state.maxMCSCount = int(CategoryRange * (CategoryRange - 1) / 2)
}
if state.cond == nil {
state.cond = sync.NewCond(&state.mu)
}
if getMcsListSize() >= state.maxMCSCount {
state.cond.Wait()
}
state.mu.Unlock()

state.Lock()
defer state.Unlock()
if state.mcsList[mcs] {
Expand All @@ -945,13 +959,22 @@ func mcsAdd(mcs string) error {
return nil
}

func getMcsListSize() int {
state.Lock()
defer state.Unlock()
return len(state.mcsList)
}

func mcsDelete(mcs string) {
if mcs == "" {
return
}
state.Lock()
defer state.Unlock()
state.mcsList[mcs] = false
state.mu.Lock()
state.cond.Signal()
state.mu.Unlock()
}

func intToMcs(id int, catRange uint32) string {
Expand Down