# Try the eBPF and BPF 想要側錄以觀察同 [namespace](https://man7.org/linux/man-pages/man7/namespaces.7.html) 的所有 syscall 行為。 參考 [Linux 核心設計: 透過 eBPF 觀察作業系統行為](https://hackmd.io/@sysprog/linux-ebpf),以及 [Dockercon19-eBPF Superpowers](https://www.youtube.com/watch?v=4SiWL5tULnQ) 提到的 Hello world of eBPF (rename to ./clone.py) 輸出結果:(圖一)  > cannot attach kprobe, probe entry may not exist ## 不知道為什麼沒有 entry 是 Kernal option 沒有開嗎? 檢查 [iovisor/bcc Kernel Configuration](https://github.com/iovisor/bcc/blob/master/INSTALL.md#kernel-configuration) 提到: ``` CONFIG_BPF=y CONFIG_BPF_SYSCALL=y # [optional, for tc filters] CONFIG_NET_CLS_BPF=m # [optional, for tc actions] CONFIG_NET_ACT_BPF=m CONFIG_BPF_JIT=y # [for Linux kernel versions 4.1 through 4.6] CONFIG_HAVE_BPF_JIT=y # [for Linux kernel versions 4.7 and later] CONFIG_HAVE_EBPF_JIT=y # [optional, for kprobes] CONFIG_BPF_EVENTS=y # Need kernel headers through /sys/kernel/kheaders.tar.xz CONFIG_IKHEADERS=y ``` * 猜測:可能因為沒有 `CONFIG_IKHEADERS` 選項導致 (此時 kernel 版本 5.10.8)(圖二)  因此重編譯 Kernel,並設定開啟該選項:(圖三)  但是執行結果仍如上(圖一)。 **等等再追 code 解決** ## 轉向 `bpftrace` 看看是否可行。 直接先使用 `apt` 套件安裝 `bpftrace` 工具鏈 ```shell= sudo apt install bpftrace libbpfcc-dev -y ``` Double free?(圖四)  是,這時候應該「路見不平,拿patch 來填」 先 build build 看 ```shell= git clone https://github.com/iovisor/bpftrace.git mkdir bpftrace/build && cd bpftrace/build cmake -DCMAKE_BUILD_TYPE=Release .. make -j $(nproc) sudo make install ``` (圖五)  (圖六) 執行看看剛下載編譯的:  Well, 還是一樣。 也先 **等等再追 code 解決** ## bpftrace using docker 不知道是否與發行版相關,但是「直覺」與發行版相關的機率很低,已時間成本考量,先試試看轉換到 docker 環境,是否仍就有問題? bpftrace GitHub [INSTALL.md](https://github.com/iovisor/bpftrace/blob/master/INSTALL.md#using-docker) 提到: > There are currently problems with bpftrace string comparisons when using the Docker build. 有不詳的預感,蛋還是先試試吧? (圖七)  Successfully tagged bpftrace-builder-alpine:latest 看來是 ./build-docker-image.sh 是可行的。 但是 ./build-release.sh 缺少 `GTest`, `libbfd`, `libopcodes` 但是在該 dockerfile step 5 中有 `libbpf-dev`, `gtest-dev`, `elfutils-dev`  經查詢資料,是這三個 package 沒錯。 * Build debug 好吧,如果不能 release 版,看看 debug 版吧。  說道: > static libc is known to cause problems, consider STATIC_LIBC=OFF. Procee at your own risk. 並同時有缺少 libbfd, libopcodes development package 好,關掉。並重新執行:  仍就缺少 those package。
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up