-
Notifications
You must be signed in to change notification settings - Fork 5
feat: use bpf_path_d_path for reading paths #1570
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
Draft
Molter73
wants to merge
3
commits into
mauro/feat/disable-preemption
from
mauro/feat/read-path-with-kfunc
+46
−10
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: stackrox/fact
Length of output: 18964
🏁 Script executed:
Repository: stackrox/fact
Length of output: 17254
🌐 Web query:
Linux eBPF verifier BPF_MAP_TYPE_PERCPU_ARRAY bpf_map_lookup_elem constant key PTR_TO_MAP_VALUE_OR_NULL nullable map value💡 Result:
When performing a lookup in a BPF_MAP_TYPE_PERCPU_ARRAY map using bpf_map_lookup_elem, the Linux eBPF verifier treats the returned pointer as a PTR_TO_MAP_VALUE_OR_NULL [1][2]. This designation indicates that the returned pointer may be NULL, even if the user logically knows the lookup will succeed (e.g., using a constant key within bounds) [3][2]. Here is a breakdown of how the verifier and this mechanism function: 1. Return Type: The helper function bpf_map_lookup_elem is defined with a return type of RET_PTR_TO_MAP_VALUE_OR_NULL [2]. Consequently, after the helper call, the register R0 (which holds the result) is assigned the type PTR_TO_MAP_VALUE_OR_NULL [2]. 2. Null-Check Requirement: Because the type includes the "OR_NULL" state, the verifier requires the eBPF program to explicitly check if the returned pointer is NULL (e.g., if (!ptr) return 0;) before accessing the memory it points to [3][2]. This check informs the verifier that the pointer is valid in the non-null branch, changing the register type from PTR_TO_MAP_VALUE_OR_NULL to PTR_TO_MAP_VALUE [2]. 3. Constant Keys and Verifier Behavior: Even when a constant key is provided, the verifier typically maintains this conservative approach [3]. While the verifier/JIT compiler may optimize array map lookups with constant keys into constant pointers or direct memory access for performance in some contexts, it generally still enforces the requirement for null-checking to ensure safety, unless specific newer mechanisms or compiler elisions are applied [4][3]. Recent efforts have explored ways for the verifier to recognize certain conditions to "elide" this nullness check, but standard practice remains to include the check [3]. 4. BPF_MAP_TYPE_PERCPU_ARRAY specifics: In this map type, bpf_map_lookup_elem automatically accesses the value slot corresponding to the current CPU [5][6]. The returned pointer points to this per-CPU memory area [5][7]. If you need to access values for specific CPUs other than the current one, the bpf_map_lookup_percpu_elem helper should be used instead, which also returns a PTR_TO_MAP_VALUE_OR_NULL and requires similar null-checking [5][8][9].
Citations:
Check
bound_pathbefore dereference.get_bound_path()returns the nullable result ofbpf_map_lookup_elem(). Line 559 dereferencesbound_pathwithout a null check. The BPF verifier can reject this access. Restore the failure check before accessingbound_path->path.🤖 Prompt for AI Agents