-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
null pointer deref and segfault in _PyObject_Alloc (obmalloc.c:1258) #75349
Comments
Python 3.7 git commit 3ca9f50 compiled with afl-clang-fast on Ubuntu 16 x64. The following script triggers undefined-behavior followed by a null pointer dereference and a segfault. import gc
t0ing0=object()
class A(object):
def f():0
x=t0ing0
r=gc.get_referrers(t0ing0)
if[0]:dct=r[0]
a=A
for i in range(1):a.f
dct["f"]=lambda:0
(a.f) Objects/dictobject.c:547:12: runtime error: index 16 out of bounds for type 'int8_t [8]' AddressSanitizer can not provide additional info. |
Yeah, bad things happen when the underlying class dict, which isn't normally exposed to Python, is mutated. |
I think it's false positive of ASAN. We have dynamically sized block. Lines 49 to 69 in 3b0f620
dictobject.c:547 calls memcpy to fill the block and head pointer |
So if I leave UBSan and ASan out of the equation and compile with gcc and run this script: Program received signal SIGSEGV, Segmentation fault. Valgrind shows a null deref as well after some invalid reads and conditional jumps. I've attached the log, it's a bit verbose. |
As Benjamin commented, this is caused by mutating internal dict. PyType_Lookup() use "method cache", based on "tp_version_tag" in the type object. I don't know we should fix it or not. |
The PEP-509 (dict version) might help if we want to fix this bug. |
But we should check dicts of all parents. |
"But we should check dicts of all parents. It will has significant penalty, especially for classes having long mro (inheriting metaclass from typing module cause long mro)." Oh right. That would defeat the whole purpose of the cache. Maybe we should not fix the bug. You are not supposed to access the hidden dictionary :-) |
Another solution is to replace class dict with a special type which invalidates the type cache on dict[key]=value. |
We ignores several crashes caused by exposing internal object |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: