gh-157526: Call __instancecheck__ and __subclasscheck__ without creating a bound method - #157670
kumaraditya303 wants to merge 2 commits into
Conversation
mpage
left a comment
There was a problem hiding this comment.
Looks good. There's one issue with the call to _PyObject_LookupSpecialMethod that I think we need to deal with though.
| int found = _PyObject_LookupSpecialMethod(name, method_and_self); | ||
| cref.ref = method_and_self[0]; |
There was a problem hiding this comment.
I don't think this is safe. We need method_and_self[0] to be a stackref that the GC is aware of (i.e. a _PyCStackRef) before we call _PyObject_LookupSpecialMethod because _PyObject_LookupSpecialMethod stores into it and then may invoke a descriptor. It's possible that the reference stored in method_and_self[0] is the only reference to the object. In that case, if the descriptor invocation triggers the GC, the GC will reclaim the reference if its unaware of the stackref. Subsequent attempts to use the reference would be a UAF.
One potential solution is to change the signature of _PyObject_LookupSpecialMethod to be int _PyObject_LookupSpecialMethod(PyObject *attr, _PyStackRef *method, _PyStackRef *self) (and update the implementation accordingly). Then we could pass cref as method.
There was a problem hiding this comment.
Thanks, fixed it
|
When you're done making the requested changes, leave the comment: |
This reduces contention when calling these methods used by ABC on free-threading.
Skipping news for individual PR, will add one after all work is complete.