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(libsinsp): cache invalidation and potential use-after-free in state table api for plugins and sinsp #2266

Merged
merged 3 commits into from
Feb 11, 2025

Conversation

jasondellaluce
Copy link
Contributor

What type of PR is this?

/kind bug

/kind cleanup

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 is a follow up for the issues fixed in #2257. I discovered that due to how thread management works, there may be corner cases where the last cached thread ref or the cached fd tables pointer might become stale, thus potentially causing use after free issues.

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

Copy link

github-actions bot commented Feb 4, 2025

Perf diff from master - unit tests

     0.01%    +18.09%  [.] sinsp_threadinfo::get_main_thread
     0.03%     +8.99%  [.] sinsp_thread_manager::create_thread_dependencies
     0.82%     +7.74%  [.] std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release
    12.93%     -5.19%  [.] sinsp::next
    10.02%     -3.19%  [.] sinsp_parser::reset
     7.48%     -2.34%  [.] sinsp_evt::get_type
     3.02%     -1.39%  [.] sinsp_thread_manager::get_thread_ref
     5.23%     -1.34%  [.] next_event_from_file
     3.64%     -1.23%  [.] gzfile_read
     3.52%     -0.97%  [.] sinsp_evt::load_params

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.0351         +0.0350           144           149           144           149
BM_sinsp_split_median                                          +0.0358         +0.0358           144           149           144           149
BM_sinsp_split_stddev                                          +0.4513         +0.4532             1             1             1             1
BM_sinsp_split_cv                                              +0.4022         +0.4040             0             0             0             0
BM_sinsp_concatenate_paths_relative_path_mean                  +0.0045         +0.0045            57            57            57            57
BM_sinsp_concatenate_paths_relative_path_median                +0.0018         +0.0018            57            57            57            57
BM_sinsp_concatenate_paths_relative_path_stddev                +0.2679         +0.2676             0             0             0             0
BM_sinsp_concatenate_paths_relative_path_cv                    +0.2622         +0.2619             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_mean                     -0.0029         -0.0029            25            25            25            25
BM_sinsp_concatenate_paths_empty_path_median                   -0.0071         -0.0070            25            25            25            25
BM_sinsp_concatenate_paths_empty_path_stddev                   +0.6453         +0.6520             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_cv                       +0.6501         +0.6568             0             0             0             0
BM_sinsp_concatenate_paths_absolute_path_mean                  -0.0443         -0.0442            57            54            57            54
BM_sinsp_concatenate_paths_absolute_path_median                -0.0648         -0.0647            57            53            57            53
BM_sinsp_concatenate_paths_absolute_path_stddev                +2.9832         +2.9847             0             2             0             2
BM_sinsp_concatenate_paths_absolute_path_cv                    +3.1676         +3.1688             0             0             0             0
BM_sinsp_split_container_image_mean                            +0.0013         +0.0014           392           392           392           392
BM_sinsp_split_container_image_median                          -0.0002         -0.0001           392           392           392           392
BM_sinsp_split_container_image_stddev                          -0.3573         -0.3569             3             2             3             2
BM_sinsp_split_container_image_cv                              -0.3581         -0.3578             0             0             0             0

Copy link

codecov bot commented Feb 4, 2025

Codecov Report

Attention: Patch coverage is 82.85714% with 6 lines in your changes missing coverage. Please review.

Project coverage is 75.33%. Comparing base (5a0302c) to head (477f327).
Report is 13 commits behind head on master.

Files with missing lines Patch % Lines
userspace/libsinsp/state/table.cpp 33.33% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2266      +/-   ##
==========================================
- Coverage   75.34%   75.33%   -0.01%     
==========================================
  Files         279      279              
  Lines       34369    34394      +25     
  Branches     5874     5884      +10     
==========================================
+ Hits        25894    25910      +16     
- Misses       8475     8484       +9     
Flag Coverage Δ
libsinsp 75.33% <82.85%> (-0.01%) ⬇️

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.

@FedeDP
Copy link
Contributor

FedeDP commented Feb 4, 2025

/milestone 0.21.0

@poiana poiana added this to the 0.21.0 milestone Feb 4, 2025
FedeDP
FedeDP previously approved these changes Feb 4, 2025
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 Feb 4, 2025

LGTM label has been added.

Git tree hash: 1b899bae799e864197801f5898492291dec5848f

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 poiana added the lgtm label Feb 4, 2025
@poiana
Copy link
Contributor

poiana commented Feb 4, 2025

LGTM label has been added.

Git tree hash: 75c2a0eaf5d331c2e9057df6df080108e10b1de2

@poiana
Copy link
Contributor

poiana commented Feb 4, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: FedeDP, 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,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 fbd198d into master Feb 11, 2025
49 checks passed
@poiana poiana deleted the fix/sinsp-state-table-uaf branch February 11, 2025 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants