Skip to content

Commit

Permalink
tetragon: Allow retry logic for clone events
Browse files Browse the repository at this point in the history
The AddCloneEvent fails to add process the the cache if
the parent does not exist - there's no record of it.

This can happen for example in TestFork test where fork events
can be delivered out of order and tetragon sees the child fork
event before the parent's one.

Adding retry logic for clone events, which will retry the fork
event processing and adding the child process entry after the
timeout. During the timeout the parent is updated and following
retry logic will add the child's entry properly.

Signed-off-by: Jiri Olsa <[email protected]>
  • Loading branch information
olsajiri authored and jrfastab committed Aug 26, 2022
1 parent ec51b2e commit a34d1ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 8 additions & 3 deletions pkg/grpc/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,22 @@ func (msg *MsgCloneEventUnix) Notify() bool {
}

func (msg *MsgCloneEventUnix) RetryInternal(ev notify.Event, timestamp uint64) (*process.ProcessInternal, error) {
return nil, fmt.Errorf("Unreachable state: MsgCloneEventUnix with missing internal")
return nil, process.AddCloneEvent(&msg.MsgCloneEvent)
}

func (msg *MsgCloneEventUnix) Retry(internal *process.ProcessInternal, ev notify.Event) error {
return eventcache.HandleGenericEvent(internal, ev)
return nil
}

func (msg *MsgCloneEventUnix) HandleMessage() *tetragon.GetEventsResponse {
switch msg.Common.Op {
case ops.MSG_OP_CLONE:
process.AddCloneEvent(&msg.MsgCloneEvent)
if err := process.AddCloneEvent(&msg.MsgCloneEvent); err != nil {
ec := eventcache.Get()
if ec != nil {
ec.Add(nil, nil, msg.MsgCloneEvent.Ktime, msg)
}
}
default:
logger.GetLogger().WithField("message", msg).Warn("HandleCloneMessage: Unhandled event")
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,12 @@ func AddExecEvent(event *tetragonAPI.MsgExecveEventUnix) *ProcessInternal {
}

// AddCloneEvent adds a new process into the cache from a CloneEvent
func AddCloneEvent(event *tetragonAPI.MsgCloneEvent) {
func AddCloneEvent(event *tetragonAPI.MsgCloneEvent) error {
parentExecId := GetProcessID(event.Parent.Pid, event.Parent.Ktime)
parent, err := Get(parentExecId)
if err != nil {
logger.GetLogger().WithField("parent-exec-id", parentExecId).Debug("AddCloneEvent: process not found in cache")
return
return err
}
pi := parent.GetProcessInternalCopy()
if pi.process != nil {
Expand All @@ -288,6 +288,7 @@ func AddCloneEvent(event *tetragonAPI.MsgCloneEvent) {
}
}
procCache.Add(pi)
return nil
}

func Get(execId string) (*ProcessInternal, error) {
Expand Down

0 comments on commit a34d1ff

Please sign in to comment.