Skip to content

Commit 56f9037

Browse files
committed
refs #2: Let watch mode allow ALL syscalls and print extra info
1 parent 08cdf77 commit 56f9037

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

main.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ loop:
273273

274274
switch eventCause {
275275
case PTRACE_EVENT_SECCOMP:
276+
var extraInfo string = ""
276277
allow := true
277278
// Linux syscall convention for x86_64 arch:
278279
// - rax: syscall number
@@ -364,37 +365,48 @@ loop:
364365
// rsi is flags
365366
mode := int(regs.Rdx)
366367
allow = policyInst.CheckPathOp(path, policy.OP_OPEN, mode)
368+
extraInfo = path
367369
case id_Access:
368370
pathPtr := uintptr(regs.Rdi)
369371
path := utils.ReadString(result.pid, pathPtr)
370372
mode := int(regs.Rsi)
371373
allow = policyInst.CheckPathOp(path, policy.OP_ACCESS, mode)
374+
extraInfo = path
372375
case id_Fchmodat:
373376
pathPtr := uintptr(regs.Rsi)
374377
path := utils.ReadString(result.pid, pathPtr)
375378
path = utils.GetAbsPathAs(path, result.pid)
376379
mode := int(regs.Rdx)
377380
allow = policyInst.CheckPathOp(path, policy.OP_CHMOD, mode)
381+
extraInfo = path
378382
case id_Chmod:
379383
pathPtr := uintptr(regs.Rdi)
380384
path := utils.ReadString(result.pid, pathPtr)
381385
path = utils.GetAbsPathAs(path, result.pid)
382386
mode := int(regs.Rsi)
383387
allow = policyInst.CheckPathOp(path, policy.OP_CHMOD, mode)
388+
extraInfo = path
384389
default:
385390
allow = true
386391
}
387392
if !allow {
388393
if debug || watch {
389394
syscallName, _ := seccomp.ScmpSyscall(syscallId).GetName()
390395
color.Set(color.FgRed)
391-
l.Printf("blocked syscall %s\n", syscallName)
396+
if extraInfo != "" {
397+
l.Printf("blocked syscall %s (%s)", syscallName, extraInfo)
398+
} else {
399+
l.Printf("blocked syscall %s", syscallName)
400+
}
392401
color.Unset()
393402
}
394-
// Skip the system call with permission error
395-
regs.Orig_rax = 0xFFFFFFFFFFFFFFFF // -1
396-
regs.Rax = 0xFFFFFFFFFFFFFFFF - uint64(syscall.EPERM) + 1
397-
syscall.PtraceSetRegs(result.pid, &regs)
403+
// If we are not in the watch mode...
404+
if !watch {
405+
// Block the system call with permission error
406+
regs.Orig_rax = 0xFFFFFFFFFFFFFFFF // -1
407+
regs.Rax = 0xFFFFFFFFFFFFFFFF - uint64(syscall.EPERM) + 1
408+
syscall.PtraceSetRegs(result.pid, &regs)
409+
}
398410
} else {
399411
if debug {
400412
syscallName, _ := seccomp.ScmpSyscall(syscallId).GetName()
@@ -509,7 +521,9 @@ func main() {
509521
l.Printf("Debug mode is set.")
510522
}
511523
if watch {
512-
l.Printf("Watch mode is set.")
524+
color.Set(color.FgYellow)
525+
l.Printf("WATCH MODE: all syscalls are ALLOWED but it shows which ones will be blocked by the current policy.")
526+
color.Unset()
513527
}
514528

515529
if !childMode {

0 commit comments

Comments
 (0)