-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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: possible heap-use-after-free with magnet links #6815
Conversation
e4e9d2c
to
4361983
Compare
e6e8c9e
to
9076d50
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this change!
IMO we can do this without exposing a new public method in tr_torrent
but 👍 with the approach of moving this to an idle func
ce53932
to
39b012f
Compare
Fixes #6706.
Stack trace at #4178 (comment).
This PR backtracks some changes made in #6383:
tr_torrentVerify()
call instead of executing it immediately after completing the metadata of a magnet link. This is the crux of the bug this PR fixes, more on that below.tr_torrentMagnetDoIdleWork()
that got removed.#6383 changed
tr_torrent::on_metainfo_completed()
so that it queuestr_torrentVerify()
to be executed in the session thread when it is free, instead of executing it immediately.This was needed because
tr_torrentVerify()
will stop the torrent, thus freeing alltr_peerMsgs
objects belonging to that torrent (i.e. disconnecting all peers), and this might trigger a chain reaction (detailed at #6383 (comment)) that leads toheap-use-after-free
.However, an unexpected consequence of this change is, there is a chance that
tr_torrentVerify()
will be executed after the originaltr_torrent
object for the magnet link is destructed, causingheap-use-after-free
. This can happen if the magnet link got removed from Transmission or the session itself got shut down immediately after the metadata transfer completed.A side effect of this PR is that we need to re-introduce the indirection step
tr_torrentMagnetDoIdleWork()
, otherwise there will beheap-use-after-free
. I made the changes in #6383 because I didn't like how it worked, but for now I don't see any better solution other then reverting to the way it was.