bpo-40071: Fix potential crash in _functoolsmodule.c#19273
Merged
vstinner merged 1 commit intopython:masterfrom Apr 1, 2020
Merged
bpo-40071: Fix potential crash in _functoolsmodule.c#19273vstinner merged 1 commit intopython:masterfrom
vstinner merged 1 commit intopython:masterfrom
Conversation
vstinner
reviewed
Apr 1, 2020
Modules/_functoolsmodule.c
Outdated
Member
There was a problem hiding this comment.
The comment is not correct. The bug is not "double free": Py_CLEAR(NULL) does NULL, that's fine. The problem is if one module instance is deallocated, kwd_mark is cleared to NULL. Other instances will use NULL and so crash.
Contributor
Author
There was a problem hiding this comment.
Rephrased the comment and updated commit message. Thanks for getting it.
Changes on 7dd549e made _functools compatible with PEP-489 and we could have multiple modules instances loaded. But, right now there is no way to make `kwd_mark` global into a per module instance variable. kwd_mark is used on lru_cache_new which does not have a reference to a PyModule*, necessary to use PyModule_GetState. PEP-573 will solve this problem and will allow us to move the global state to per-module data and properly clear the state when unloading a module instance. This change temporarily disable cleaning of kwd_mark to avoid NULL pointer dereference if we clear kwd_mark and other module instances still alive use it. wip
a6ab03d to
eb807ad
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes on 7dd549e made _functools compatible with
PEP-489 and we could have multiple modules instances loaded.
But, right now there is no way to make
kwd_markglobal intoa per module instance variable. kwd_mark is used on lru_cache_new
which does not have a reference to a PyModule*, necessary to use
PyModule_GetState.
PEP-573 will solve this problem and will allow us to move the global
state to per-module data and properly clear the state when unloading
a module instance.
This change temporarily disable cleaning of kwd_mark to avoid NULL
pointer dereference if we clear kwd_mark and other module instances
still alive use it.
https://bugs.python.org/issue40071