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

[v0.22.4-1] fix: clock time detection #4529

Merged
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.2.3
github.com/aquasecurity/libbpfgo v0.7.0-libbpf-1.4.0.20240729111821-61d531acf4ca
github.com/aquasecurity/libbpfgo v0.7.0-libbpf-1.4.0.20250117141734-5eb6fe431140
github.com/aquasecurity/tracee/api v0.0.0-20240910204947-35a9e259821a
github.com/aquasecurity/tracee/signatures/helpers v0.0.0-20240607205742-90c301111aee
github.com/aquasecurity/tracee/types v0.0.0-20241011005226-27f2cbdf6bd7
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdII
github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRBij0P8=
github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo=
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.7.0-libbpf-1.4.0.20250117141734-5eb6fe431140 h1:5dR75+C8hqo6PCErThbZvvkZ1DZYJzprv3DHnUVnEP0=
github.com/aquasecurity/libbpfgo v0.7.0-libbpf-1.4.0.20250117141734-5eb6fe431140/go.mod h1:UpO6kTehEgAGGKR2twztBxvzjTiLiV/cb2xmlYb+TfE=
github.com/aquasecurity/tracee/api v0.0.0-20240910204947-35a9e259821a h1:J+Kfx5Ju7084mov6cgqxf74x2bH5kH9bIqHlAtmwhvM=
github.com/aquasecurity/tracee/api v0.0.0-20240910204947-35a9e259821a/go.mod h1:Gn6xVkaBkVe1pOQ0++uuHl+lMMClv0TPY8mCQ6j88aA=
github.com/aquasecurity/tracee/signatures/helpers v0.0.0-20240607205742-90c301111aee h1:1KJy6Z2bSpmKQVPShU7hhbXgGVOgMwvzf9rjoWMTYEg=
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 @@ -525,17 +523,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