Skip to content

Commit

Permalink
tracing: ensure strings are valid utf-8
Browse files Browse the repository at this point in the history
[ upstream commit 7c7ed6a ]

Kprobe arguments that include strings are generated using
handleGenericKprobeString. Because protobufs only support strings that
are valid utf-8, we need to ensure that the strings we get from bpf are
valid utf-8.

Also, ensure that Path in loader is valid utf-8.

Signed-off-by: Kornilios Kourtis <[email protected]>
  • Loading branch information
kkourt committed Jul 28, 2023
1 parent 7c1c7d1 commit b1937f1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/sensors/tracing/generickprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/cilium/tetragon/pkg/sensors"
"github.com/cilium/tetragon/pkg/sensors/base"
"github.com/cilium/tetragon/pkg/sensors/program"
"github.com/cilium/tetragon/pkg/strutils"
lru "github.com/hashicorp/golang-lru/v2"
"github.com/sirupsen/logrus"

Expand Down Expand Up @@ -739,7 +740,7 @@ func handleGenericKprobeString(r *bytes.Reader, def string) string {
return def
}

strVal := string(outputStr[:])
strVal := strutils.UTF8FromBPFBytes(outputStr[:])
lenStrVal := len(strVal)
if lenStrVal > 0 && strVal[lenStrVal-1] == '\x00' {
strVal = strVal[0 : lenStrVal-1]
Expand Down
3 changes: 2 additions & 1 deletion pkg/sensors/tracing/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/cilium/tetragon/pkg/policyfilter"
"github.com/cilium/tetragon/pkg/sensors"
"github.com/cilium/tetragon/pkg/sensors/program"
"github.com/cilium/tetragon/pkg/strutils"
"github.com/cilium/tetragon/pkg/tracingpolicy"
"golang.org/x/sys/unix"
)
Expand Down Expand Up @@ -168,7 +169,7 @@ func handleLoader(r *bytes.Reader) ([]observer.Event, error) {
msg := &tracing.MsgProcessLoaderUnix{
ProcessKey: m.ProcessKey,
Ktime: m.Common.Ktime,
Path: string(path),
Path: strutils.UTF8FromBPFBytes(path),
Buildid: m.BuildId[:m.BuildIdSize],
}
return []observer.Event{msg}, nil
Expand Down

0 comments on commit b1937f1

Please sign in to comment.