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(userspace/libsinsp): avoid possible UB when calling back or front without checking string emptiness #2088

Merged
merged 1 commit into from
Sep 30, 2024

Conversation

FedeDP
Copy link
Contributor

@FedeDP FedeDP commented Sep 30, 2024

What type of PR is this?

/kind bug

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:

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

@FedeDP
Copy link
Contributor Author

FedeDP commented Sep 30, 2024

This UB was spotted by Falco zig CI: https://github.com/falcosecurity/falco/actions/runs/11106489185?pr=3307
/cc @LucaGuerra @jasondellaluce

/milestone 0.19.0

@poiana poiana added this to the 0.19.0 milestone Sep 30, 2024
LucaGuerra
LucaGuerra previously approved these changes Sep 30, 2024
Copy link
Contributor

@LucaGuerra LucaGuerra left a comment

Choose a reason for hiding this comment

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

Thank you!

@@ -2384,7 +2384,7 @@ std::string sinsp_parser::parse_dirfd(sinsp_evt *evt, std::string_view name, int
return "<UNKNOWN>";
}

if(fdinfo->m_name.back() == '/') {
if(!fdinfo->m_name.empty() && fdinfo->m_name.back() == '/') {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In both fixes, if m_name is empty i return "/"; perhaps it is better to just return the empty string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Decided together with @jasondellaluce to just return an empty string in these cases.

@FedeDP
Copy link
Contributor Author

FedeDP commented Sep 30, 2024

/hold
per #2088 (comment)

Copy link

github-actions bot commented Sep 30, 2024

Perf diff from master - unit tests

    12.03%     -2.69%  [.] sinsp_parser::reset
     5.77%     -1.25%  [.] next
     2.50%     +0.55%  [.] sinsp_thread_manager::find_thread
     1.82%     -0.54%  [.] std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release
     1.14%     -0.53%  [.] std::vector<sinsp_evt_param, std::allocator<sinsp_evt_param> >::emplace_back<sinsp_evt*, unsigned int&, char const*, unsigned long&>
     0.62%     +0.52%  [.] scap_event_encode_params_v
     0.78%     -0.49%  [.] sinsp_fdtable::sinsp_fdtable
     0.78%     -0.49%  [.] libsinsp::runc::match_container_id
     0.55%     +0.47%  [.] sinsp_utils::find_longest_matching_evt_param
     7.07%     +0.45%  [.] sinsp::next

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.0627         +0.0627           144           153           144           153
BM_sinsp_split_median                                          +0.0737         +0.0737           143           153           143           153
BM_sinsp_split_stddev                                          -0.5464         -0.5462             3             1             3             1
BM_sinsp_split_cv                                              -0.5731         -0.5730             0             0             0             0
BM_sinsp_concatenate_paths_relative_path_mean                  +0.0853         +0.0853            56            61            56            61
BM_sinsp_concatenate_paths_relative_path_median                +0.0887         +0.0888            56            61            56            61
BM_sinsp_concatenate_paths_relative_path_stddev                +0.4784         +0.4787             0             0             0             0
BM_sinsp_concatenate_paths_relative_path_cv                    +0.3622         +0.3624             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_mean                     +0.0566         +0.0566            23            25            23            25
BM_sinsp_concatenate_paths_empty_path_median                   +0.0527         +0.0527            23            25            23            25
BM_sinsp_concatenate_paths_empty_path_stddev                   +3.2203         +3.2248             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_cv                       +2.9941         +2.9984             0             0             0             0
BM_sinsp_concatenate_paths_absolute_path_mean                  +0.1270         +0.1269            56            63            56            63
BM_sinsp_concatenate_paths_absolute_path_median                +0.1297         +0.1297            55            63            55            63
BM_sinsp_concatenate_paths_absolute_path_stddev                +2.2972         +2.2966             0             1             0             1
BM_sinsp_concatenate_paths_absolute_path_cv                    +1.9257         +1.9252             0             0             0             0
BM_sinsp_split_container_image_mean                            +0.0101         +0.0100           392           396           392           396
BM_sinsp_split_container_image_median                          +0.0059         +0.0059           392           395           392           395
BM_sinsp_split_container_image_stddev                          +0.9591         +0.9563             2             4             2             4
BM_sinsp_split_container_image_cv                              +0.9396         +0.9368             0             0             0             0

…ont` without checking string emptiness.

Signed-off-by: Federico Di Pierro <[email protected]>
@FedeDP FedeDP force-pushed the fix/check_string_emptiness_before_front_back branch from bef6c42 to 8a0b548 Compare September 30, 2024 15:42
@FedeDP
Copy link
Contributor Author

FedeDP commented Sep 30, 2024

/unhold

Copy link

codecov bot commented Sep 30, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 73.58%. Comparing base (8baec4b) to head (8a0b548).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
userspace/libsinsp/sinsp_filtercheck_fdlist.cpp 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2088      +/-   ##
==========================================
- Coverage   73.58%   73.58%   -0.01%     
==========================================
  Files         253      253              
  Lines       31869    31869              
  Branches     5650     5644       -6     
==========================================
- Hits        23452    23451       -1     
+ Misses       8408     8393      -15     
- Partials        9       25      +16     
Flag Coverage Δ
libsinsp 73.58% <66.66%> (-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.

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.

/approve

@poiana
Copy link
Contributor

poiana commented Sep 30, 2024

[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 aeb8793 into master Sep 30, 2024
48 of 49 checks passed
@poiana poiana deleted the fix/check_string_emptiness_before_front_back branch September 30, 2024 16:15
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.

5 participants