-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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
Failed assertion in _PyUnicode_Equal
from calculate_suggestions
with non-string candidate
#129573
Comments
@picnixz, could you take a second look at this? I think this issue is more serious than it looks, and I want a core dev opinion before applying security labels.
I'm not certain on how accessible the attack is, but it's not making me particularly comfortable. There's some other ways to trigger this, for example: globals()[1] = "a"
b My main concern would be things that do some sort of runtime introspection or construction, but I'm definitely doing a good deal of speculation. Imagine a library that wants to expose JSON responses as objects, they might design an object like this: class DynamicJSON:
def __init__(self, response):
self.response = response
for k, v in response.items():
setattr(self, str(k), v)
def __dir__(self):
return list(self.response.keys()) Someone could in theory hijack the API response, and then wait for a developer downstream to mistype and get a TL;DR Do you think this is worth backporting to 3.11? |
I don't think that it deserves to be handled a security vulnerability: an attacker requires to be able to execute arbitrary Python code, so it's already game over. |
Right--but my point is that this sort of thing could reasonably slip past reviews for supply chain attacks. If you were to look at the reproducer (especially the |
IMO there are simpler ways to inject malwares. |
Ok, I'll leave it up to you. Is there any downside to backporting the fix? |
I think this is something we already had in another issue (I think @ncoghlan was involved in this issue but I don't exactly remember which one it was). I think we decided that messing up with globals like this is at your own risk though and didn't treat it as a security issue.
As I'm on mobile it's quite hard to check the relevant code part but IIUC, you mean we are accessing other part of the memory because we are not crashing in a release build (there is no issue with DEBUG builds right? just that release builds may access arbitrary memory because we didn't abort in time). If this is the case, it's indeed a possible security issue but we need to take into account how likely it can be exploited. As I don't have time (nor the resources) to audit this, I'll cc some other security experts: @gpshead @sethmlarson (@alex if you can have a look at it, it would be appreciated, thanks in advance). Now, even though it could be a hard-to-exploit vulnerability, I still think we can afford a backport up to 3.9 though I'll wait for "practical" experts' opinion (this kind of security issues is not my area of expertise though I have some skills as part of my curriculum). |
Yeah,
Note that this doesn't affect <3.11, the relevant code there uses functions that do check if the argument is a unicode object. I'm inclined to follow Victor's opinion here--if he thinks the chance of a vulnerability is too small, then it's probably fine to keep the fix on 3.12+ |
In Rust parlance we'd say that this code is "unsound" -- there's not a vulnerability to be directly exploited, but depending on the code written by the user, it may be possible to produce a vulnerability. The question here is whether there is non-pathological Python code that might make this exploitable by a user? I'm not sure if there is. |
I can't think of a non-pathological path that could be exploited. Maybe we could make the interpreter segfault though but again, I don't have my laptop to perform some experiments (in this case I'm just interested in making a segfault / memory access violation, which would make it more of a DoS attack). For now, let's treat it as a regular bug and fix it on 3.12+. If I have time next week, I'll see if we can make it more catastrophic but I don't see an obvious way to do it (and if Alex doesn't see it either then I doubt I'd be able to find one). |
Crash report
What happened?
The interpreter will abort if
runpy._run_module_code
is called with invalid values:Another way to trigger:
Abort message:
The suggestions machinery is the source of the issue, with
calculate_suggestions
calling_PyUnicode_Equal(name, item)
for an item that might not be unicode.Only aborts in 3.12. In 3.13 and main it results in an error in the traceback machinery:
Will submit a PR shortly.
Found using fusil by @vstinner.
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.12.8+ (heads/3.12:580d7810946, Feb 2 2025, 01:56:47) [GCC 13.3.0]
Linked PRs
calculate_suggestions
#129574The text was updated successfully, but these errors were encountered: