Skip to content

Commit

Permalink
disk_mount: don't whitelist runc process (#2659)
Browse files Browse the repository at this point in the history
instead use the ContainerStarted context flag
  • Loading branch information
roikol authored Jan 31, 2023
1 parent f4048f9 commit 1742355
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
14 changes: 5 additions & 9 deletions signatures/golang/disk_mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,16 @@ func (sig *DiskMount) OnEvent(event protocol.Event) error {

case "security_sb_mount":

if !eventObj.ContextFlags.ContainerStarted {
return nil
}

deviceName, err := helpers.GetTraceeStringArgumentByName(eventObj, "dev_name")
if err != nil {
return nil
}

if !isRunc(eventObj) && strings.HasPrefix(deviceName, sig.devDir) {
if strings.HasPrefix(deviceName, sig.devDir) {
metadata, err := sig.GetMetadata()
if err != nil {
return err
Expand All @@ -82,11 +86,3 @@ func (sig *DiskMount) OnSignal(s detect.Signal) error {
return nil
}
func (sig *DiskMount) Close() {}

func isRunc(event trace.Event) bool {
if event.ThreadID == 1 && strings.HasPrefix(event.ProcessName, "runc:") {
return true
}

return false
}
30 changes: 17 additions & 13 deletions signatures/golang/disk_mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ func TestDiskMount(t *testing.T) {
Name: "should trigger detection",
Events: []trace.Event{
{
ProcessName: "mal",
ThreadID: 8,
EventName: "security_sb_mount",
ProcessName: "mal",
ThreadID: 8,
ContextFlags: trace.ContextFlags{ContainerStarted: true},
EventName: "security_sb_mount",
Args: []trace.Argument{
{
ArgMeta: trace.ArgMeta{
Expand All @@ -37,9 +38,10 @@ func TestDiskMount(t *testing.T) {
"TRC-1014": {
Data: nil,
Event: trace.Event{
ProcessName: "mal",
ThreadID: 8,
EventName: "security_sb_mount",
ProcessName: "mal",
ThreadID: 8,
ContextFlags: trace.ContextFlags{ContainerStarted: true},
EventName: "security_sb_mount",
Args: []trace.Argument{
{
ArgMeta: trace.ArgMeta{
Expand Down Expand Up @@ -68,12 +70,13 @@ func TestDiskMount(t *testing.T) {
},
},
{
Name: "should not trigger detection - runc",
Name: "should not trigger detection - container not started",
Events: []trace.Event{
{
ProcessName: "runc:[init]",
ThreadID: 1,
EventName: "security_sb_mount",
ProcessName: "runc:[init]",
ThreadID: 1,
ContextFlags: trace.ContextFlags{ContainerStarted: false},
EventName: "security_sb_mount",
Args: []trace.Argument{
{
ArgMeta: trace.ArgMeta{
Expand All @@ -90,9 +93,10 @@ func TestDiskMount(t *testing.T) {
Name: "should not trigger detection - wrong path",
Events: []trace.Event{
{
ProcessName: "runc:[init]",
ThreadID: 8,
EventName: "security_sb_mount",
ProcessName: "runc:[init]",
ThreadID: 8,
ContextFlags: trace.ContextFlags{ContainerStarted: true},
EventName: "security_sb_mount",
Args: []trace.Argument{
{
ArgMeta: trace.ArgMeta{
Expand Down

0 comments on commit 1742355

Please sign in to comment.