Skip to content

Commit f5cb740

Browse files
committed
fix: clock time detection
- The clock time detection was rework since the libbpfgo func BPFHelperIsSupported changed; - Unless it is explicitly marked as unsupported (supported=false), it will default to BOOTTIME.
1 parent 34224a9 commit f5cb740

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

pkg/ebpf/tracee.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ package ebpf
33
import (
44
gocontext "context"
55
"encoding/binary"
6-
"errors"
76
"fmt"
87
"os"
98
"strconv"
109
"strings"
1110
"sync"
1211
"sync/atomic"
13-
"syscall"
1412
"unsafe"
1513

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

389-
// only report if operation not permitted
390-
if errors.Is(innerErr, syscall.EPERM) {
391-
return innerErr
392-
}
393-
394-
// If BPFFuncKtimeGetBootNs is not available, eBPF will generate events based on monotonic time.
394+
// Use CLOCK_MONOTONIC only when the helper is explicitly unsupported
395395
if !supported {
396396
usedClockID = traceetime.CLOCK_MONOTONIC
397397
}
398+
399+
if innerErr != nil {
400+
logger.Debugw("Detect clock timing", "warn", innerErr)
401+
}
402+
398403
return nil
399404
})
400405
if err != nil {

0 commit comments

Comments
 (0)