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): fixed possible buffer overflow in sinsp_plugin::get_metrics #1880

Merged
merged 1 commit into from
May 29, 2024

Conversation

FedeDP
Copy link
Contributor

@FedeDP FedeDP commented May 29, 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:

This PR fixes a possible source of buffer overflow in the recently-added sinsp_plugin::get_metrics API (#1828).

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Output on master:

[ RUN      ] sinsp_with_test_input.plugin_metrics
*** buffer overflow detected ***: terminated
Annullato (core dump creato)

Full trace (courtesy of valgrind massif (?)):

[ RUN      ] sinsp_with_test_input.plugin_metrics
*** buffer overflow detected ***: terminated
==311913== 
==311913== Process terminating with default action of signal 6 (SIGABRT)
==311913==    at 0x5215B1C: __pthread_kill_implementation (pthread_kill.c:44)
==311913==    by 0x5215B1C: __pthread_kill_internal (pthread_kill.c:78)
==311913==    by 0x5215B1C: pthread_kill@@GLIBC_2.34 (pthread_kill.c:89)
==311913==    by 0x51BC26D: raise (raise.c:26)
==311913==    by 0x519F8FE: abort (abort.c:79)
==311913==    by 0x51A07B5: __libc_message_impl.cold (libc_fatal.c:132)
==311913==    by 0x52ADC18: __fortify_fail (fortify_fail.c:24)
==311913==    by 0x52AD5D3: __chk_fail (chk_fail.c:28)
==311913==    by 0x52AF018: __strlcpy_chk (strlcpy_chk.c:28)
==311913==    by 0x7312C2: strlcpy (string_fortified.h:156)
==311913==    by 0x7312C2: sinsp_plugin::get_metrics() const (plugin.cpp:944)
==311913==    by 0x72B1EB: libs::metrics::libs_metrics_collector::snapshot() (metrics_collector.cpp:468)
==311913==    by 0x46F515: sinsp_with_test_input_plugin_metrics_Test::TestBody() (plugins.ut.cpp:909)
==311913==    by 0x8B6DEE: void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (in /home/federico/Work/libs/build/libsinsp/test/unit-test-libsinsp)
==311913==    by 0x89EB15: testing::Test::Run() (in /home/federico/Work/libs/build/libsinsp/test/unit-test-libsinsp)
==311913==    by 0x89ECD4: testing::TestInfo::Run() (in /home/federico/Work/libs/build/libsinsp/test/unit-test-libsinsp)
==311913==    by 0x89EEBE: testing::TestSuite::Run() (in /home/federico/Work/libs/build/libsinsp/test/unit-test-libsinsp)
==311913==    by 0x8ACD2B: testing::internal::UnitTestImpl::RunAllTests() (in /home/federico/Work/libs/build/libsinsp/test/unit-test-libsinsp)
==311913==    by 0x8B74C6: bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) (in /home/federico/Work/libs/build/libsinsp/test/unit-test-libsinsp)
==311913==    by 0x89F0B7: testing::UnitTest::Run() (in /home/federico/Work/libs/build/libsinsp/test/unit-test-libsinsp)
==311913==    by 0x2C0143: main (in /home/federico/Work/libs/build/libsinsp/test/unit-test-libsinsp)
==311913== 
Annullato (core dump creato)

Does this PR introduce a user-facing change?:

fix(userspace/libsinsp): fixed possible buffer overflow in sinsp_plugin::get_metrics

/milestone 0.17.1

…gin::get_metrics`.

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
Copy link
Contributor

@Molter73 Molter73 left a comment

Choose a reason for hiding this comment

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

/lgtm

Nice catch!

@FedeDP
Copy link
Contributor Author

FedeDP commented May 29, 2024

/hold

@FedeDP
Copy link
Contributor Author

FedeDP commented May 29, 2024

/cc @LucaGuerra

@poiana poiana requested a review from LucaGuerra May 29, 2024 10:49
@poiana
Copy link
Contributor

poiana commented May 29, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: FedeDP, LucaGuerra, Molter73

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,LucaGuerra,Molter73]

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

@FedeDP
Copy link
Contributor Author

FedeDP commented May 29, 2024

/unhold

@poiana poiana merged commit 62a6399 into master May 29, 2024
40 checks passed
@poiana poiana deleted the fix/buff_overflow branch May 29, 2024 10:53
@FedeDP FedeDP mentioned this pull request May 29, 2024
This pull request was closed.
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.

4 participants