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

TcHook.Detach() always raises the failed to detach tc hook: invalid argument error. #420

Closed
mozillazg opened this issue Apr 6, 2024 · 7 comments

Comments

@mozillazg
Copy link
Contributor

mozillazg commented Apr 6, 2024

TcHook.Detach() always raises the failed to detach tc hook: invalid argument error.

$ git diff
diff --git a/selftest/tc/main.go b/selftest/tc/main.go
index 0174eb1..4137fc2 100644
--- a/selftest/tc/main.go
+++ b/selftest/tc/main.go
@@ -61,6 +61,12 @@ func main() {
                fmt.Fprintln(os.Stderr, err)
                os.Exit(-1)
        }
+       defer func() {
+               if err := hook.Detach(&tcOpts); err != nil {
+                       fmt.Fprintln(os.Stderr, err)
+                       os.Exit(-1)
+               }
+       }()
 
        eventsChannel := make(chan []byte)
        rb, err := bpfModule.InitRingBuf("events", eventsChannel)
$ make run
...
failed to detach tc hook: invalid argument
[!] ERROR: test error

test with the main branch: a55c024

@geyslan
Copy link
Member

geyslan commented Apr 8, 2024

@mozillazg I couldn't reproduce it in the vagrant VM, only got this:

libbpf: object 'main': failed (-22) to create BPF token from '/sys/fs/bpf', skipping optional step...

The unique detected besides that type is libbpf: map 'tester': failed to create: Invalid argument(-22) in selftest/map-autocreate: https://github.com/aquasecurity/libbpfgo/actions/runs/8570253314/job/23488218928#step:4:1585

What's your testing env?

@mozillazg
Copy link
Contributor Author

@geyslan we can reproduce it in the ci env:
mozillazg#9

chentao-kernel added a commit to chentao-kernel/libbpfgo that referenced this issue Apr 8, 2024
The bpf_tc_query interface should init the parameter first, sometimes
it may be confused for us, so add the case to reduce the confusion.

aquasecurity#421
aquasecurity#420

Signed-off-by: Tao Chen <[email protected]>
@chentao-kernel
Copy link
Contributor

@geyslan @mozillazg hi, geyslan, i think it is same issue with 211, and i also add test case again.

chentao-kernel added a commit to chentao-kernel/libbpfgo that referenced this issue Apr 8, 2024
The bpf_tc_query/bpf_tc_detach interface should init the parameter first,
sometimes it may be confused for us, so add the case to reduce the confusion.

aquasecurity#421
aquasecurity#420

Signed-off-by: Tao Chen <[email protected]>
chentao-kernel added a commit to chentao-kernel/libbpfgo that referenced this issue Apr 8, 2024
The bpf_tc_query/bpf_tc_detach interface should init the parameter first,
sometimes it may be confused for us, so add the case to reduce the confusion.

aquasecurity#421
aquasecurity#420

Signed-off-by: Tao Chen <[email protected]>
@chentao-kernel
Copy link
Contributor

@geyslan @mozillazg hi, geyslan, i think it is same cause with #421, and i also add test case for it.

chentao-kernel added a commit to chentao-kernel/libbpfgo that referenced this issue Apr 8, 2024
The bpf_tc_query/bpf_tc_detach interface should init the parameter
first, sometimes it may be confused for us, so add the case to reduce
the confusion.

aquasecurity#421
aquasecurity#420

Signed-off-by: Tao Chen <[email protected]>
chentao-kernel added a commit to chentao-kernel/libbpfgo that referenced this issue Apr 8, 2024
The bpf_tc_query/bpf_tc_detach interface should init the parameter
first, sometimes it may be confused for us, so add the case to reduce
the confusion.

aquasecurity#421
aquasecurity#420

Signed-off-by: Tao Chen <[email protected]>
@chentao-kernel
Copy link
Contributor

@mozillazg I couldn't reproduce it in the vagrant VM, only got this:我无法在流浪者虚拟机中重现它,只得到这个:

libbpf: object 'main': failed (-22) to create BPF token from '/sys/fs/bpf', skipping optional step...

The unique detected besides that type is libbpf: map 'tester': failed to create: Invalid argument(-22) in selftest/map-autocreate: https://github.com/aquasecurity/libbpfgo/actions/runs/8570253314/job/23488218928#step:4:1585除该类型外,检测到的唯一值 libbpf: map 'tester': failed to create: Invalid argument(-22)selftest/map-autocreatehttps://github.com/aquasecurity/libbpfgo/actions/runs/8570253314/job/23488218928#step:4:1585

What's your testing env?您的测试环境是什么?

@geyslan, it it not the same issue with #420
it may be caused by the ebpf new feature of token

@chentao-kernel
Copy link
Contributor

chentao-kernel commented Apr 9, 2024

@mozillazg I couldn't reproduce it in the vagrant VM, only got this:我无法在流浪者虚拟机中重现它,只得到这个:
libbpf: object 'main': failed (-22) to create BPF token from '/sys/fs/bpf', skipping optional step...
The unique detected besides that type is libbpf: map 'tester': failed to create: Invalid argument(-22) in selftest/map-autocreate: https://github.com/aquasecurity/libbpfgo/actions/runs/8570253314/job/23488218928#step:4:1585除该类型外,检测到的唯一值 libbpf: map 'tester': failed to create: Invalid argument(-22)selftest/map-autocreatehttps://github.com/aquasecurity/libbpfgo/actions/runs/8570253314/job/23488218928#step:4:1585
What's your testing env?您的测试环境是什么?

@geyslan, it it not the same issue with #420 it may be caused by the ebpf new feature of token

It seems that the vm not support ebpf token in kernel, but anyway, the result of test case will not be influenced.

chentao-kernel added a commit to chentao-kernel/libbpfgo that referenced this issue Apr 9, 2024
The bpf_tc_query/bpf_tc_detach interface should init the parameter
first, sometimes it may be confused for us, so add the case to reduce
the confusion.

aquasecurity#421
aquasecurity#420

Signed-off-by: Tao Chen <[email protected]>
geyslan pushed a commit that referenced this issue Apr 9, 2024
The bpf_tc_query/bpf_tc_detach interface should init the parameter
first, sometimes it may be confused for us, so add the case to reduce
the confusion.

#421
#420

Signed-off-by: Tao Chen <[email protected]>
@mozillazg
Copy link
Contributor Author

Closed via #422

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants