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

refactor(userspace/libsinsp)!: file descriptor tables for better OOP design and extensibility #1637

Merged
merged 2 commits into from
Jan 23, 2024

Conversation

jasondellaluce
Copy link
Contributor

What type of PR is this?

/kind cleanup

/kind design

Any specific area of the project related to this PR?

/area libsinsp

Does this PR require a change in the driver versions?

What this PR does / why we need it:

This PR attempts refactoring the data structures related to file descriptor tables on the following points:

  • Most methods on fd infos could be const or inlined by currently aren't. Furthermore, some methods are currently unused and are now cleaned up
  • The sinsp_fdinfo class has fields and methods definitions mixed with no clarity about their order and visibility (what's public and what's not?). The class has been cleanup up with reasonable ordering
  • sinsp_fdinfo is currently a template for no good reason, if not the possibility of extending the class with a "sidecar" delegated object. This suboptimal for type safety and pollutes our headers for very little value, whereas the same can simply be attained through inheritance following well-known OOP principles. This also caused defining the type twice (as sinsp_fdinfo_t too), of which unification led to most of the LOC changes of this PR
  • The file descriptor tables are currently accessed in their internals from many parts, mostly just with the purpose of looping through their elements, even though we have functional accessors for that. We now uniform that for accessing fds only through loop API
  • File descriptor infos are allocated by value instead that by pointer (e.g. which we instead do for thread infos), effectively preventing practitioners and non-falco clients from extending the fd infos, and making allocation a bit puzzling in certain situations. For example, shifting to a pointer-based allocation uncovered a subtle issue in caching fd table queries but that used to work "by mistake"
  • Unlike thread infos, there was no factory method for building thread infos, and allocation of new ones was scattered in many points. This is a first step that will allow exposing those tables in the state API accessible by plugins in the future
  • Fd infos have been passed as raw pointers without no criteria about who's the memory owner. For example, the simple add_fd path drove me crazy in some paths understanding who owned memory. I've now switched to unique pointers wherever possible. More will come later, but this is a starter.

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

refactor(userspace/libsinsp)!: file descriptor tables for better OOP design and extensibility

Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
…apis

Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
@FedeDP
Copy link
Contributor

FedeDP commented Jan 23, 2024

/milestone 0.15.0

@poiana poiana added this to the 0.15.0 milestone Jan 23, 2024
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.

/approve

@poiana
Copy link
Contributor

poiana commented Jan 23, 2024

LGTM label has been added.

Git tree hash: 000ed22edf971fe94b811bc409ec385812882a10

@poiana
Copy link
Contributor

poiana commented Jan 23, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: FedeDP, gnosek, jasondellaluce

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 [FedeDP,gnosek,jasondellaluce]

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

@poiana poiana merged commit 8b05ac9 into master Jan 23, 2024
31 checks passed
@poiana poiana deleted the refactor/file-descriptors-mgmt branch January 23, 2024 15:10
FedeDP added a commit that referenced this pull request Mar 15, 2024
Basically, `scap_get_fdlist()` called in the sinsp parsers loop to manage SCM_RIGHTS flag for recvmsg,
updates the pointers in the thread fdtable.
After #1637, doing so invalidates `event` m_fdinfo field, that is a pointer to a now freed data.

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
FedeDP added a commit that referenced this pull request Mar 19, 2024
Basically, `scap_get_fdlist()` called in the sinsp parsers loop to manage SCM_RIGHTS flag for recvmsg,
updates the pointers in the thread fdtable.
After #1637, doing so invalidates `event` m_fdinfo field, that is a pointer to a now freed data.

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
poiana pushed a commit that referenced this pull request Mar 19, 2024
Basically, `scap_get_fdlist()` called in the sinsp parsers loop to manage SCM_RIGHTS flag for recvmsg,
updates the pointers in the thread fdtable.
After #1637, doing so invalidates `event` m_fdinfo field, that is a pointer to a now freed data.

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
FedeDP added a commit that referenced this pull request Mar 19, 2024
Basically, `scap_get_fdlist()` called in the sinsp parsers loop to manage SCM_RIGHTS flag for recvmsg,
updates the pointers in the thread fdtable.
After #1637, doing so invalidates `event` m_fdinfo field, that is a pointer to a now freed data.

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
poiana pushed a commit that referenced this pull request Mar 22, 2024
Basically, `scap_get_fdlist()` called in the sinsp parsers loop to manage SCM_RIGHTS flag for recvmsg,
updates the pointers in the thread fdtable.
After #1637, doing so invalidates `event` m_fdinfo field, that is a pointer to a now freed data.

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
mrgian pushed a commit to mrgian/libs that referenced this pull request Mar 22, 2024
Basically, `scap_get_fdlist()` called in the sinsp parsers loop to manage SCM_RIGHTS flag for recvmsg,
updates the pointers in the thread fdtable.
After falcosecurity#1637, doing so invalidates `event` m_fdinfo field, that is a pointer to a now freed data.

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
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