forked from tarantool/tarantool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vinyl: fix use-after-free in vy_read_iterator_next
A read source iterator stores statements in a vy_history object using vy_history_append_stmt(). If a statement can be referenced, it's reference counter is incremented. If it can't, i.e. it belongs to a memory source, it's stored in a vy_history object without referencing. This works fine because memory sources are append-only. A problem arises only when we get to scanning disk sources. Since we yield while reading disk, a dump task may complete concurrently dropping the memory sources and possibly invalidating statements stored in the iterator history. Although we drop the history accumulated so far and restart the iteration from scratch in this case, there's still an issue that can result in a use-after-free bug in vy_read_iterator_next(). The problem is that we access the current candidate for the next statement while evaluating a disk source after a disk read. If 'next' refers to a referenced statement, it's fine, but if it refers to a statement from a memory source, it may cause use-after-free because the memory source may be dropped during a disk read. To fix this issue, let's make vy_history_append_stmt() copy statements coming from memory sources. This should be fine performance-wise because we copied memory statements eventually in vy_history_apply() anyway, before returning them to the user. Note that we also have to update vy_read_iterator_restore_mem() because it implicitly relied on the fact that 'next' coming from a memory source can't be freed by vy_mem_iterator_restore(), which cleans up the memory source history. Now, it isn't true anymore so we have to temporarily take a reference to 'next' explicitly. Closes tarantool#8852 NO_DOC=bug fix NO_TEST=tested by ASAN
- Loading branch information
Showing
4 changed files
with
35 additions
and
29 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
changelogs/unreleased/gh-8852-vy-read-iterator-use-after-free-fix.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## bugfix/vinyl | ||
|
||
* Fixed a heap-use-after-free bug in the Vinyl read iterator caused by a race | ||
between a disk read and a memory dump task. The bug could lead to a crash or | ||
an invalid query result (gh-8852). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters