-
Notifications
You must be signed in to change notification settings - Fork 431
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
fix empty arguments resolution #4442
Conversation
Let's change all parsers inside this file that currently return an empty value on an error to return the raw value instead |
Okay, but I think the code is still going to look weird because if we just print the information without any need for processing it behind the scenes, why would we write the function like this: func funcArg(arg *trace.Argument, val uint64) {
arg.Type = "string"
argument, err := parsers.funcArg(mode)
if err != nil {
arg.Value = ""
return
}
arg.Value = argument.String()
} instead of like this: func funcArg(arg *tracee.Argument, val uint64) {
arg.Type = "string"
arg.Value = val
} or just remove it entirely? It looks pretty weird that we check for an error and don't even use it. Note: Not every function behaves like this, but most of them do. |
We do use the error, that way we know to use the raw value. |
Because the parsers return the parsed value of the argument. For example, if some (fake) argument has a raw value 0x4 which means F_WRITE, the output string will be "F_WRITE". However, if it has a value of 0x20, but the parsers don't know this value, an error will be returned. In this case, we can simply return the string value of the raw argument, which is "0x20" |
LGTM |
@yanivagman I added tests for parse_args_helpers.go |
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.
Put some thoughts.
12045c9
to
880d400
Compare
When tracee tries to resolve a numeric argument to a string (e.g. cmd value of bpf syscall), if the resolution fails, the event field will contain an empty string. Return the raw value as a string in case of a failed resolution.
1cbdc3d
to
a3c9df7
Compare
@@ -157,7 +160,7 @@ func parseBPFCmd(arg *trace.Argument, cmd uint64) { | |||
arg.Type = "string" | |||
bpfCommandArgument, err := parsers.ParseBPFCmd(cmd) | |||
if err != nil { | |||
arg.Value = "" | |||
arg.Value = strconv.FormatUint(cmd, 10) |
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.
Since the cmd
field from both ebpf
and security_bpf
is int
, shouldn't we use the following instead?
arg.Value = strconv.FormatInt(int64(cmd), 10)
If we use BPF_INVALID_CMD=-1
in the python script, the Tracee result in cmd
field is 18446744073709551615
(0xFFFFFFFFFFFFFFFF
) and not -1, take a look:
sudo ./dist/tracee -e bpf -s comm=python3.10
TIME UID COMM PID TID RET EVENT ARGS
06:13:50:764876 1000 python3.10 117825 117825 -1 bpf cmd: 18446744073709551615, attr: 0x0, size: 0
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.
well as you can see the cmd arg is unit64 and not int64, do you suggest we change it to int64?
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.
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.
I reviewed this issue and think it is a great addition, also removes unnecessary casting that will also resolute in better performance
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.
LGTM
1. Explain what the PR does
make check-pr
:1cbdc3d tests: add argument parsers tests
69d55cb fix: empty arguments resolution
69d55cb fix: empty arguments resolution
2. Explain how to test it
In order to test you can run the test in the file with this command
TestParseArgsHelpers
to a function name like:TestParseBPFCmd
to test a more specific3. Other comments
Resolves #3892