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

fix(driver): drop EF_USES_FD and EF_MODIFIES_STATE flags for enter events generated by uring syscalls #395

Merged

Conversation

alacuku
Copy link
Member

@alacuku alacuku commented Jun 14, 2022

Signed-off-by: Aldo Lacuku <aldo@lacuku.eu>

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind bug

/kind cleanup

/kind design

/kind documentation

/kind failing-test

/kind feature

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area build

/area driver-kmod

/area driver-bpf

/area driver-modern-bpf

/area libscap-engine-bpf

/area libscap-engine-gvisor

/area libscap-engine-kmod

/area libscap-engine-modern-bpf

/area libscap-engine-nodriver

/area libscap-engine-noop

/area libscap-engine-source-plugin

/area libscap-engine-udig

/area libscap

/area libsinsp

/area tests

/area proposals

What this PR does / why we need it:
This PR prevents libs from crashing when handling events generated by io_uring_enter and io_uring_register syscalls.

Which issue(s) this PR fixes:

Fixes #
When Falco is running with -A option enabled and receives events generated by io_uring_enter and io_uring_register syscalls it crashes with the following error:

Runtime error: vector::_M_range_check: __n (which is 0) >= this->size() (which is 0). Exiting.

That is because ENTER events for the io_uring_enter and io_uring_register syscalls presented the EF_USES_FD flag. When the flag is set the libsinsp tries to extract the file descriptor from the event:

if(eflags & EF_USES_FD)
{
sinsp_evt_param *parinfo;
//
// Get the fd.
// The fd is always the first parameter of the enter event.
//
parinfo = evt->get_param(0);
ASSERT(parinfo->m_len == sizeof(int64_t));
ASSERT(evt->get_param_info(0)->type == PT_FD);
evt->m_tinfo->m_lastevent_fd = *(int64_t *)parinfo->m_val;
evt->m_fdinfo = evt->m_tinfo->get_fd(evt->m_tinfo->m_lastevent_fd);
}

Since the event does not have any parameters and we are trying to access the first one it causes a runtime error.

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

fix(driver): drop EF_USES_FD and EF_MODIFIES_STATE flags for enter events generated by uring syscalls

…scalls

The ENTER events of io_uring_enter and io_uring_register syscalls had the
EF_USES_FD. But since both syscalls return 0 parameters, it causes the the libs
to crash with the following error:
Runtime error: vector::_M_range_check: __n (which is 0) >= this->size() (which is 0). Exiting.
That is because the code tries to access the file descriptor on the event that has the
EF_USES_FD flag.

Signed-off-by: Aldo Lacuku <aldo@lacuku.eu>
@poiana
Copy link
Contributor

poiana commented Jun 14, 2022

Hi @alacuku. Thanks for your PR.

I'm waiting for a falcosecurity member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@Andreagit97
Copy link
Member

Thank you @alacuku!
/ok-to-test

Copy link
Member

@Andreagit97 Andreagit97 left a comment

Choose a reason for hiding this comment

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

/approve

@poiana
Copy link
Contributor

poiana commented Jun 14, 2022

LGTM label has been added.

Git tree hash: 448103615648e28f32b96defd46887a5691f88b7

@poiana
Copy link
Contributor

poiana commented Jun 14, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alacuku, Andreagit97

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Contributor

@FedeDP FedeDP left a comment

Choose a reason for hiding this comment

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

Great catch, thank you!

@FedeDP
Copy link
Contributor

FedeDP commented Jun 14, 2022

/test build-libs-bundled-deps

@poiana poiana merged commit b358896 into falcosecurity:master Jun 14, 2022
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.

4 participants