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

wip: fix(plugin): enforce strict versioning for static plugins #2278

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

Conversation

gnosek
Copy link
Contributor

@gnosek gnosek commented Feb 11, 2025

Statically linked plugins have stricter version requirements, since they rely on the layout of the plugin_api struct. So, when loading a statically linked plugin, we enforce the plugin API to be exactly equal (up to the patch level) to the framework API.

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:

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 Feb 11, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gnosek

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:

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

Copy link

github-actions bot commented Feb 11, 2025

Perf diff from master - unit tests

    18.27%     +0.72%  [.] sinsp_threadinfo::get_main_thread
     3.84%     -0.43%  [.] next_event_from_file
     7.01%     -0.36%  [.] sinsp_parser::reset
     0.85%     +0.36%  [.] libsinsp::sinsp_suppress::process_event
     9.60%     -0.30%  [.] sinsp_thread_manager::create_thread_dependencies
     1.41%     +0.29%  [.] sinsp_parser::process_event
     0.58%     -0.25%  [.] scap_next
     0.85%     -0.24%  [.] sinsp_evt::get_syscall_return_value
     0.74%     +0.23%  [.] sinsp_evt_filter::sinsp_evt_filter
     0.19%     +0.21%  [.] std::_Hashtable<conversion_key, std::pair<conversion_key const, conversion_info>, std::allocator<std::pair<conversion_key const, conversion_info> >, std::__detail::_Select1st, std::equal_to<conversion_key>, std::hash<conversion_key>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true> >::find

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.0059         -0.0059           150           150           150           150
BM_sinsp_split_median                                          +0.0092         +0.0091           151           152           151           152
BM_sinsp_split_stddev                                          +4.1250         +4.1246             1             5             1             5
BM_sinsp_split_cv                                              +4.1555         +4.1551             0             0             0             0
BM_sinsp_concatenate_paths_relative_path_mean                  -0.0095         -0.0095            63            62            63            62
BM_sinsp_concatenate_paths_relative_path_median                -0.0096         -0.0096            63            62            63            62
BM_sinsp_concatenate_paths_relative_path_stddev                +0.1074         +0.1069             1             1             1             1
BM_sinsp_concatenate_paths_relative_path_cv                    +0.1180         +0.1175             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_mean                     +0.0390         +0.0390            24            25            24            25
BM_sinsp_concatenate_paths_empty_path_median                   +0.0341         +0.0341            24            25            24            25
BM_sinsp_concatenate_paths_empty_path_stddev                   +5.3221         +5.3568             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_cv                       +5.0850         +5.1183             0             0             0             0
BM_sinsp_concatenate_paths_absolute_path_mean                  +0.0222         +0.0222            62            64            62            64
BM_sinsp_concatenate_paths_absolute_path_median                +0.0208         +0.0208            62            63            62            63
BM_sinsp_concatenate_paths_absolute_path_stddev                +0.2992         +0.3008             0             0             0             0
BM_sinsp_concatenate_paths_absolute_path_cv                    +0.2710         +0.2725             0             0             0             0
BM_sinsp_split_container_image_mean                            +0.0169         +0.0169           395           401           395           401
BM_sinsp_split_container_image_median                          +0.0141         +0.0141           396           401           396           401
BM_sinsp_split_container_image_stddev                          -0.3300         -0.3303             4             3             4             3
BM_sinsp_split_container_image_cv                              -0.3411         -0.3414             0             0             0             0

Copy link

codecov bot commented Feb 11, 2025

Codecov Report

Attention: Patch coverage is 92.30769% with 2 lines in your changes missing coverage. Please review.

Project coverage is 75.34%. Comparing base (0d94d2b) to head (a69bd1f).

Files with missing lines Patch % Lines
userspace/libsinsp/test/plugins/routines.cpp 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2278      +/-   ##
==========================================
+ Coverage   75.32%   75.34%   +0.01%     
==========================================
  Files         280      280              
  Lines       34556    34582      +26     
  Branches     5902     5902              
==========================================
+ Hits        26031    26055      +24     
- Misses       8525     8527       +2     
Flag Coverage Δ
libsinsp 75.34% <92.30%> (+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.

@leogr
Copy link
Member

leogr commented Feb 11, 2025

/milestone 0.21.0

@poiana poiana added this to the 0.21.0 milestone Feb 11, 2025
@gnosek gnosek force-pushed the static-plugin-api-compat branch 2 times, most recently from 478bf4b to 6cfa7ba Compare February 17, 2025 15:22
@poiana poiana added size/XL and removed size/M labels Feb 17, 2025
@gnosek gnosek force-pushed the static-plugin-api-compat branch from 6cfa7ba to c0f346b Compare February 17, 2025 15:29
API 3.10 changed the layout of the plugin_api struct
in an ABI-incompatible way. This does not matter for shared library
plugins, but statically linked plugins do depend on binary compatibility
between the two structs.

Signed-off-by: Grzegorz Nosek <[email protected]>
`extract_plugin_abi.py` parses the output from pahole describing
the `plugin_api` struct (with the offsets and sizes of all fields)
and generates a `plugin_abi.h` header with static asserts to ensure
the ABI is up to date (on x86_64/Linux).

`diff_plugin_abi.py` takes two copies of the generated plugin_abi.h
files (presumably, one from the repo and a freshly generated one)
and raises an error if:
 * a struct member has been moved/removed without ABI version bump
 * the ABI version has been increased without breaking changes

Note: adding a field at the end of the plugin_api struct does not
count as a breaking change.

Signed-off-by: Grzegorz Nosek <[email protected]>
The current ABI is arbitrarily chosen as v3 (to match the major API
version).

Note: when making incompatible ABI changes, this file will prevent
the build from succeeding. When you're making ABI changes on purpose,
the easiest way is to remove everything but the ABI version `#define`
from plugin_abi.h and once everything builds, regenerate plugin_abi.h

(see tools/plugin_abi/extract_plugin_abi.py)

Signed-off-by: Grzegorz Nosek <[email protected]>
@gnosek gnosek force-pushed the static-plugin-api-compat branch from c0f346b to dc3a941 Compare February 17, 2025 16:20
Introduce an explicit ABI version field to plugin_api, as well as
a size field. This allows us to explicitly detect incompatible
ABIs, but also to detect struct changes within an ABI version.

The size field is actually pretty important (maybe more than
the actual version field, as long as get_api_version can be easily
found), because it's the only way to know how big the plugin-provided
struct actually is. With plugins targeting older API versions,
we're doing a basically guaranteed out of bounds read otherwise
(if the plugin_api struct in the framework is larger than what
the plugin exports).

Signed-off-by: Grzegorz Nosek <[email protected]>
@gnosek gnosek force-pushed the static-plugin-api-compat branch from dc3a941 to 815dc2d Compare February 17, 2025 16:25
@FedeDP
Copy link
Contributor

FedeDP commented Feb 18, 2025

Format code / format code 🐲 (pull_request) Failing after 30s

You should add userspace/plugin/plugin_abi.h to clang-format-ignore since it is autogenerated.

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.

4 participants