From 6258291815e823034218fc617c3fc70978d7137b Mon Sep 17 00:00:00 2001 From: Fabricio Voznika Date: Wed, 15 Jun 2022 13:37:13 -0700 Subject: [PATCH] Small fixes to trace points Don't collect `cwd` when task root is not present anymore, e.g. zombie. Limit the size allocated for address in `connect(2)`. Updates #4805 PiperOrigin-RevId: 455208465 --- pkg/sentry/kernel/seccheck.go | 14 ++++++++------ pkg/sentry/syscalls/linux/points.go | 5 +---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/pkg/sentry/kernel/seccheck.go b/pkg/sentry/kernel/seccheck.go index 9afb7c130..9d680235e 100644 --- a/pkg/sentry/kernel/seccheck.go +++ b/pkg/sentry/kernel/seccheck.go @@ -49,12 +49,14 @@ func LoadSeccheckDataLocked(t *Task, mask seccheck.FieldMask, info *pb.ContextDa info.ContainerId = t.tg.leader.ContainerID() } if mask.Contains(seccheck.FieldCtxtCwd) { - root := t.FSContext().RootDirectoryVFS2() - defer root.DecRef(t) - wd := t.FSContext().WorkingDirectoryVFS2() - defer wd.DecRef(t) - vfsObj := root.Mount().Filesystem().VirtualFilesystem() - info.Cwd, _ = vfsObj.PathnameWithDeleted(t, root, wd) + if root := t.FSContext().RootDirectoryVFS2(); root.Ok() { + defer root.DecRef(t) + if wd := t.FSContext().WorkingDirectoryVFS2(); wd.Ok() { + defer wd.DecRef(t) + vfsObj := root.Mount().Filesystem().VirtualFilesystem() + info.Cwd, _ = vfsObj.PathnameWithDeleted(t, root, wd) + } + } } if mask.Contains(seccheck.FieldCtxtProcessName) { info.ProcessName = t.Name() diff --git a/pkg/sentry/syscalls/linux/points.go b/pkg/sentry/syscalls/linux/points.go index bedfeb899..6b7a3956c 100644 --- a/pkg/sentry/syscalls/linux/points.go +++ b/pkg/sentry/syscalls/linux/points.go @@ -191,10 +191,7 @@ func PointConnect(t *kernel.Task, fields seccheck.FieldSet, cxtData *pb.ContextD addr := info.Args[1].Pointer() addrlen := info.Args[2].Uint() - if addr > 0 { - p.Address = make([]byte, addrlen) - _, _ = t.CopyInBytes(addr, p.Address) - } + p.Address, _ = CaptureAddress(t, addr, addrlen) if fields.Local.Contains(seccheck.FieldSyscallPath) { p.FdPath = getFilePath(t, int32(p.Fd))