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

filter_lua: fix buffer size calculation(#7304) #7305

Merged
merged 1 commit into from
May 4, 2023

Conversation

nokute78
Copy link
Collaborator

@nokute78 nokute78 commented May 3, 2023

https://github.com/fluent/fluent-bit/blob/v2.1.2/plugins/filter_lua/lua.c#L610
filter_lua passes record_end as a buffer size.
However it is an offset, it means record_end increases per loop.
https://github.com/fluent/fluent-bit/blob/v2.1.2/plugins/filter_lua/lua.c#L493

It will cause SIGSEGV, when record_end becomes huge value.


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.

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

Documentation

  • [N/A] Documentation required for this feature

Backporting

  • [N/A] Backport to latest stable release.

Configuration

Log file

[SERVICE]
    parsers_file parsers.conf

[INPUT]
    name             tail
    parser           docker
    path             test.json
    tag              logs.docker-container
    Read_from_Head   True

[FILTER]
    Name lua
    Match logs.docker-container
    Script a.lua
    Call first
    alias lua.first

[FILTER]
    Name lua
    Match logs.docker-container
    Script a.lua
    Call second
    alias lua.second

[OUTPUT]
    Name stdout
    Match *

parsers.conf:

[PARSER]
    Name         docker
    Format       json
    Time_Key     time
    Time_Format  %Y-%m-%dT%H:%M:%S.%L
    Time_Keep    On

Debug/Valgrind output

e$ valgrind --leak-check=full ~/git/fluent-bit/build/bin/fluent-bit -c a.conf 
==120874== Memcheck, a memory error detector
==120874== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==120874== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==120874== Command: /home/taka/git/fluent-bit/build/bin/fluent-bit -c a.conf
==120874== 
Fluent Bit v2.1.3
* Copyright (C) 2015-2022 The Fluent Bit Authors
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
* https://fluentbit.io

[2023/05/03 11:10:08] [ info] [fluent bit] version=2.1.3, commit=2d71ea9ab0, pid=120874
[2023/05/03 11:10:08] [ info] [storage] ver=1.2.0, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2023/05/03 11:10:08] [ info] [cmetrics] version=0.6.1
[2023/05/03 11:10:08] [ info] [ctraces ] version=0.3.0
[2023/05/03 11:10:08] [ info] [input:tail:tail.0] initializing
[2023/05/03 11:10:08] [ info] [input:tail:tail.0] storage_strategy='memory' (memory only)
[2023/05/03 11:10:08] [ info] [output:stdout:stdout.0] worker #0 started
[2023/05/03 11:10:08] [ info] [sp] stream processor started
[2023/05/03 11:10:09] [ info] [input:tail:tail.0] inotify_fs_add(): inode=3977771 watch_fd=1 name=test.json
(snip)
^C[2023/05/03 11:10:10] [engine] caught signal (SIGINT)
[2023/05/03 11:10:10] [ warn] [engine] service will shutdown in max 5 seconds
[2023/05/03 11:10:10] [ info] [input] pausing tail.0
[2023/05/03 11:10:11] [ info] [engine] service has stopped (0 pending tasks)
[2023/05/03 11:10:11] [ info] [input] pausing tail.0
[2023/05/03 11:10:11] [ info] [input:tail:tail.0] inotify_fs_remove(): inode=3977771 watch_fd=1
[2023/05/03 11:10:11] [ info] [output:stdout:stdout.0] thread worker #0 stopping...
[2023/05/03 11:10:11] [ info] [output:stdout:stdout.0] thread worker #0 stopped
==120874== 
==120874== HEAP SUMMARY:
==120874==     in use at exit: 0 bytes in 0 blocks
==120874==   total heap usage: 7,334 allocs, 7,334 frees, 20,028,263 bytes allocated
==120874== 
==120874== All heap blocks were freed -- no leaks are possible
==120874== 
==120874== For lists of detected and suppressed errors, rerun with: -s
==120874== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

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.

@nokute78 nokute78 temporarily deployed to pr May 3, 2023 02:12 — with GitHub Actions Inactive
@nokute78 nokute78 temporarily deployed to pr May 3, 2023 02:12 — with GitHub Actions Inactive
@nokute78 nokute78 temporarily deployed to pr May 3, 2023 02:12 — with GitHub Actions Inactive
@nokute78 nokute78 temporarily deployed to pr May 3, 2023 02:33 — with GitHub Actions Inactive
Copy link
Collaborator

@leonardo-albertovich leonardo-albertovich left a comment

Choose a reason for hiding this comment

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

I noticed that this record offset tracking was done in a few different plugins at the time and ended up adding record_base and record_length to log_decoder to eliminate the need to manually do this in the plugins with the intention of eliminating this type of issue but I forgot to update this one to use the implicit values.

I'm approving your PR because it's correct and available right now but if you see this and feel like replacing that with the "new" way I'd really appreciate it, otherwise I'll make a note to update it in the future.

Thank you for fixing this issue.

@nokute78 nokute78 temporarily deployed to pr May 3, 2023 22:51 — with GitHub Actions Inactive
@nokute78 nokute78 temporarily deployed to pr May 3, 2023 22:51 — with GitHub Actions Inactive
@nokute78
Copy link
Collaborator Author

nokute78 commented May 3, 2023

@leonardo-albertovich Thank you for comment.
I updated this PR to use new way.

@nokute78 nokute78 temporarily deployed to pr May 3, 2023 22:52 — with GitHub Actions Inactive
@nokute78 nokute78 temporarily deployed to pr May 3, 2023 23:10 — with GitHub Actions Inactive
@leonardo-albertovich leonardo-albertovich merged commit d08533b into fluent:master May 4, 2023
@nokute78 nokute78 deleted the fix_7304 branch May 4, 2023 22:33
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.

2 participants