Skip to content

Conversation

@picnixz
Copy link
Member

@picnixzpicnixz commented Oct 26, 2024

Minimal PoCs:

importasyncioclassEvilLoop: defcall_soon(self, *args, **kwargs): print(1) # crashes just after printingdefget_debug(self): returnFalsedef__getattribute__(self, name): globaltrackerifname=="call_soon": fut.remove_done_callback(tracker) deltrackerreturnobject.__getattribute__(self, name) fut=asyncio.Future(loop=EvilLoop()) tracker=lambda: ... fut.add_done_callback(tracker) fut.set_result("boom")

and

importasyncioclassEvilLoop: defcall_soon(self, *args, **kwargs): raiseException("unreachable") defget_debug(self): returnFalsedef__getattribute__(self, name): ifname=="call_soon": x=lambda: ... x.get_debug=lambda: Falsefut.__init__(loop=x) returnobject.__getattribute__(self, name) fut=asyncio.Future(loop=EvilLoop()) cb, ctx=lambda: ..., lambda: ... fut.add_done_callback(cb, context=ctx) delcb, ctxfut.set_result("kaboom")

Note that depending on how the PoC is written, the crash may happen at interpreter shutdown instead. The above PoCs are a bit different from the original ones and from the ones in the tests though, but I've confirmed that without the ownership transfer, all PoCs crash.

cc @Nico-Posada

UAFs (on `fut->fut_callback0` and on `fut->fut_context0`) can be triggered if the future's event loop implements an evil `__getattribute__`.
@picnixzpicnixz added needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes labels Oct 26, 2024
@picnixzpicnixz changed the title gh-125984: fix UAF on fut->fut_{callback,context}0 due an evil loop.__getattribute__gh-125984: fix UAF on fut->fut_{callback,context}0 due to an evil loop.__getattribute__Oct 26, 2024
@miss-islington-app
Copy link

Thanks @picnixz for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 27, 2024
… due to an evil `loop.__getattribute__` (pythonGH-126003) (cherry picked from commit f819d43) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 27, 2024
… due to an evil `loop.__getattribute__` (pythonGH-126003) (cherry picked from commit f819d43) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@bedevere-app
Copy link

GH-126043 is a backport of this pull request to the 3.13 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.13 bugs and security fixes label Oct 27, 2024
@bedevere-app
Copy link

GH-126044 is a backport of this pull request to the 3.12 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.12 only security fixes label Oct 27, 2024
@picnixzpicnixz deleted the fix/future-uaf-head-callback-125984 branch October 27, 2024 15:05
kumaraditya303 pushed a commit that referenced this pull request Oct 27, 2024
…` due to an evil `loop.__getattribute__` (GH-126003) (#126044) gh-125984: fix use-after-free on `fut->fut_{callback,context}0` due to an evil `loop.__getattribute__` (GH-126003) (cherry picked from commit f819d43) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
kumaraditya303 pushed a commit that referenced this pull request Oct 27, 2024
…` due to an evil `loop.__getattribute__` (GH-126003) (#126043) gh-125984: fix use-after-free on `fut->fut_{callback,context}0` due to an evil `loop.__getattribute__` (GH-126003) (cherry picked from commit f819d43) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
picnixz added a commit to picnixz/cpython that referenced this pull request Dec 8, 2024
ebonnal pushed a commit to ebonnal/cpython that referenced this pull request Jan 12, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@picnixz@asvetlov@kumaraditya303