8000 Policies mntns issue and Segfault fix by rafaeldtinoco · Pull Request #2974 · aquasecurity/tracee · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Policies mntns issue and Segfault fix #2974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions pkg/cmd/flags/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ func PrepareFilterMapFromPolicies(policies []PolicyFile) (FilterMap, error) {
return nil, err
}

// currently an event can only be used once in the policy,
// this might change in the future to allow multiple times the same event with different filters
// Currently, an event can only be used once in the policy. Support for using the same
// event, multiple times, with different filters, shall be implemented in the future.
if _, ok := events[r.Event]; ok {
return nil, errfmt.Errorf("policy %s, event %s is duplicated", p.Name, r.Event)
}
Expand All @@ -132,7 +132,7 @@ func PrepareFilterMapFromPolicies(policies []PolicyFile) (FilterMap, error) {
operatorIdx := strings.IndexAny(f, "=!<>")

if operatorIdx == -1 {
return nil, errfmt.Errorf("invalid filter: %s", f)
return nil, errfmt.Errorf("invalid filter operator: %s", f)
}

filterName := f[:operatorIdx]
Expand Down Expand Up @@ -227,7 +227,7 @@ func validateScope(policyName, s string) error {
scopes := []string{
"uid",
"pid",
"mntNS",
"mntns",
"pidns",
"uts",
"comm",
Expand Down
38 changes: 23 additions & 15 deletions pkg/cmd/flags/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ func newFilterFlagBasedOn(f *filterFlag, policyName string) *filterFlag {

func TestPolicyScopes(t *testing.T) {
tests := []struct {
testName string
policy PolicyFile
expected FilterMap
testName string
policy PolicyFile
expected FilterMap
skipPolicyCreation bool
}{
{
testName: "global scope - single event",
Expand Down Expand Up @@ -122,11 +123,11 @@ func TestPolicyScopes(t *testing.T) {
},
},
{
testName: "mntNS scope",
testName: "mntns scope",
policy: PolicyFile{
Name: "mntNS_scope",
Description: "mntNS scope",
Scope: []string{"mntNS=4026531840"},
Name: "mntns",
Description: "mntns scope",
Scope: []string{"mntns=4026531840"},
DefaultAction: "log",
Rules: []Rule{
{Event: "write"},
Expand All @@ -135,13 +136,13 @@ func TestPolicyScopes(t *testing.T) {
expected: FilterMap{
0: {
{
full: "mntNS=4026531840",
filterName: "mntNS",
full: "mntns=4026531840",
filterName: "mntns",
operatorAndValues: "=4026531840",
policyIdx: 0,
policyName: "mntNS_scope",
policyName: "mntns",
},
newFilterFlagBasedOn(writeFlag, "mntNS_scope"),
newFilterFlagBasedOn(writeFlag, "mntns"),
},
},
},
Expand Down Expand Up @@ -360,6 +361,7 @@ func TestPolicyScopes(t *testing.T) {
newFilterFlagBasedOn(writeFlag, "binary_scope"),
},
},
skipPolicyCreation: true, // needs root privileges
},
{
testName: "bin=4026532448:/usr/bin/ls",
Expand Down Expand Up @@ -465,6 +467,11 @@ func TestPolicyScopes(t *testing.T) {
assert.Equal(t, v, filterMap[k])
}

if !test.skipPolicyCreation {
p, err := CreatePolicies(filterMap)
assert.NotNil(t, p)
assert.NoError(t, err)
}
})
}
}
Expand Down Expand Up @@ -1393,9 +1400,10 @@ func TestPolicyEventFilter(t *testing.T) {

func TestPrepareFilterScopesForPolicyValidations(t *testing.T) {
tests := []struct {
testName string
policies []PolicyFile
expectedError error
testName string
policies []PolicyFile
expectedError error
expectedPolicyError bool
}{
{
testName: "empty name",
Expand Down Expand Up @@ -1546,7 +1554,7 @@ func TestPrepareFilterScopesForPolicyValidations(t *testing.T) {
},
},
},
expectedError: errors.New("flags.PrepareFilterMapFromPolicies: invalid filter: random"),
expectedError: errors.New("flags.PrepareFilterMapFromPolicies: invalid filter operator: random"),
},
{
testName: "invalid filter",
Expand Down
4 changes: 4 additions & 0 deletions pkg/ebpf/events_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,10 @@ func (t *Tracee) deriveEvents(ctx context.Context, in <-chan *trace.Event) (
for {
select {
case event := <-in:
if event == nil {
continue // might happen during initialization (ctrl+c seg faults)
}

// Get a copy of our event before sending it down the pipeline.
// This is needed because later modification of the event (in
// particular of the matched policies) can affect the derivation
Expand Down
4 changes: 4 additions & 0 deletions pkg/ebpf/signature_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func (t *Tracee) engineEvents(ctx context.Context, in <-chan *trace.Event) (<-ch
for {
select {
case event := <-in:
if event == nil {
continue // might happen during initialization (ctrl+c seg faults)
}

id := events.ID(event.EventID)

// if the event is marked as submit, we pass it to the engine
Expand Down
0