Skip to content

fix(libsinsp): generalize big-endian handling beyond s390x#3003

Open
Scottcjn wants to merge 2 commits into
falcosecurity:masterfrom
Scottcjn:fix/bigendian-beyond-s390x
Open

fix(libsinsp): generalize big-endian handling beyond s390x#3003
Scottcjn wants to merge 2 commits into
falcosecurity:masterfrom
Scottcjn:fix/bigendian-beyond-s390x

Conversation

@Scottcjn
Copy link
Copy Markdown

What type of PR is this?

/kind bug

Any specific area of the project related to this PR?

/area libsinsp

What this PR does / why we need it:

While looking at #3002 (big-endian PowerPC), the userspace side still treats s390x as a synonym for "big-endian":

  • flt_cast() in filter_compare.cpp applies a byte-shift adjustment for evt.rawarg.* fields when len > sizeof(fromT) on big-endian systems — but it was compiled only under #ifdef __s390x__. On any other big-endian target (e.g. big-endian PowerPC) that adjustment is silently dropped and evt.rawarg.* comparisons read the wrong bytes. The guard now keys on endianness (#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) instead of a specific arch. The defined(__BYTE_ORDER__) part keeps the Windows/MSVC build path correct (the macro is absent there, and a bare #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ would wrongly evaluate true). The executable block body is unchanged — only the guard and comment.

  • The scap-file test suite in userspace/libsinsp/test/CMakeLists.txt was disabled by matching the s390x processor string; it now keys off CMAKE_CXX_BYTE_ORDER so every big-endian host is covered.

This mirrors how the repo already detects endianness elsewhere (__BYTE_ORDER__ in parse_connect.cpp, ifinfo.ut.cpp). The kernel-driver / modern-BPF side of #3002 is larger and out of scope here.

Which issue(s) this PR fixes:

Refs #3002

Special notes for your reviewer:

Verified: the new guard compiles inactive on x86_64 (little-endian, no perf hit) and active on s390x — cross-compiled and run under qemu-s390x. The flt_cast block body is byte-identical to the previous __s390x__-gated code, so big-endian compile coverage is inherited from the existing s390x build.

Does this PR introduce a user-facing change?:

fix(libsinsp): apply the big-endian `evt.rawarg.*` byte adjustment on all big-endian targets, not only s390x

🤖 Generated with Claude Code

flt_cast()'s byte-shift adjustment for `evt.rawarg.*` fields, applied
on big-endian systems when len > sizeof(fromT), was compiled only
under `#ifdef __s390x__`. s390x is not the only big-endian target --
big-endian PowerPC hits the same edge case -- so the guard now keys on
endianness (`__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__`) instead of a
specific arch. The `defined(__BYTE_ORDER__)` part keeps the MSVC build
path (where the macro is absent) correct. The block body is unchanged.

The scap-file test suite was likewise disabled by matching the s390x
processor string; it now keys off CMAKE_CXX_BYTE_ORDER so every
big-endian host is covered.

Refs falcosecurity#3002

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Scott Boudreaux <scott@elyanlabs.com>
@poiana
Copy link
Copy Markdown
Contributor

poiana commented May 20, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Scottcjn
Once this PR has been reviewed and has the lgtm label, please assign andreagit97 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details 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

@poiana
Copy link
Copy Markdown
Contributor

poiana commented May 20, 2026

Welcome @Scottcjn! It looks like this is your first PR to falcosecurity/libs 🎉

@poiana poiana added the size/S label May 20, 2026
@github-actions
Copy link
Copy Markdown

Perf diff from master - unit tests

    16.49%     -4.86%  [.] std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_add_ref_lock_nothrow()
    16.87%     +3.65%  [.] std::__shared_ptr<sinsp_threadinfo, (__gnu_cxx::_Lock_policy)2>::__shared_ptr(std::__weak_ptr<sinsp_threadinfo, (__gnu_cxx::_Lock_policy)2> const&, std::nothrow_t)
    17.65%     -3.29%  [.] sinsp_threadinfo::get_main_thread()
     9.70%     +3.03%  [.] sinsp_thread_manager::create_thread_dependencies(std::shared_ptr<sinsp_threadinfo> const&)
     6.43%     +1.61%  [.] std::__shared_count<(__gnu_cxx::_Lock_policy)2>::_M_get_use_count() const
     6.97%     -0.86%  [.] std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count(std::__weak_count<(__gnu_cxx::_Lock_policy)2> const&, std::nothrow_t)
     3.27%     +0.71%  [.] sinsp_threadinfo::get_fd_table()
     5.06%     +0.12%  [.] thread_group_info::get_first_thread() const
     0.13%     -0.11%  [.] strlen@plt
     0.16%     -0.09%  [.] sinsp::next(sinsp_evt**)

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.0408         +0.0408           271           282           271           282
BM_sinsp_split_median                                                                +0.0422         +0.0424           270           281           270           281
BM_sinsp_split_stddev                                                                +0.1372         +0.1411             3             4             3             4
BM_sinsp_split_cv                                                                    +0.0927         +0.0964             0             0             0             0
BM_sinsp_concatenate_paths_relative_path_mean                                        +0.0349         +0.0349            79            81            79            81
BM_sinsp_concatenate_paths_relative_path_median                                      +0.0288         +0.0289            79            81            79            81
BM_sinsp_concatenate_paths_relative_path_stddev                                      +6.5545         +6.6172             0             3             0             3
BM_sinsp_concatenate_paths_relative_path_cv                                          +6.3000         +6.3600             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_mean                                           +0.0966         +0.0965            45            49            45            49
BM_sinsp_concatenate_paths_empty_path_median                                         +0.0991         +0.0992            45            49            45            49
BM_sinsp_concatenate_paths_empty_path_stddev                                        +18.9195        +20.7584             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_cv                                            +17.1655        +18.8431             0             0             0             0
BM_sinsp_concatenate_paths_absolute_path_mean                                        +0.0621         +0.0621            78            83            78            83
BM_sinsp_concatenate_paths_absolute_path_median                                      +0.0659         +0.0659            78            83            77            83
BM_sinsp_concatenate_paths_absolute_path_stddev                                      -0.5590         -0.5523             1             0             1             0
BM_sinsp_concatenate_paths_absolute_path_cv                                          -0.5848         -0.5785             0             0             0             0
BM_sinsp_sanitize_string_fast_path_ascii_short_mean                                  +0.0032         +0.0033            19            19            19            19
BM_sinsp_sanitize_string_fast_path_ascii_short_median                                +0.0011         +0.0010            19            19            19            19
BM_sinsp_sanitize_string_fast_path_ascii_short_stddev                                -0.9541         -0.9564             0             0             0             0
BM_sinsp_sanitize_string_fast_path_ascii_short_cv                                    -0.9542         -0.9565             0             0             0             0
BM_sinsp_sanitize_string_fast_path_ascii_long_mean                                   +0.0034         +0.0036           165           165           165           165
BM_sinsp_sanitize_string_fast_path_ascii_long_median                                 +0.0034         +0.0036           165           165           165           165
BM_sinsp_sanitize_string_fast_path_ascii_long_stddev                                 -0.2986         -0.0756             0             0             0             0
BM_sinsp_sanitize_string_fast_path_ascii_long_cv                                     -0.3010         -0.0789             0             0             0             0
BM_sinsp_sanitize_string_fast_path_multibyte_short_mean                              +0.0232         +0.0233            14            14            14            14
BM_sinsp_sanitize_string_fast_path_multibyte_short_median                            +0.0002         +0.0002            14            14            14            14
BM_sinsp_sanitize_string_fast_path_multibyte_short_stddev                            +0.9801         +0.9774             0             1             0             1
BM_sinsp_sanitize_string_fast_path_multibyte_short_cv                                +0.9352         +0.9324             0             0             0             0
BM_sinsp_sanitize_string_fast_path_multibyte_long_mean                               -0.0180         -0.0180          4954          4865          4952          4863
BM_sinsp_sanitize_string_fast_path_multibyte_long_median                             -0.0144         -0.0143          4935          4864          4933          4863
BM_sinsp_sanitize_string_fast_path_multibyte_long_stddev                             -0.9599         -0.9632            36             1            36             1
BM_sinsp_sanitize_string_fast_path_multibyte_long_cv                                 -0.9592         -0.9625             0             0             0             0
BM_sinsp_sanitize_string_fast_path_mixed_long_mean                                   -0.1511         -0.1511          2341          1988          2340          1987
BM_sinsp_sanitize_string_fast_path_mixed_long_median                                 -0.1488         -0.1487          2335          1987          2334          1987
BM_sinsp_sanitize_string_fast_path_mixed_long_stddev                                 -0.9549         -0.9557            18             1            18             1
BM_sinsp_sanitize_string_fast_path_mixed_long_cv                                     -0.9469         -0.9479             0             0             0             0
BM_sinsp_sanitize_string_slow_path_c1_controls_long_alloc_mean                       +0.0386         +0.0386          5941          6170          5939          6168
BM_sinsp_sanitize_string_slow_path_c1_controls_long_alloc_median                     +0.0009         +0.0009          6136          6142          6135          6140
BM_sinsp_sanitize_string_slow_path_c1_controls_long_alloc_stddev                     -0.8217         -0.8215           285            51           285            51
BM_sinsp_sanitize_string_slow_path_c1_controls_long_alloc_cv                         -0.8283         -0.8281             0             0             0             0
BM_sinsp_sanitize_string_slow_path_c1_controls_long_noalloc_mean                     +0.0002         +0.0003          6019          6021          6017          6019
BM_sinsp_sanitize_string_slow_path_c1_controls_long_noalloc_median                   +0.0003         +0.0003          6019          6020          6017          6018
BM_sinsp_sanitize_string_slow_path_c1_controls_long_noalloc_stddev                   +0.0740         +0.4924             2             2             1             2
BM_sinsp_sanitize_string_slow_path_c1_controls_long_noalloc_cv                       +0.0737         +0.4920             0             0             0             0
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_alloc_mean                    -0.0070         -0.0070           328           325           328           325
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_alloc_median                  -0.0088         -0.0089           327           325           327           324
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_alloc_stddev                  +0.5036         +0.5005             2             2             2             2
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_alloc_cv                      +0.5142         +0.5111             0             0             0             0
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_noalloc_mean                  -0.0022         -0.0022           220           220           220           220
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_noalloc_median                -0.0017         -0.0019           220           220           220           220
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_noalloc_stddev                -0.2840         -0.2845             1             1             1             1
BM_sinsp_sanitize_string_slow_path_sparse_invalid_long_noalloc_cv                    -0.2824         -0.2829             0             0             0             0
BM_sinsp_sanitize_string_slow_path_all_invalid_long_alloc_mean                       -0.0067         -0.0067         12455         12372         12451         12367
BM_sinsp_sanitize_string_slow_path_all_invalid_long_alloc_median                     +0.0001         +0.0002         12454         12455         12450         12453
BM_sinsp_sanitize_string_slow_path_all_invalid_long_alloc_stddev                    +51.1686        +55.8847             6           327             6           328
BM_sinsp_sanitize_string_slow_path_all_invalid_long_alloc_cv                        +51.5206        +56.2704             0             0             0             0
BM_sinsp_sanitize_string_slow_path_all_invalid_long_noalloc_mean                     +0.0006         +0.0005         12244         12252         12240         12247
BM_sinsp_sanitize_string_slow_path_all_invalid_long_noalloc_median                   +0.0002         -0.0001         12243         12245         12239         12238
BM_sinsp_sanitize_string_slow_path_all_invalid_long_noalloc_stddev                   +1.9905         +2.5921             5            15             4            15
BM_sinsp_sanitize_string_slow_path_all_invalid_long_noalloc_cv                       +1.9887         +2.5902             0             0             0             0

@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.76%. Comparing base (b1e3a8b) to head (94b4ec5).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3003   +/-   ##
=======================================
  Coverage   75.76%   75.76%           
=======================================
  Files         299      299           
  Lines       33099    33099           
  Branches     5126     5126           
=======================================
  Hits        25079    25079           
  Misses       8020     8020           
Flag Coverage Δ
libsinsp 75.76% <ø> (ø)

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@terror96
Copy link
Copy Markdown
Contributor

Hi @Scottcjn, thanks for the contribution. It seems that you need to address a minor formatting issue...

Re-wrap a comment to the repo cmake-format config so the format-code
pre-commit check passes.

Signed-off-by: Scott Boudreaux <scott@elyanlabs.com>
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