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

Adds flag to exec events indicating a memfd target #161

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Tacklebox
Copy link
Contributor

Also adds flags for whether the exec target is has setuid and/or setgid bits set

Also adds flags for whether the exec target is has setuid and/or setgid
bits set
@Tacklebox Tacklebox requested review from rhysre, m-sample, a team and lrishi November 7, 2022 22:13
Copy link
Contributor

@rhysre rhysre left a comment

Choose a reason for hiding this comment

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

Left a few comments.

Also I really wouldn't be comfortable merging this without some multi-kernel tests to ensure the suid/sgid/memfd detection work on all kernels we support. They should be pretty straightforward to write (just a test binary that does memfd_create and chmod as needed and some asserts to check data is correct).

Let me know if you have any issues with the test setup and I'd be happy to lend a hand.

// memfd exec
char buf [7];
bpf_probe_read_kernel_str(buf, 7, binprm->file->f_path.dentry->d_iname);
if (buf[0] == 'm' && buf[1] == 'e' && buf[2] == 'm' && buf[3] == 'f' && buf[4] == 'd' && buf[5] == ':' )
Copy link
Contributor

Choose a reason for hiding this comment

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

For readability, I'd recommend just writing a 4 line implementation of strncmp in Helpers.h and using that here. You can put the string memfd: on the stack.

@@ -115,6 +118,15 @@ int BPF_PROG(sched_process_exec,
size = read_kernel_str_or_empty_str(field->data, PATH_MAX, binprm->filename);
ebpf_vl_field__set_size(&event->vl_fields, field, size);

// memfd exec
char buf [7];
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: needs code format, CI won't pass without it.

@@ -446,6 +456,15 @@ static void out_process_exec(struct ebpf_process_exec_event *evt)
out_cred_info("creds", &evt->creds);
out_comma();

out_named_object_start("red_flags");
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO the nesting here is unnecessary, I say just keep them at the top level.

out_comma();
out_bool_flag("is_setuid", evt->is_setuid);
out_comma();
out_bool_flag("is_setgid", evt->is_setgid);
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO out_bool_flag should just be out_bool for simplicity and consistency with the other out_ functions.

@lrishi
Copy link
Contributor

lrishi commented Nov 21, 2022

Ping: @Tacklebox Can we address the review comments and merge this asap, Thanks!

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

Successfully merging this pull request may close these issues.

3 participants