-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinvalid_offset.go
More file actions
67 lines (51 loc) · 1.74 KB
/
invalid_offset.go
File metadata and controls
67 lines (51 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2024 Leon Hwang.
// SPDX-License-Identifier: Apache-2.0
package main
import (
"context"
"log"
"os"
"os/signal"
"github.com/Asphaltt/tailcall-issues/internal/assert"
"github.com/cilium/ebpf"
"github.com/cilium/ebpf/link"
)
//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -cc clang invalid ./bpf/invalid-offset.c -- -g -D__TARGET_ARCH_x86 -I./bpf/headers -Wall
func checkIssueInvalidOffset(progID uint32) {
var objs invalidObjects
err := loadInvalidObjects(&objs, nil)
assert.NoVerifierErr(err, "Failed to load invalid-offset bpf objects: %v")
defer objs.Close()
err = objs.JmpTable.Put(uint32(0), objs.Tailcallee)
assert.NoErr(err, "Failed to put tailcallee into jmp table: %v")
info, err := newBpfProgInfo(objs.Entry, false)
assert.NoErr(err, "Failed to get program info: %v")
if info.issueInvalidOffset {
log.Printf("Current kernel has invalid offset issue")
} else {
log.Printf("Current kernel does not have invalid offset issue")
}
l, err := link.Kprobe("tcp_connect", objs.Entry, nil)
assert.NoErr(err, "Failed to attach kprobe: %v")
defer l.Close()
if progID != 0 {
prog, err := ebpf.NewProgramFromID(ebpf.ProgramID(progID))
assert.NoErr(err, "Failed to get program from ID: %v")
defer prog.Close()
info, err := newBpfProgInfo(prog, false)
assert.NoErr(err, "Failed to get program info: %v")
if info.issueInvalidOffset {
log.Printf("BPF program (id=%d name=%s) has invalid offset issue", progID, info.name)
} else {
log.Printf("BPF program (id=%d name=%s) does not have invalid offset issue", progID, info.name)
}
return
}
if !waitToExit {
return
}
log.Printf("Ctrl+C to stop ..")
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()
<-ctx.Done()
}