-
Notifications
You must be signed in to change notification settings - Fork 474
handle resolve of NULL pointers #4327
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
Open
andrewstrohman
wants to merge
9
commits into
cilium:main
Choose a base branch
from
andrewstrohman:pr/andrewstrohman/resolve-null
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
081661f
tetragon: handle resolving null pointer
andrewstrohman 52e5682
tetragon: add resolve_err_depth to KprobeArgument
andrewstrohman 724b45e
api: make protogen
andrewstrohman 268d12e
tracepoint: plumb resolve err depth into event
andrewstrohman 483aefd
tetragon: Plumb resolve error from bpf to event
andrewstrohman d2e8653
tester-progs: Add program that passes NULL
andrewstrohman e3c2f30
tetragon: test uprobe resolve failure
andrewstrohman 5bcb17c
tetragon: make GetIndex() consistent
andrewstrohman fb943fe
tetragon: Add additional returnCopy test
andrewstrohman 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,3 +38,5 @@ regs-override | |
| uretprobe | ||
| uprobe-resolve | ||
| uprobe-resolve.btf | ||
| uprobe-null | ||
| uprobe-null.btf | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,7 +40,8 @@ PROGS = sigkill-tester \ | |
| usdt-override \ | ||
| usdt-resolve \ | ||
| uretprobe \ | ||
| uprobe-resolve | ||
| uprobe-resolve \ | ||
| uprobe-null | ||
|
|
||
| PROGS += $(PROGS_ARCH) | ||
|
|
||
|
|
@@ -120,6 +121,13 @@ uprobe-resolve: uprobe-resolve.c | |
| llvm-objcopy -I binary -O elf64-x86-64 --rename-section .data=.BTF [email protected] [email protected] | ||
| rm [email protected] | ||
|
|
||
| uprobe-null: uprobe-null.c | ||
| $(GCC) -ggdb3 -O2 -Wall $< -o $@ | ||
| pahole -J $@ | ||
| llvm-objcopy --dump-section [email protected] $@ | ||
| llvm-objcopy -I binary -O elf64-x86-64 --rename-section .data=.BTF [email protected] [email protected] | ||
| rm [email protected] | ||
|
|
||
| ifeq ($(shell uname -m),x86_64) | ||
| regs-override: regs-override.c | ||
| $(GCC) -Wall -fcf-protection=none $< -o $@ | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| //go:build ignore | ||
|
|
||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
| #include <inttypes.h> | ||
| #include <stdbool.h> | ||
|
|
||
| struct mysubstruct { | ||
| int32_t val; | ||
| }; | ||
|
|
||
| struct mystruct { | ||
| struct mysubstruct *subp; | ||
| }; | ||
|
|
||
| void usage(char *argv0) | ||
| { | ||
| fprintf(stderr, "Usage: %s <type>\n", argv0); | ||
| fprintf(stderr, "type can be one of: first, middle, nonull\n"); | ||
| } | ||
|
|
||
| // without noinline, the symbol is found, but no event fires | ||
| __attribute__((noinline)) int func(struct mystruct *ms) { | ||
| if (!ms) | ||
| return -1; | ||
|
|
||
| if (!ms->subp) | ||
| return -1; | ||
|
|
||
| printf("%d\n", ms->subp->val); | ||
| return 0; | ||
| } | ||
|
|
||
| int main(int argc, char *argv[]) | ||
| { | ||
|
|
||
| if (argc < 2) { | ||
| usage(argv[0]); | ||
| exit(1); | ||
| } | ||
|
|
||
| char *type = argv[1]; | ||
|
|
||
| if (!strcmp(type, "first")) { | ||
| func(NULL); | ||
| } else if (!strcmp(type, "middle")) { | ||
| struct mystruct ms; | ||
| ms.subp = NULL; | ||
| func(&ms); | ||
| } else if (!strcmp(type, "nonull")) { | ||
| struct mystruct ms; | ||
| struct mysubstruct mss; | ||
| ms.subp = &mss; | ||
| mss.val = 0; | ||
| func(&ms); | ||
| } else { | ||
| usage(argv[0]); | ||
| exit(1); | ||
| } | ||
| exit(0); | ||
| } |
Oops, something went wrong.
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.
so if we fail to resolve we still continue and store the 'unresolved data' which likely null, right? I think we can skip it
but how about we make this more generic and we start each argument data with '__u32 error' status and in case of failure we write just error != 0 as argument value.. in case of resolve failure we encode the depth into it
then on user space side the getArg would just read first uint32 from event reader to get the argument status
so all the extra retrieval of error depth from each probe type would not be needed, also probably the argument index will be clear, because you have the error for argument you are about to read, or skip reading if it's != 0
we could use this to store other errors that happen during argument encoding, which there are plenty
and into final event instead of the depth value, I'd add error string that in case of resolve failure would contain something like: "failed to resolve current->file->f_inode"
seems like this could save some cycles and prevent bogus arguments values, because IIUC if we bail from argument storing in the middle on kernel side the user side still tries to read the whole part