-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
183 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2016-present Datadog, Inc. | ||
|
||
// Package probe holds probe related files | ||
package probe | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"syscall" | ||
|
||
psutil "github.com/shirou/gopsutil/v3/process" | ||
|
||
"github.com/DataDog/datadog-agent/pkg/security/secl/model" | ||
) | ||
|
||
const ( | ||
userSpaceKillWithinMillis = 2000 | ||
) | ||
|
||
// KillFromUserspace tries to kill from userspace | ||
func (p *ProcessKiller) KillFromUserspace(pid uint32, sig uint32, ev *model.Event) error { | ||
proc, err := psutil.NewProcess(int32(pid)) | ||
if err != nil { | ||
return errors.New("process not found in procfs") | ||
} | ||
|
||
name, err := proc.Name() | ||
if err != nil { | ||
return errors.New("process not found in procfs") | ||
} | ||
|
||
createdAt, err := proc.CreateTime() | ||
if err != nil { | ||
return errors.New("process not found in procfs") | ||
} | ||
evCreatedAt := ev.ProcessContext.ExecTime.UnixMilli() | ||
|
||
within := uint64(evCreatedAt) >= uint64(createdAt-userSpaceKillWithinMillis) && uint64(evCreatedAt) <= uint64(createdAt+userSpaceKillWithinMillis) | ||
|
||
if !within || ev.ProcessContext.Comm != name { | ||
return fmt.Errorf("not sharing the same namespace: %s/%s", ev.ProcessContext.Comm, name) | ||
} | ||
|
||
return syscall.Kill(int(pid), syscall.Signal(sig)) | ||
} | ||
|
||
func (p *ProcessKiller) getPids(scope string, ev *model.Event, entry *model.ProcessCacheEntry) ([]uint32, error) { | ||
var pids []uint32 | ||
|
||
if entry.ContainerID != "" && scope == "container" { | ||
pids = entry.GetContainerPIDs() | ||
} else { | ||
pids = []uint32{ev.ProcessContext.Pid} | ||
} | ||
return pids, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2016-present Datadog, Inc. | ||
|
||
// Package probe holds probe related files | ||
package probe | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/DataDog/datadog-agent/pkg/security/secl/model" | ||
"github.com/DataDog/datadog-agent/pkg/util/winutil" | ||
) | ||
|
||
// KillFromUserspace tries to kill from userspace | ||
func (p *ProcessKiller) KillFromUserspace(pid uint32, sig uint32, _ *model.Event) error { | ||
if sig != model.SIGKILL { | ||
return nil | ||
} | ||
return winutil.KillProcess(int(pid), 0) | ||
} | ||
|
||
func (p *ProcessKiller) getPids(scope string, ev *model.Event, _ *model.ProcessCacheEntry) ([]uint32, error) { | ||
if scope == "container" { | ||
return nil, errors.New("container scope not supported") | ||
} | ||
return []uint32{ev.ProcessContext.Pid}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2016-present Datadog, Inc. | ||
|
||
// Package model holds model related files | ||
package model | ||
|
||
const ( | ||
// SIGKILL id for the kill action | ||
SIGKILL = iota + 1 | ||
) | ||
|
||
var ( | ||
errorConstants = map[string]int{} | ||
openFlagsConstants = map[string]int{} | ||
fileModeConstants = map[string]int{} | ||
inodeModeConstants = map[string]int{} | ||
// KernelCapabilityConstants list of kernel capabilities | ||
KernelCapabilityConstants = map[string]uint64{} | ||
unlinkFlagsConstants = map[string]int{} | ||
ptraceConstants = map[string]uint32{} | ||
ptraceArchConstants = map[string]uint32{} | ||
protConstants = map[string]int{} | ||
mmapFlagConstants = map[string]uint64{} | ||
mmapFlagArchConstants = map[string]uint64{} | ||
addressFamilyConstants = map[string]uint16{} | ||
|
||
// SignalConstants list of signals | ||
SignalConstants = map[string]int{ | ||
"SIGKILL": SIGKILL, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2016-present Datadog, Inc. | ||
|
||
//go:build !linux | ||
|
||
// Package utils holds utils related files | ||
package utils | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
// Getpid returns the current process ID in the host namespace | ||
func Getpid() uint32 { | ||
return uint32(os.Getpid()) | ||
} |