Skip to content
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

tetragon: Check the returned data length for exec arguments #211

Merged
merged 1 commit into from
Jul 1, 2022

Conversation

olsajiri
Copy link
Contributor

@olsajiri olsajiri commented Jun 30, 2022

It can actually happen that there will be no arguments
or filename, in which case we need to check the data
length and api.EventErrorFilename flag.

Signed-off-by: Jiri Olsa [email protected]

Copy link
Contributor

@willfindlay willfindlay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@olsajiri can we do similar bounds checking here? This could also panic if Index() returns -1 (which it can).

} else {
n := bytes.Index(args, []byte{0x00})
proc.Filename = string(args[:n])
args = args[n+1:]

@jrfastab
Copy link
Contributor

And unit test would be great.

It can actually happen that there will be no arguments
or filename, in which case we need to check the data
length and api.EventErrorFilename flag.

Signed-off-by: Jiri Olsa <[email protected]>
@olsajiri
Copy link
Contributor Author

And unit test would be great.

this seems to happen when probe_read_str fails to read the filename,
I'll check but not sure there's easy way to simulate that

@olsajiri olsajiri marked this pull request as ready for review July 1, 2022 08:20
@olsajiri olsajiri requested a review from a team as a code owner July 1, 2022 08:20
@olsajiri olsajiri requested a review from kevsecurity July 1, 2022 08:20
@kkourt kkourt merged commit b0edd37 into cilium:main Jul 1, 2022
@olsajiri
Copy link
Contributor Author

olsajiri commented Jul 1, 2022

And unit test would be great.

this seems to happen when probe_read_str fails to read the filename, I'll check but not sure there's easy way to simulate that

fwiw I managed to reproduce with:

--- a/bpf/process/bpf_execve_event.c
+++ b/bpf/process/bpf_execve_event.c
@@ -116,7 +116,10 @@ event_filename_builder(void *ctx, struct msg_process *curr, __u32 curr_pid,
        earg = (void *)curr + offsetof(struct msg_process, args);
 
        size = probe_read_str(earg, MAXARGLENGTH - 1, filename);
-       if (size < 0) {
+       if (1) {
+               flags |= EVENT_ERROR_FILENAME;
+               size = 0;
+       } else if (size < 0) {
                flags |= EVENT_ERROR_FILENAME;
                size = 0;
        } else if (size == MAXARGLENGTH - 1) {

and the change fixes the crash.. maybe we could have a way to instrument bpf program to trigger the error for some binary name and test that.. but that'd mean more changes

@kkourt
Copy link
Contributor

kkourt commented Jul 11, 2022

maybe we could have a way to instrument bpf program to trigger the error for some binary name and test that.. but that'd mean more changes

👍

A simpler solution might be to add some unit tests on the go side for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants