Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tsi): close series id iterator after merging
Browse files Browse the repository at this point in the history
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 authored and Tristan Su committed Feb 10, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 262cdba commit ee2439b
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -86,6 +86,7 @@ RPM packages, which has been left unchanged.
1. [20702](https://github.com/influxdata/influxdb/pull/20702): Fix loading config when `INFLUXD_CONFIG_PATH` points to a directory with `.` in its name.
1. [20678](https://github.com/influxdata/influxdb/pull/20678): Fix infinite loop in Flux parser caused by invalid array expressions.
1. [20360](https://github.com/influxdata/influxdb/pull/20360): Update API spec to document Flux dictionary features.
1. [19936](https://github.com/influxdata/influxdb/pull/19936): Close series id iterator after merging

## v2.0.3 [2020-12-14]

13 changes: 9 additions & 4 deletions tsdb/index.go
Original file line number Diff line number Diff line change
@@ -557,9 +557,11 @@ 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())
// `a` holds references to itr0/itr1 so itr0/itr1 should not be closed when `a` is still in use
itr0.Close()
itr1.Close()
return NewSeriesIDSetIterator(a[0].SeriesIDSet().And(a[1].SeriesIDSet()))
return NewSeriesIDSetIterator(ss)
}

return &seriesIDIntersectIterator{itrs: [2]SeriesIDIterator{itr0, itr1}}
@@ -646,10 +648,11 @@ 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())
// `a` holds references to itr0/itr1 so itr0/itr1 should not be closed when `a` is still in use
itr0.Close()
itr1.Close()
return NewSeriesIDSetIterator(ss)
}

@@ -733,9 +736,11 @@ 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())
// `a` holds references to itr0/itr1 so itr0/itr1 should not be closed when `a` is still in use
itr0.Close()
itr1.Close()
return NewSeriesIDSetIterator(a[0].SeriesIDSet().AndNot(a[1].SeriesIDSet()))
return NewSeriesIDSetIterator(ss)
}

return &seriesIDDifferenceIterator{itrs: [2]SeriesIDIterator{itr0, itr1}}

0 comments on commit ee2439b

Please sign in to comment.