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

new: scap ppme to sc mapping table #937

Merged
merged 4 commits into from
Mar 8, 2023
Merged

Conversation

FedeDP
Copy link
Contributor

@FedeDP FedeDP commented Mar 2, 2023

What type of PR is this?

/kind cleanup
/kind feature

Any specific area of the project related to this PR?

/area libscap
/area libsinsp

Does this PR require a change in the driver versions?

What this PR does / why we need it:

This PR is extracted from #889 .
It implements:

  • split scap ppm sc API (exposed by scap.h) in scap_platform library, under {linux,win32,osx}/scap_ppm_sc.c source file.
  • In the linux file, a new map[event_code][list of ppm_sc codes that generated that event] was created and it is needed to correctly retrieve all ppm_sc given an event_set.
    Indeed, using the syscall_table to retrieve that information was very error prone because in userspace we only saw syscalls present on that architecture (included by our driver/syscall_compat_$arch.h); moreover there was no way to map OLD_VERSION events.
  • Ported all ppm_sc related scap APIs to use that table (that is linux specific, and scap_ppm_sc.c private).
    This allows us to reliably retrieve all ppm_sc related to an event set (because we are no more iterating over the syscalls_table, but we directly map event -> ppm_sc).

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Most of the changes are in userspace/libscap/linux/scap_ppm_sc.c.
Macos and win32 scap_ppm_sc API impl does nothing.

Tests were cleaned up of now useless ifdef __NR_FOO checks, and <sys/syscall.h> includes.
Added a small test to guarantee that any new PPM_SC is also added to the new scap_ppm_sc.c table.

Other tests present in #889 will be added once all the PRs are in (ie: this one, #936 and the ppm_tp table refactor/merge into ppm_sc)

Does this PR introduce a user-facing change?:

NONE

*
* @return supported true or false.
*/
bool pman_check_support();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

While i was at it, exported this function in the libpman header. Otherwise compilation complained about it.

[PPME_SOCKET_LISTEN_X] = (ppm_sc_code[]){PPM_SC_LISTEN, -1},
[PPME_SOCKET_ACCEPT_E] = (ppm_sc_code[]){PPM_SC_ACCEPT, -1},
[PPME_SOCKET_ACCEPT_X] = (ppm_sc_code[]){PPM_SC_ACCEPT, -1},
[PPME_SOCKET_SEND_E] = NULL, // TODO (ppm_sc_code[]){PPM_SC_SEND, -1},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will be addressed by #936 .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Idea here is:

  • is event actually sent but we still miss the PPM_SC mapping it (tracepoint ppm_sc that will be introduced once we merge the ppm_sc table with the tb table)? Then use PPM_SC_UNKNOWN.
  • else, use NULL

In this case, the event is not actually sent right now.

[PPME_SOCKET_SEND_X] = NULL, // TODO (ppm_sc_code[]){PPM_SC_SEND, -1},
[PPME_SOCKET_SENDTO_E] = (ppm_sc_code[]){PPM_SC_SENDTO, -1},
[PPME_SOCKET_SENDTO_X] = (ppm_sc_code[]){PPM_SC_SENDTO, -1},
[PPME_SOCKET_RECV_E] = NULL, // TODO (ppm_sc_code[]){PPM_SC_RECV, -1},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will be addressed by #936 .

@FedeDP
Copy link
Contributor Author

FedeDP commented Mar 6, 2023

/milestone 0.11.0

@poiana poiana added this to the 0.11.0 milestone Mar 6, 2023
@FedeDP FedeDP force-pushed the new/scap_ppme_to_sc_table branch from 15e13d9 to c054a66 Compare March 6, 2023 09:33
@FedeDP
Copy link
Contributor Author

FedeDP commented Mar 6, 2023

Rebased on top of new master.

Andreagit97
Andreagit97 previously approved these changes Mar 6, 2023
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.

This LGTM thank you for splitting it, now it's very easy and clear! Left just one minor comment
/approve

#endif

#ifdef __NR_writev
//io_sc_set_truth.insert(PPM_SC_PWRITE);
Copy link
Member

Choose a reason for hiding this comment

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

why is this commented? I don't see any PPM_SC_PWRITE between our enums, is it correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep exactly; i don't know what that was indeed :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can clean it up later!

Copy link
Contributor

Choose a reason for hiding this comment

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

🤷‍♀️ I don't remember either and I was probably the one who added it? Plz cleanup and adjust as needed 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cleaned up!

@FedeDP
Copy link
Contributor Author

FedeDP commented Mar 6, 2023

Need to rebase :(

@FedeDP FedeDP force-pushed the new/scap_ppme_to_sc_table branch 2 times, most recently from 8890f72 to d5381c2 Compare March 6, 2023 13:01
Andreagit97
Andreagit97 previously approved these changes Mar 6, 2023
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

Copy link
Contributor

@jasondellaluce jasondellaluce left a comment

Choose a reason for hiding this comment

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

LGTM!

Will wait for @incertum's feedback before approving.

@jasondellaluce
Copy link
Contributor

cc @falcosecurity/libs-maintainers for visibility.

Copy link
Contributor

@incertum incertum left a comment

Choose a reason for hiding this comment

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

Thanks @FedeDP for this, on board!

Re timing let's wait for #936 to be merged first.

Since we are asking for more feedback perhaps we can wait until Wednesday this week before we merge it?

auto generic_ev_set = libsinsp::events::set<ppm_event_code>({PPME_GENERIC_E, PPME_GENERIC_X});
auto generic_sc_set = libsinsp::events::event_set_to_sc_set(generic_ev_set);
auto final_ev_set = libsinsp::events::sc_set_to_event_set(generic_sc_set);
ASSERT_EQ(final_ev_set, generic_ev_set);
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using the new macro we added for consistency ASSERT_PPM_EVENT_CODES_EQ.
Also we can and should do another extension to test coverage and @Andreagit97 already has bunch of more tests lined up 🎉

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe another small test for this PR could be this test for non generic syscalls while also including non syscall events ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done :)

#include "syscall_compat_aarch64.h"
#elif __s390x__
#include "syscall_compat_s390x.h"
#endif /* __x86_64__ */
Copy link
Contributor

Choose a reason for hiding this comment

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

Amazing 😅

#endif

#ifdef __NR_writev
//io_sc_set_truth.insert(PPM_SC_PWRITE);
Copy link
Contributor

Choose a reason for hiding this comment

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

🤷‍♀️ I don't remember either and I was probably the one who added it? Plz cleanup and adjust as needed 🙏

…o map each PPME_EVENT to the PPM_SC that generate it.

Moreover, small improvements to libsinsp::events API.

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
Moreover, cleaned up interesting_syscalls test and added a new events_set test.

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
Copy link
Contributor

@incertum incertum left a comment

Choose a reason for hiding this comment

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

Thanks @FedeDP!

/approve

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 Mar 8, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Andreagit97, FedeDP, incertum

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:
  • OWNERS [Andreagit97,FedeDP,incertum]

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

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.

None yet

5 participants