[issue46561] Descriptor resolution should own arguments passed to descriptors

2022-02-01 Thread Raymond Hettinger
Raymond Hettinger added the comment: If this can only be triggered from C code, it less of a concern. The PR increases cost on a critical path, so we ought to be wary of applying it unless a known problem is being solved. Note, this code path has survived two decades of deployment. Also, th

[issue46561] Descriptor resolution should own arguments passed to descriptors

2022-02-01 Thread Mark Shannon
Mark Shannon added the comment: # This needs to be C code for this to fail, I'm writing it in Python for clarity and brevity class D: def __get__(self, instance, owner): del C.d # There are now no strong references to self self.whatever # Access to freed memory # Thi

[issue46561] Descriptor resolution should own arguments passed to descriptors

2022-01-28 Thread Dennis Sweeney
Dennis Sweeney added the comment: Hi Max, My apologies -- my first message was probably too dismissive. Is there any way to make the existing code crash with pure Python, and can we then add such a test case? If not with pure Python, then perhaps with some minimal reproducible example using

[issue46561] Descriptor resolution should own arguments passed to descriptors

2022-01-28 Thread Maxwell Bernstein
Maxwell Bernstein added the comment: Ah, and another piece of the puzzle: this can happen in runtimes like Cinder that provide their own native code entrypoints to functions like a __get__. -- ___ Python tracker

[issue46561] Descriptor resolution should own arguments passed to descriptors

2022-01-28 Thread Maxwell Bernstein
Change by Maxwell Bernstein : -- components: +C API ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://m

[issue46561] Descriptor resolution should own arguments passed to descriptors

2022-01-28 Thread Maxwell Bernstein
Maxwell Bernstein added the comment: Hi Dennis, Sorry, let me be more clear. CPython in general ensures that objects passed in as arguments to a function will live for the duration of the function call if they are otherwise untouched. As it is now, this invariant is not maintained when call

[issue46561] Descriptor resolution should own arguments passed to descriptors

2022-01-27 Thread Dennis Sweeney
Dennis Sweeney added the comment: Why? Callee-borrowing-from-caller is the established norm across the C API. You mention use-after-free, but can you elaborate on how that can happen in practice? https://docs.python.org/3/extending/extending.html?highlight=borrowed#ownership-rules says: """

[issue46561] Descriptor resolution should own arguments passed to descriptors

2022-01-27 Thread Maxwell Bernstein
Change by Maxwell Bernstein : -- keywords: +patch pull_requests: +29158 stage: -> patch review pull_request: https://github.com/python/cpython/pull/30979 ___ Python tracker __

[issue46561] Descriptor resolution should own arguments passed to descriptors

2022-01-27 Thread Maxwell Bernstein
New submission from Maxwell Bernstein : Currently the descriptor (self) argument to __get__ is passed borrowed, since _PyType_LookupId returns a borrowed reference (see _PyObject_LookupSpecial and lookup_maybe_method in Objects/typeobject.c). This should instead own the reference. --