Incorrect GC behavior in xxlimited could lead to use-after-free
The xxlimited module in Python 3.6 on Linux mishandles garbage collection, causing a use-after-free that crashes the interpreter and lets an attacker influence a register value. In other variants the same flaw leads to a double-free.
Originally disclosed on HackerOne
- Fixed in 4 days
- Paid in 4 days
- Disclosed after 2.8 years
Issue submitted: http://bugs.python.org/issue29398 xxlimited module exist only in Python3.6 compiled on Linux.
Starting program: /usr/bin/python3.6 xlimited.py [Thread debugging using libthread_db enabled] Using host libthread_db library "/usr/lib/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault. 0x00007ffff73d73f5 in PyArena_Malloc () from /usr/lib/libpython3.6m.so.1.0 (gdb) info reg rax 0x2000000000000000 2305843009213693952 rbx 0x4141414141414141 4702111234474983745 rcx 0xe 14 rdx 0x0 0 rsi 0x10 16 rdi 0x7ffff7f812a0 140737353618080 rbp 0x7ffff7f812a0 0x7ffff7f812a0 rsp 0x7fffffffd8d0 0x7fffffffd8d0 r8 0x10e 270 r9 0x2 2 r10 0x2 2 r11 0x122a0 74400 r12 0x1 1 r13 0x7ffff7f812a0 140737353618080 r14 0x7fffffffda40 140737488345664 r15 0x7ffff7f28558 140737353254232 rip 0x7ffff73d73f5 0x7ffff73d73f5 <PyArena_Malloc+21> eflags 0x10202 [ IF RF ] cs 0x33 51 ss 0x2b 43 ds 0x0 0 es 0x0 0 fs 0x0 0 gs 0x0 0 (gdb)
As presented above, PoC gives good control on RBX passed in PyArena_Malloc() function. Payload is limited to ASCII characters, because of exec() origin. In other variants, PoC leads to double-free.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
An attacker could crash the interpreter and gain partial control of a register value, and other variants cause a double-free; the payload is limited to ASCII characters.
What the attacker needed
Python 3.6 on Linux; xxlimited module present; attacker can run a script
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Python manages memory automatically and frees objects it thinks are no longer used. Here it frees something too early and then still uses it, which is called a use-after-free. A crafted script can then crash Python and partly control what the program does next.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.