Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clock time detection #4513

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.22.4
require (
github.com/IBM/fluent-forward-go v0.2.2
github.com/Masterminds/sprig/v3 v3.3.0
github.com/aquasecurity/libbpfgo v0.7.0-libbpf-1.4.0.20240729111821-61d531acf4ca
github.com/aquasecurity/libbpfgo v0.8.0-libbpf-1.5.0.20250117141322-c0ac6035ae61
github.com/aquasecurity/tracee/api v0.0.0-20250117110942-a403bd985f72
github.com/aquasecurity/tracee/signatures/helpers v0.0.0-20241225084355-5b8f456dae7b
github.com/aquasecurity/tracee/types v0.0.0-20250117124739-92cb7e0f7155
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ github.com/Microsoft/hcsshim v0.12.3 h1:LS9NXqXhMoqNCplK1ApmVSfB4UnVLRDWRapB6EIl
github.com/Microsoft/hcsshim v0.12.3/go.mod h1:Iyl1WVpZzr+UkzjekHZbV8o5Z9ZkxNGx6CtY2Qg/JVQ=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/aquasecurity/libbpfgo v0.7.0-libbpf-1.4.0.20240729111821-61d531acf4ca h1:OPbvwFFvR11c1bgOLhBq1R5Uk3hwUjHW2KfrdyJan9Y=
github.com/aquasecurity/libbpfgo v0.7.0-libbpf-1.4.0.20240729111821-61d531acf4ca/go.mod h1:UpO6kTehEgAGGKR2twztBxvzjTiLiV/cb2xmlYb+TfE=
github.com/aquasecurity/libbpfgo v0.8.0-libbpf-1.5.0.20250117141322-c0ac6035ae61 h1:EdqmOm8rk/FMtYetPcceDdW27lZxXzpHZw8XpF3lG+g=
github.com/aquasecurity/libbpfgo v0.8.0-libbpf-1.5.0.20250117141322-c0ac6035ae61/go.mod h1:HB2DYWHuMraOB0IFcfjL8tsxN8TcFOdWKTrNqnHrTrs=
github.com/aquasecurity/tracee/api v0.0.0-20250117110942-a403bd985f72 h1:M1G3ttGcozWGfMMlD2nbdCgskGkAHSIVMsodRykOYSE=
github.com/aquasecurity/tracee/api v0.0.0-20250117110942-a403bd985f72/go.mod h1:mSYGLfhjpcLq78gjb4/XDQaY8DhfpDNAuLD0tvU2bZc=
github.com/aquasecurity/tracee/signatures/helpers v0.0.0-20241225084355-5b8f456dae7b h1:eTIrU0vdn49P0LhtEypnSdGgoRzLvNPAGivGHPnCBXg=
Expand Down
21 changes: 13 additions & 8 deletions pkg/ebpf/tracee.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ package ebpf
import (
gocontext "context"
"encoding/binary"
"errors"
"fmt"
"os"
"strconv"
"strings"
"sync"
"sync/atomic"
"syscall"
"unsafe"

"kernel.org/pub/linux/libs/security/libcap/cap"
Expand Down Expand Up @@ -384,17 +382,24 @@ func (t *Tracee) Init(ctx gocontext.Context) error {
usedClockID := traceetime.CLOCK_BOOTTIME
err = capabilities.GetInstance().EBPF(
func() error {
// Since this code is running with sufficient capabilities, we can safely trust the result of `BPFHelperIsSupported`.
// If the helper is reported as supported (`supported == true`), it is assumed to be reliable for use.
// If `supported == false`, it indicates that the helper for getting BOOTTIME is not available.
// The `innerErr` provides information about errors that occurred during the check, regardless of whether `supported`
// is true or false.
// For a full explanation of the caveats and behavior, refer to:
// https://github.com/aquasecurity/libbpfgo/blob/eb576c71ece75930a693b8b0687c5d052a5dbd56/libbpfgo.go#L99-L119
supported, innerErr := bpf.BPFHelperIsSupported(bpf.BPFProgTypeKprobe, bpf.BPFFuncKtimeGetBootNs)

// only report if operation not permitted
if errors.Is(innerErr, syscall.EPERM) {
return innerErr
}

// If BPFFuncKtimeGetBootNs is not available, eBPF will generate events based on monotonic time.
// Use CLOCK_MONOTONIC only when the helper is explicitly unsupported
if !supported {
usedClockID = traceetime.CLOCK_MONOTONIC
}

if innerErr != nil {
logger.Debugw("Detect clock timing", "warn", innerErr)
}

return nil
})
if err != nil {
Expand Down
Loading