-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
gh-117657: TSAN Fix race in PyMember_Get
and PyMember_Set
, for Py_T_OBJECT_EX
type
#119368
Conversation
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
@DinoV this is ready for review now |
PyMember_Get
and PyMember_Set
, for Py_T_OBJECT_EX
typePyMember_Get
and PyMember_Set
, for Py_T_OBJECT_EX
type
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 don't think we can rely on _Py_REF_MAYBE_WEAKREF
(i.e., _PyObject_SetMaybeWeakref
) being set on the field's value. The underlying field may be modified by a C API user outside of PyMember_SetOne
, such as if it's defined with a PyMemberDef
.
I think the setter needs to use a critical section. The reader can optimistically try _Py_TryIncrefCompare
, but needs to fall back to a read inside a critical section if that fails.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
I see your point, but there would be a problem that I cannot see how to solve, though.
So, what lock would I use for the critical section? |
Use the original address (i.e., We already assume it's a Line 80 in bd8c1f9
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
@@ -59,6 +59,8 @@ extern "C" { | |||
_Py_atomic_store_uint16_relaxed(&value, new_value) | |||
#define FT_ATOMIC_STORE_UINT32_RELAXED(value, new_value) \ | |||
_Py_atomic_store_uint32_relaxed(&value, new_value) | |||
#define FT_ATOMIC_EXCHANGE_PTR(value, new_value) \ |
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'm not using this now, should I leave it in?
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.
Let's remove it then.
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Co-authored-by: Erlend E. Aasland <[email protected]>
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
@colesbury I can just remove the commented code, it isn't relevant yet. |
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Co-authored-by: Erlend E. Aasland <[email protected]>
@colesbury let me know if you want me to make more changes. |
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.
Sorry for the delay - I was on vacation last week.
This LGTM with a minor edit to the test. I'll make the change directly and merge this.
Thanks @dpdani for the PR, and @colesbury for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
…pythonGH-119368) Fix a race in `PyMember_GetOne` and `PyMember_SetOne` for `Py_T_OBJECT_EX`. These functions implement `__slots__` accesses for Python objects. (cherry picked from commit 362cd26) Co-authored-by: Daniele Parmeggiani <[email protected]>
GH-120655 is a backport of this pull request to the 3.13 branch. |
GH-119368) (#120655) Fix a race in `PyMember_GetOne` and `PyMember_SetOne` for `Py_T_OBJECT_EX`. These functions implement `__slots__` accesses for Python objects. (cherry picked from commit 362cd26) Co-authored-by: Daniele Parmeggiani <[email protected]>
thank you @colesbury, celebrated with a good beer and good vibes 1️⃣🍻🎉 |
…python#119368) Fix a race in `PyMember_GetOne` and `PyMember_SetOne` for `Py_T_OBJECT_EX`. These functions implement `__slots__` accesses for Python objects.
…python#119368) Fix a race in `PyMember_GetOne` and `PyMember_SetOne` for `Py_T_OBJECT_EX`. These functions implement `__slots__` accesses for Python objects.
…python#119368) Fix a race in `PyMember_GetOne` and `PyMember_SetOne` for `Py_T_OBJECT_EX`. These functions implement `__slots__` accesses for Python objects.
Fix one data race and use-after-free in PyMember.
I've just started working on this, there are more races to be solved, but this is the only one visible from python code, AFAIU.
More PRs are required for making these functions thread-safe.
I've added some commented code to show what the follow-up tests would look like.