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

feat(userspace/libsinsp): improve recvmsg SCM_RIGHTS cmsg handling #2262

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ekoops
Copy link
Contributor

@ekoops ekoops commented Jan 29, 2025

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 API-version

/area build

/area CI

/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-savefile

/area libscap

/area libpman

/area libsinsp

/area tests

/area proposals

Does this PR require a change in the driver versions?

/version driver-API-version-major

/version driver-API-version-minor

/version driver-API-version-patch

/version driver-SCHEMA-version-major

/version driver-SCHEMA-version-minor

/version driver-SCHEMA-version-patch

What this PR does / why we need it:

This enhances file descriptor handling in the context of SCM_RIGHTS control message processing for recvmsg events. Specifically:

  • it introduces a new API in libscap for getting single fd info
  • it handles all cmsghdr and all file descriptors contained in SCM_RIGHTS control messages, by selectively call the new API on them, instead of entirely scanning the entire procfs fd directory each time.
  • it replaces readlink + sscanf calls with a single call to stat for retrieving the inode number of a network namespace in scap_fd_scan_fd_dir and scap_fd_get_fdinfo

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

@poiana
Copy link
Contributor

poiana commented Jan 29, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: ekoops
Once this PR has been reviewed and has the lgtm label, please assign lucaguerra for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@ekoops ekoops changed the title feat(userspace/libsinsp): improve recvmsg SCM_RIGHTS cmsg handling feat(userspace/libsinsp): improve recvmsg SCM_RIGHTS cmsg handling Jan 29, 2025
@FedeDP
Copy link
Contributor

FedeDP commented Jan 29, 2025

/milestone 0.21.0

@poiana poiana added this to the 0.21.0 milestone Jan 29, 2025
Copy link

github-actions bot commented Jan 29, 2025

Perf diff from master - unit tests

    10.01%     +0.62%  [.] sinsp_parser::reset
     1.19%     +0.40%  [.] libsinsp::sinsp_suppress::process_event
     1.04%     -0.36%  [.] std::vector<sinsp_evt_param, std::allocator<sinsp_evt_param> >::emplace_back<sinsp_evt*, unsigned int&, char const*, unsigned long&>
     1.70%     -0.36%  [.] sinsp::fetch_next_event
     2.75%     +0.32%  [.] sinsp_thread_manager::find_thread
     2.34%     -0.31%  [.] is_conversion_needed
     0.59%     -0.29%  [.] sinsp_evt::is_filtered_out
     5.22%     +0.27%  [.] next_event_from_file
     2.03%     -0.26%  [.] std::_Hashtable<long, std::pair<long const, std::shared_ptr<sinsp_threadinfo> >, std::allocator<std::pair<long const, std::shared_ptr<sinsp_threadinfo> > >, std::__detail::_Select1st, std::equal_to<long>, std::hash<long>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::_M_find_before_node
     3.02%     -0.24%  [.] sinsp_thread_manager::get_thread_ref

Heap diff from master - unit tests

peak heap memory consumption: 0B
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B

Heap diff from master - scap file

peak heap memory consumption: 0B
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B

Benchmarks diff from master

Comparing gbench_data.json to /root/actions-runner/_work/libs/libs/build/gbench_data.json
Benchmark                                                         Time             CPU      Time Old      Time New       CPU Old       CPU New
----------------------------------------------------------------------------------------------------------------------------------------------
BM_sinsp_split_mean                                            +0.0177         +0.0178           144           146           144           146
BM_sinsp_split_median                                          +0.0188         +0.0189           144           146           144           146
BM_sinsp_split_stddev                                          +0.0293         +0.0276             1             1             1             1
BM_sinsp_split_cv                                              +0.0114         +0.0096             0             0             0             0
BM_sinsp_concatenate_paths_relative_path_mean                  +0.0131         +0.0132            57            58            57            58
BM_sinsp_concatenate_paths_relative_path_median                +0.0057         +0.0058            57            57            57            57
BM_sinsp_concatenate_paths_relative_path_stddev                +1.1598         +1.1599             0             1             0             1
BM_sinsp_concatenate_paths_relative_path_cv                    +1.1320         +1.1319             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_mean                     +0.0058         +0.0059            25            25            25            25
BM_sinsp_concatenate_paths_empty_path_median                   +0.0019         +0.0020            25            25            25            25
BM_sinsp_concatenate_paths_empty_path_stddev                   +0.6378         +0.6390             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_cv                       +0.6283         +0.6294             0             0             0             0
BM_sinsp_concatenate_paths_absolute_path_mean                  +0.1241         +0.1242            57            64            57            64
BM_sinsp_concatenate_paths_absolute_path_median                +0.1197         +0.1198            57            64            57            64
BM_sinsp_concatenate_paths_absolute_path_stddev                +0.4103         +0.4106             0             1             0             1
BM_sinsp_concatenate_paths_absolute_path_cv                    +0.2546         +0.2547             0             0             0             0
BM_sinsp_split_container_image_mean                            -0.0189         -0.0188           392           385           392           385
BM_sinsp_split_container_image_median                          -0.0184         -0.0183           392           385           392           385
BM_sinsp_split_container_image_stddev                          -0.1252         -0.1267             3             2             3             2
BM_sinsp_split_container_image_cv                              -0.1083         -0.1100             0             0             0             0

Copy link

codecov bot commented Jan 29, 2025

Codecov Report

Attention: Patch coverage is 0% with 35 lines in your changes missing coverage. Please review.

Project coverage is 75.29%. Comparing base (3476089) to head (7c9c7e7).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
userspace/libsinsp/parsers.cpp 0.00% 35 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2262      +/-   ##
==========================================
- Coverage   75.34%   75.29%   -0.05%     
==========================================
  Files         279      279              
  Lines       34368    34389      +21     
  Branches     5872     5878       +6     
==========================================
- Hits        25894    25893       -1     
- Misses       8474     8496      +22     
Flag Coverage Δ
libsinsp 75.29% <0.00%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ekoops
Copy link
Contributor Author

ekoops commented Jan 29, 2025

/hold

@ekoops ekoops force-pushed the ekoops/scm-rights-procfs-scan branch 8 times, most recently from 4f9cc6a to db5ffd2 Compare January 31, 2025 14:52
Parse all control messages instead of parsing just the first one.
Leverage the new scap_get_fdinfo API to get info only from the file
in procfs associated to the file descriptor, instead of scanning each
time the entire procfs fd directory.

Signed-off-by: Leonardo Di Giovanna <[email protected]>
Co-authored-by: Roberto Scolaro <[email protected]>
@ekoops ekoops force-pushed the ekoops/scm-rights-procfs-scan branch from db5ffd2 to 7c9c7e7 Compare January 31, 2025 14:57
@ekoops
Copy link
Contributor Author

ekoops commented Feb 3, 2025

/unhold

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

Successfully merging this pull request may close these issues.

3 participants