Skip to content

Commit

Permalink
[CWS] ebpfless handle retval
Browse files Browse the repository at this point in the history
  • Loading branch information
safchain committed Dec 18, 2023
1 parent a87ec42 commit 94edb50
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/security/probe/probe_epbfless.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func (p *EBPFLessProbe) handleClientMsg(msg *clientMsg) {
p.Resolvers.ProcessResolver.AddForkEntry(process.CacheResolverKey{Pid: syscallMsg.PID, NSID: syscallMsg.NSID}, syscallMsg.Fork.PPID)
case ebpfless.SyscallTypeOpen:
event.Type = uint32(model.FileOpenEventType)
event.Open.Retval = syscallMsg.Retval
event.Open.File.PathnameStr = syscallMsg.Open.Filename
event.Open.File.BasenameStr = filepath.Base(syscallMsg.Open.Filename)
event.Open.Flags = syscallMsg.Open.Flags
Expand Down
1 change: 1 addition & 0 deletions pkg/security/proto/ebpfless/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ type SyscallMsg struct {
NSID uint64
Type SyscallType
PID uint32
Retval int64
ContainerContext *ContainerContext
Exec *ExecSyscallMsg
Open *OpenSyscallMsg
Expand Down
7 changes: 6 additions & 1 deletion pkg/security/ptracer/cws.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,10 @@ func checkEntryPoint(path string) (string, error) {
return name, nil
}

func isAcceptedRetval(retval int64) bool {
return retval < 0 && retval != -int64(syscall.EACCES) && retval != -int64(syscall.EPERM)
}

// StartCWSPtracer start the ptracer
func StartCWSPtracer(args []string, probeAddr string, creds Creds, verbose bool) error {
entry, err := checkEntryPoint(args[0])
Expand Down Expand Up @@ -632,11 +636,12 @@ func StartCWSPtracer(args []string, probeAddr string, creds Creds, verbose bool)
case ExecveNr, ExecveatNr:
send(process.Nr[nr])
case OpenNr, OpenatNr:
if ret := tracer.ReadRet(regs); ret >= 0 {
if ret := tracer.ReadRet(regs); !isAcceptedRetval(ret) {
msg, exists := process.Nr[nr]
if !exists {
return
}
msg.Retval = ret

send(msg)

Expand Down

0 comments on commit 94edb50

Please sign in to comment.