diff --git a/pkg/security/probe/discarders.go b/pkg/security/probe/discarders.go index 23c6c330c6267..e7ff18967cfb0 100644 --- a/pkg/security/probe/discarders.go +++ b/pkg/security/probe/discarders.go @@ -81,7 +81,7 @@ var ( ) var ( - dentryInvalidDiscarder = []interface{}{""} + dentryInvalidDiscarder = []string{""} eventZeroDiscarder = &model.Event{ FieldHandlers: &model.DefaultFieldHandlers{}, ContainerContext: &model.ContainerContext{}, @@ -89,7 +89,7 @@ var ( ) // InvalidDiscarders exposes list of values that are not discarders -var InvalidDiscarders = map[eval.Field][]interface{}{ +var InvalidDiscarders = map[eval.Field][]string{ "open.file.path": dentryInvalidDiscarder, "unlink.file.path": dentryInvalidDiscarder, "chmod.file.path": dentryInvalidDiscarder, @@ -518,27 +518,23 @@ func filenameDiscarderWrapper(eventType model.EventType, getter inodeEventGetter } // isInvalidDiscarder returns whether the given value is a valid discarder for the given field -func isInvalidDiscarder(field eval.Field, value interface{}) bool { - values, exists := invalidDiscarders[field] - if !exists { - return false - } - - return values[value] +func isInvalidDiscarder(field eval.Field, value string) bool { + return invalidDiscarders[invalidDiscarderEntry{ + field: field, + value: value, + }] } // rearrange invalid discarders for fast lookup -func createInvalidDiscardersCache() map[eval.Field]map[interface{}]bool { - invalidDiscarders := make(map[eval.Field]map[interface{}]bool) +func createInvalidDiscardersCache() map[invalidDiscarderEntry]bool { + invalidDiscarders := make(map[invalidDiscarderEntry]bool) for field, values := range InvalidDiscarders { - ivalues := invalidDiscarders[field] - if ivalues == nil { - ivalues = make(map[interface{}]bool) - invalidDiscarders[field] = ivalues - } for _, value := range values { - ivalues[value] = true + invalidDiscarders[invalidDiscarderEntry{ + field: field, + value: value, + }] = true } } @@ -700,7 +696,12 @@ func dumpDiscarders(resolver *dentry.Resolver, pidMap, inodeMap, statsFB, statsB return dump, nil } -var invalidDiscarders map[eval.Field]map[interface{}]bool +type invalidDiscarderEntry struct { + field eval.Field + value string +} + +var invalidDiscarders map[invalidDiscarderEntry]bool func init() { invalidDiscarders = createInvalidDiscardersCache()