Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

memtx: fix 'use after free' of garbage collected MVCC stories #7466

Conversation

CuriousGeorgiy
Copy link
Member

@CuriousGeorgiy CuriousGeorgiy commented Jul 25, 2022

directly_replaced stories can potentially get garbage collected in
memtx_tx_handle_gap_write, which is unexpected and leads to 'use after
free': in order to fix this, limit garbage collection points only to
external API calls.

Wrap all possible garbage collection points with explicit warnings (see
c9981a5).

Closes #7449

@CuriousGeorgiy CuriousGeorgiy self-assigned this Jul 25, 2022
@CuriousGeorgiy CuriousGeorgiy force-pushed the gh-7449-tuple-is-dirty-assertion-on-replace branch from fab326e to f01bf2f Compare July 25, 2022 06:41
Copy link
Contributor

@drewdzzz drewdzzz left a comment

Choose a reason for hiding this comment

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

Please, make the lines of the commit messages shorter, and see my comment about the test. Otherwise, it's OK.

@drewdzzz drewdzzz assigned CuriousGeorgiy and unassigned drewdzzz Jul 26, 2022
@CuriousGeorgiy CuriousGeorgiy force-pushed the gh-7449-tuple-is-dirty-assertion-on-replace branch from f01bf2f to 45e900f Compare July 27, 2022 06:56
@CuriousGeorgiy
Copy link
Member Author

@drewdzzz fixed commit subject length, opened a corresponding issue (tarantool/checkpatch#29).

Copy link
Contributor

@drewdzzz drewdzzz left a comment

Choose a reason for hiding this comment

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

It won't work if we rework GC as we discussed f2f.

@drewdzzz drewdzzz assigned CuriousGeorgiy and unassigned drewdzzz Jul 29, 2022
@CuriousGeorgiy CuriousGeorgiy added the do not merge Not ready to be merged label Aug 5, 2022
@CuriousGeorgiy CuriousGeorgiy force-pushed the gh-7449-tuple-is-dirty-assertion-on-replace branch from 45e900f to 9d6d08a Compare August 8, 2022 08:40
@CuriousGeorgiy CuriousGeorgiy changed the title memtx: add explicit warnings about potential MVCC story garbage colle… memtx: fix 'use after free' of garbage collected MVCC stories Aug 8, 2022
@CuriousGeorgiy CuriousGeorgiy force-pushed the gh-7449-tuple-is-dirty-assertion-on-replace branch 2 times, most recently from 9353c18 to d166e45 Compare August 8, 2022 08:44
@CuriousGeorgiy CuriousGeorgiy removed the do not merge Not ready to be merged label Aug 8, 2022
@CuriousGeorgiy CuriousGeorgiy requested a review from drewdzzz August 8, 2022 10:44
@CuriousGeorgiy CuriousGeorgiy force-pushed the gh-7449-tuple-is-dirty-assertion-on-replace branch from d166e45 to 4745224 Compare August 8, 2022 12:21
@@ -2992,7 +3003,7 @@ memtx_tx_snapshot_clarify_slow(struct memtx_tx_snapshot_cleaner *cleaner,
assert(entry->from == tuple);
tuple = entry->to;
}

memtx_tx_story_gc();
Copy link
Contributor

Choose a reason for hiding this comment

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

Snapshot cleaner must not collect garbage at least because it may be run from different thread.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I didn't bear that in mind, removed it.

I added it just for the sake of more often garbage collection.

src/box/memtx_tx.c Outdated Show resolved Hide resolved
@CuriousGeorgiy CuriousGeorgiy force-pushed the gh-7449-tuple-is-dirty-assertion-on-replace branch 3 times, most recently from 36e3e1a to 2e77c99 Compare September 12, 2022 11:55
@drewdzzz drewdzzz removed their assignment Sep 12, 2022
@CuriousGeorgiy CuriousGeorgiy requested review from alyapunov and removed request for Korablev77 September 12, 2022 14:11
@CuriousGeorgiy CuriousGeorgiy added the full-ci Enables all tests for a pull request label Sep 12, 2022
@coveralls
Copy link

coveralls commented Sep 12, 2022

Coverage Status

Coverage increased (+0.0009%) to 84.31% when pulling ba16861 on CuriousGeorgiy:gh-7449-tuple-is-dirty-assertion-on-replace into 7f52f44 on tarantool:master.

src/box/memtx_tx.h Outdated Show resolved Hide resolved
src/box/memtx_tx.h Outdated Show resolved Hide resolved
src/box/memtx_tx.h Outdated Show resolved Hide resolved
`directly_replaced` stories can potentially get garbage collected in
`memtx_tx_handle_gap_write`, which is unexpected and leads to 'use after
free': in order to fix this, limit garbage collection points only to
external API calls.

Wrap all possible garbage collection points with explicit warnings (see
c9981a5).

Closes tarantool#7449

NO_DOC=bugfix
@CuriousGeorgiy CuriousGeorgiy force-pushed the gh-7449-tuple-is-dirty-assertion-on-replace branch from 2e77c99 to ba16861 Compare September 13, 2022 11:01
@alyapunov alyapunov merged commit 18e042f into tarantool:master Sep 15, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working complicated full-ci Enables all tests for a pull request memtx mvcc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Certain memtx transaction manager state triggers tuple_has_flag(tuple, TUPLE_IS_DIRTY) assertion on replace
5 participants