fix(run-queue): guard detach against NULL obj in cleanup path - #155
Open
yuKing123-king wants to merge 1 commit into
Open
yuKing123-king wants to merge 1 commit into
yuKing123-king wants to merge 1 commit into
Conversation
Signed-off-by: Wang Yu <wangyu6@uniontech.com>
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修复的 Bug
run-queue在 BPF 加载失败时,cleanup路径会对 NULL 指针解引用,导致 SIGSEGV 崩溃。触发路径:
open_and_load返回 NULL 是现实可触发的:非 root 运行、内核版本不支持该 BPF 程序、内存不足(calloc失败)。用户在非特权或低内存场景运行run-queue,BPF 加载失败后本应清理退出,却在detach(NULL)处崩溃。为什么这样修复
根因是 libbpf skeleton 生成代码的不对称缺陷:经核实
build/observe/run-queue.skel.h,run_queue_bpf__destroy()有if (!obj) return;判空(skeleton.h:57-58),但run_queue_bpf__detach()无判空,直接bpf_object__detach_skeleton(obj->skeleton)解引用(skeleton.h:133)。这是 libbpf 生成代码的固有问题,不应在工具侧"修改 skeleton",而应在调用点(run-queue.cpp的 cleanup)规避。只在工具侧加
if (obj),不改 skeleton.h:skeleton.h 是构建系统自动生成的(bpftool gen skeleton),任何手改都会被下次构建覆盖;正确的修复点在调用方。且cleanup段上方对rb已有if (rb)判空,detach加判空风格一致,最小改动。destroy不加判空:run_queue_bpf__destroy()已自带if (!obj) return;,对 NULL 调用安全,无需改动,避免冗余。验证方式