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

     8.38%     -0.57%  [.] sinsp_evt::get_type
     4.15%     -0.54%  [.] gzfile_read
     1.55%     +0.46%  [.] next
     5.43%     +0.39%  [.] next_event_from_file
     2.28%     -0.38%  [.] is_conversion_needed
     1.13%     +0.37%  [.] sinsp::fetch_next_event
     1.97%     +0.35%  [.] 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
     0.64%     +0.31%  [.] libsinsp::events::is_unknown_event
     2.17%     -0.28%  [.] std::_Hashtable<unsigned long, std::pair<unsigned long const, std::shared_ptr<ppm_evt_hdr> >, std::allocator<std::pair<unsigned long const, std::shared_ptr<ppm_evt_hdr> > >, std::__detail::_Select1st, std::equal_to<unsigned long>, std::hash<unsigned 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
     1.59%     -0.28%  [.] libsinsp::sinsp_suppress::process_event

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.0102         +0.0102           148           150           148           150
BM_sinsp_split_median                                          +0.0148         +0.0148           148           151           148           151
BM_sinsp_split_stddev                                          -0.0114         -0.0119             1             1             1             1
BM_sinsp_split_cv                                              -0.0214         -0.0219             0             0             0             0
BM_sinsp_concatenate_paths_relative_path_mean                  +0.0823         +0.0823            57            62            57            62
BM_sinsp_concatenate_paths_relative_path_median                +0.0848         +0.0848            57            62            57            62
BM_sinsp_concatenate_paths_relative_path_stddev                -0.7756         -0.7756             1             0             1             0
BM_sinsp_concatenate_paths_relative_path_cv                    -0.7926         -0.7927             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_mean                     -0.0432         -0.0432            25            24            25            24
BM_sinsp_concatenate_paths_empty_path_median                   -0.0426         -0.0426            25            24            25            24
BM_sinsp_concatenate_paths_empty_path_stddev                   -0.6388         -0.6399             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_cv                       -0.6225         -0.6237             0             0             0             0
BM_sinsp_concatenate_paths_absolute_path_mean                  +0.0975         +0.0975            58            64            58            64
BM_sinsp_concatenate_paths_absolute_path_median                +0.0894         +0.0894            58            64            58            64
BM_sinsp_concatenate_paths_absolute_path_stddev                -0.8402         -0.8402             1             0             1             0
BM_sinsp_concatenate_paths_absolute_path_cv                    -0.8544         -0.8544             0             0             0             0
BM_sinsp_split_container_image_mean                            -0.0047         -0.0047           390           388           390           388
BM_sinsp_split_container_image_median                          -0.0023         -0.0023           390           389           390           389
BM_sinsp_split_container_image_stddev                          +0.0530         +0.0534             2             2             2             2
BM_sinsp_split_container_image_cv                              +0.0579         +0.0584             0             0             0             0

Copy link

codecov bot commented Jan 29, 2025

Codecov Report

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

Project coverage is 75.33%. Comparing base (3476089) to head (c7f02ba).

Files with missing lines Patch % Lines
userspace/libsinsp/parsers.cpp 0.00% 20 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2262      +/-   ##
==========================================
- Coverage   75.34%   75.33%   -0.02%     
==========================================
  Files         279      279              
  Lines       34368    34373       +5     
  Branches     5872     5872              
==========================================
  Hits        25894    25894              
- Misses       8474     8479       +5     
Flag Coverage Δ
libsinsp 75.33% <0.00%> (-0.02%) ⬇️

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 4 times, most recently from 05b2b33 to 9183259 Compare January 29, 2025 16:56
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]>
@ekoops ekoops force-pushed the ekoops/scm-rights-procfs-scan branch from 9183259 to c7f02ba Compare January 30, 2025 09:30
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