Skip to content
New issue

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

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

Already on GitHub? # to your account

synchronize bpf watch map reads #3506

Merged
merged 2 commits into from
Apr 1, 2020
Merged
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
15 changes: 11 additions & 4 deletions lib/bpf/bpf.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (s *Service) emitCommandEvent(eventBytes []byte) {
}

// If the event comes from a unmonitored process/cgroup, don't process it.
ctx, ok := s.watch[event.CgroupID]
ctx, ok := s.getWatch(event.CgroupID)
if !ok {
return
}
Expand Down Expand Up @@ -320,7 +320,7 @@ func (s *Service) emitDiskEvent(eventBytes []byte) {
}

// If the event comes from a unmonitored process/cgroup, don't process it.
ctx, ok := s.watch[event.CgroupID]
ctx, ok := s.getWatch(event.CgroupID)
if !ok {
return
}
Expand Down Expand Up @@ -360,7 +360,7 @@ func (s *Service) emit4NetworkEvent(eventBytes []byte) {
}

// If the event comes from a unmonitored process/cgroup, don't process it.
ctx, ok := s.watch[event.CgroupID]
ctx, ok := s.getWatch(event.CgroupID)
if !ok {
return
}
Expand Down Expand Up @@ -411,7 +411,7 @@ func (s *Service) emit6NetworkEvent(eventBytes []byte) {
}

// If the event comes from a unmonitored process/cgroup, don't process it.
ctx, ok := s.watch[event.CgroupID]
ctx, ok := s.getWatch(event.CgroupID)
if !ok {
return
}
Expand Down Expand Up @@ -457,6 +457,13 @@ func (s *Service) emit6NetworkEvent(eventBytes []byte) {
ctx.AuditLog.EmitAuditEvent(events.SessionNetwork, eventFields)
}

func (s *Service) getWatch(cgoupID uint64) (ctx *SessionContext, ok bool) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cgroupID

s.watchMu.Lock()
defer s.watchMu.Unlock()
ctx, ok = s.watch[cgoupID]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cgroupID

return
}

func (s *Service) addWatch(cgroupID uint64, ctx *SessionContext) {
s.watchMu.Lock()
defer s.watchMu.Unlock()
Expand Down