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(tsi): close series id iterator after merging #19936

Merged
merged 2 commits into from
Feb 10, 2021

Conversation

foobar
Copy link
Contributor

@foobar foobar commented Nov 9, 2020

This use-after-free bug may lead to segfault. The iterators that have
reference to the underlying index files were closed too early while
the bitmaps were still used afterwards. If a compaction occurs
concurrently and removes the index files, it would result in accessing
unmap'd memory address.

@foobar foobar force-pushed the fix-use-after-free branch 2 times, most recently from 96465f4 to 9ae2bbe Compare November 11, 2020 06:19
@foobar foobar force-pushed the fix-use-after-free branch from 9ae2bbe to 0be081b Compare January 25, 2021 07:11
@foobar
Copy link
Contributor Author

foobar commented Feb 9, 2021

@danxmoran can you review this PR ?

@foobar foobar force-pushed the fix-use-after-free branch from 0be081b to 38861cf Compare February 9, 2021 07:04
@danxmoran danxmoran self-requested a review February 9, 2021 15:03
@@ -557,9 +557,10 @@ func IntersectSeriesIDIterators(itr0, itr1 SeriesIDIterator) SeriesIDIterator {

// Create series id set, if available.
if a := NewSeriesIDSetIterators([]SeriesIDIterator{itr0, itr1}); a != nil {
ss := a[0].SeriesIDSet().And(a[1].SeriesIDSet())
Copy link
Contributor

Choose a reason for hiding this comment

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

Does a[0] == itr0 and a[1] == itr1 here? If so, could we add a comment saying so? I think it'll make it more obvious why the Close() calls have to happen after this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i added comments. please check if it matches your suggestion.

@@ -646,10 +647,10 @@ func UnionSeriesIDIterators(itr0, itr1 SeriesIDIterator) SeriesIDIterator {

// Create series id set, if available.
if a := NewSeriesIDSetIterators([]SeriesIDIterator{itr0, itr1}); a != nil {
itr0.Close()
itr1.Close()
ss := NewSeriesIDSet()
ss.Merge(a[0].SeriesIDSet(), a[1].SeriesIDSet())
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment / request as above

@@ -733,9 +734,10 @@ func DifferenceSeriesIDIterators(itr0, itr1 SeriesIDIterator) SeriesIDIterator {

// Create series id set, if available.
if a := NewSeriesIDSetIterators([]SeriesIDIterator{itr0, itr1}); a != nil {
ss := a[0].SeriesIDSet().AndNot(a[1].SeriesIDSet())
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment / request as above

This use-after-free bug may lead to segfault. The iterators that have
reference to the underlying index files were closed too early while
the bitmaps were still used afterwards. If a compaction occurs
concurrently and removes the index files, it would result in accessing
unmap'd memory address.
@foobar foobar force-pushed the fix-use-after-free branch from 38861cf to ee2439b Compare February 10, 2021 01:57
Copy link
Contributor

@danxmoran danxmoran left a comment

Choose a reason for hiding this comment

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

LGTM, thanks again! I'll handle wrangling the CI / changelog from here

@danxmoran danxmoran self-assigned this Feb 10, 2021
@danxmoran danxmoran merged commit c9965e5 into influxdata:master Feb 10, 2021
@foobar foobar deleted the fix-use-after-free branch February 11, 2021 05:18
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.

2 participants