Skip to content

Commit 815dc2d

Browse files
committed
new(sinsp): support explicit ABI versioning
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]>
1 parent b525d3f commit 815dc2d

16 files changed

Lines changed: 130 additions & 52 deletions

userspace/libsinsp/test/events_plugin.ut.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ static ss_plugin_rc mock_plugin_next_batch(ss_plugin_t* s,
7777

7878
static void set_mock_plugin_api(plugin_api& api) {
7979
memset(&api, 0, sizeof(plugin_api));
80+
api.static_plugin_abi_version = PLUGIN_ABI_VERSION;
81+
api.static_plugin_api_size = sizeof(plugin_api);
8082
api.get_required_api_version = mock_plugin_get_required_api_version;
8183
api.get_version = mock_plugin_get_version;
8284
api.get_description = mock_plugin_get_description;

userspace/libsinsp/test/plugins/metrics.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ ss_plugin_metric* plugin_get_metrics(ss_plugin_t* s, uint32_t* num_metrics) {
112112

113113
void get_plugin_api_sample_metrics(plugin_api& out) {
114114
memset(&out, 0, sizeof(plugin_api));
115+
out.static_plugin_abi_version = PLUGIN_ABI_VERSION;
116+
out.static_plugin_api_size = sizeof(plugin_api);
115117
out.get_required_api_version = plugin_get_required_api_version;
116118
out.get_version = plugin_get_version;
117119
out.get_description = plugin_get_description;

userspace/libsinsp/test/plugins/plugin_extract.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ ss_plugin_rc plugin_set_config(ss_plugin_t* s, const ss_plugin_set_config_input*
157157

158158
void get_plugin_api_sample_plugin_extract(plugin_api& out) {
159159
memset(&out, 0, sizeof(plugin_api));
160+
out.static_plugin_abi_version = PLUGIN_ABI_VERSION;
161+
out.static_plugin_api_size = sizeof(plugin_api);
160162
out.get_required_api_version = plugin_get_required_api_version;
161163
out.get_version = plugin_get_version;
162164
out.get_description = plugin_get_description;

userspace/libsinsp/test/plugins/plugin_source.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ ss_plugin_rc plugin_next_batch(ss_plugin_t* s,
155155

156156
void get_plugin_api_sample_plugin_source(plugin_api& out) {
157157
memset(&out, 0, sizeof(plugin_api));
158+
out.static_plugin_abi_version = PLUGIN_ABI_VERSION;
159+
out.static_plugin_api_size = sizeof(plugin_api);
158160
out.get_required_api_version = plugin_get_required_api_version;
159161
out.get_version = plugin_get_version;
160162
out.get_description = plugin_get_description;

userspace/libsinsp/test/plugins/routines.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ static ss_plugin_rc plugin_capture_close(ss_plugin_t* s, const ss_plugin_capture
140140

141141
void get_plugin_api_sample_routines(plugin_api& out) {
142142
memset(&out, 0, sizeof(plugin_api));
143+
out.static_plugin_abi_version = PLUGIN_ABI_VERSION;
144+
out.static_plugin_api_size = sizeof(plugin_api);
143145
out.get_required_api_version = plugin_get_required_api_version;
144146
out.get_version = plugin_get_version;
145147
out.get_description = plugin_get_description;

userspace/libsinsp/test/plugins/syscall_async.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ ss_plugin_rc plugin_dump_state(ss_plugin_t* s,
229229

230230
void get_plugin_api_sample_syscall_async(plugin_api& out) {
231231
memset(&out, 0, sizeof(plugin_api));
232+
out.static_plugin_abi_version = PLUGIN_ABI_VERSION;
233+
out.static_plugin_api_size = sizeof(plugin_api);
232234
out.get_required_api_version = plugin_get_required_api_version;
233235
out.get_version = plugin_get_version;
234236
out.get_description = plugin_get_description;

userspace/libsinsp/test/plugins/syscall_extract.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ ss_plugin_rc plugin_extract_fields(ss_plugin_t* s,
372372

373373
void get_plugin_api_sample_syscall_extract(plugin_api& out) {
374374
memset(&out, 0, sizeof(plugin_api));
375+
out.static_plugin_abi_version = PLUGIN_ABI_VERSION;
376+
out.static_plugin_api_size = sizeof(plugin_api);
375377
out.get_required_api_version = plugin_get_required_api_version;
376378
out.get_version = plugin_get_version;
377379
out.get_description = plugin_get_description;

userspace/libsinsp/test/plugins/syscall_parse.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ ss_plugin_rc plugin_parse_event(ss_plugin_t* s,
257257

258258
void get_plugin_api_sample_syscall_parse(plugin_api& out) {
259259
memset(&out, 0, sizeof(plugin_api));
260+
out.static_plugin_abi_version = PLUGIN_ABI_VERSION;
261+
out.static_plugin_api_size = sizeof(plugin_api);
260262
out.get_required_api_version = plugin_get_required_api_version;
261263
out.get_version = plugin_get_version;
262264
out.get_description = plugin_get_description;

userspace/libsinsp/test/plugins/syscall_source.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ ss_plugin_rc plugin_next_batch(ss_plugin_t* s,
149149

150150
void get_plugin_api_sample_syscall_source(plugin_api& out) {
151151
memset(&out, 0, sizeof(plugin_api));
152+
out.static_plugin_abi_version = PLUGIN_ABI_VERSION;
153+
out.static_plugin_api_size = sizeof(plugin_api);
152154
out.get_required_api_version = plugin_get_required_api_version;
153155
out.get_version = plugin_get_version;
154156
out.get_description = plugin_get_description;

userspace/libsinsp/test/plugins/syscall_subtables.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ ss_plugin_rc plugin_parse_event(ss_plugin_t* s,
275275

276276
void get_plugin_api_sample_syscall_subtables(plugin_api& out) {
277277
memset(&out, 0, sizeof(plugin_api));
278+
out.static_plugin_abi_version = PLUGIN_ABI_VERSION;
279+
out.static_plugin_api_size = sizeof(plugin_api);
278280
out.get_required_api_version = plugin_get_required_api_version;
279281
out.get_version = plugin_get_version;
280282
out.get_description = plugin_get_description;

0 commit comments

Comments
 (0)