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

tests/internal: fix use-after-free for input_chunks test input_chunk_dropping_chunks. #9472

Merged

Conversation

pwhelan
Copy link
Contributor

@pwhelan pwhelan commented Oct 8, 2024

Summary

There is a use-after-free bug in the internal test input_chunks, specifically in the sub-test input_chunk_dropping_chunks. This is caused by a premature and explicit freeing of all the chunks and explicit stopping of all the tasks by the test. This is done implicitly by either flb_stop or flb_destroy.

This PR simply eliminates this code to fix this potential use-after-free or double-free. This should make this test less flakey on macOS, as well as other operating systems.


Enter [N/A] in the box, if an item is not applicable to your change.

Testing
Before we can approve your change; please submit the following in a comment:

  • Example configuration file for the change
  • Debug log output from testing the change
  • Attached Valgrind output that shows no leaks or memory corruption was found

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

  • Run local packaging test showing all targets (including any new ones) build.
  • Set ok-package-test label to test for all targets (requires maintainer to do).

Documentation

  • Documentation required for this feature

Backporting

  • Backport to latest stable release.

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

@pwhelan
Copy link
Contributor Author

pwhelan commented Oct 8, 2024

The only reasoning for this code would be to avoid a memory leak during the test which could cause it to fail with SANITIZE_ADDRESS=On. I therefore tested it with valgrind:

$ valgrind ./bin/flb-it-input_chunk input_chunk_dropping_chunks
==26247== Memcheck, a memory error detector
==26247== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==26247== Using Valgrind-3.23.0 and LibVEX; rerun with -h for copyright info
==26247== Command: ./bin/flb-it-input_chunk input_chunk_dropping_chunks
==26247==
Test input_chunk_dropping_chunks...             [2024/10/08 11:26:50] [error] [input chunk] fail to drop enough chunks in order to place new data coming from input plugin lib.0
[2024/10/08 11:26:50] [error] [output:http:http.0] no upstream connections available to 127.0.0.1:1
[2024/10/08 11:26:52] [error] [input chunk] fail to drop enough chunks in order to place new data coming from input plugin lib.0
[2024/10/08 11:26:52] [error] [output:http:http.0] no upstream connections available to 127.0.0.1:1
[2024/10/08 11:26:54] [error] [input chunk] fail to drop enough chunks in order to place new data coming from input plugin lib.0
[2024/10/08 11:26:54] [error] [output:http:http.0] no upstream connections available to 127.0.0.1:1
[2024/10/08 11:26:56] [error] [input chunk] fail to drop enough chunks in order to place new data coming from input plugin lib.0
[2024/10/08 11:26:56] [error] [output:http:http.0] no upstream connections available to 127.0.0.1:1
[2024/10/08 11:26:58] [error] [input chunk] fail to drop enough chunks in order to place new data coming from input plugin lib.0
[2024/10/08 11:26:58] [error] [output:http:http.0] no upstream connections available to 127.0.0.1:1
[2024/10/08 11:27:01] [error] [output:http:http.0] no upstream connections available to 127.0.0.1:1
[2024/10/08 11:27:01] [error] [engine] chunk '26247-1728397617.365742741.flb' cannot be retried: task_id=0, input=lib.0 > output=http.0
[ OK ]
==26247== Warning: invalid file descriptor -1 in syscall close()
SUCCESS: All unit tests have passed.
==26247==
==26247== HEAP SUMMARY:
==26247==     in use at exit: 0 bytes in 0 blocks
==26247==   total heap usage: 4,051 allocs, 4,051 frees, 1,957,249 bytes allocated
==26247==
==26247== All heap blocks were freed -- no leaks are possible
==26247==
==26247== For lists of detected and suppressed errors, rerun with: -s
==26247== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

@edsiper edsiper merged commit 8088400 into master Oct 10, 2024
43 of 45 checks passed
@edsiper edsiper deleted the pwhelan-fix-internal-test-input-chunks-use-after-free branch October 10, 2024 23:34
@edsiper edsiper added this to the Fluent Bit v3.2.0 milestone Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants