GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-133009: fix UAF in `xml.etree.ElementTree.Element.__deepcopy__` by picnixz · Pull Request #133010 · python/cpython Conversation
|
|
I actually tried to do something with tag etc, but I wasn't able to crash the interpreter. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
String literals are interned and saved in the constants list. You need to use something having a single reference. Try |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
I've actually removed this code because I thought it wasn't needed, but I'll check with an evil non-interned string tomorrow. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I'll try to add more tests later as well. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
|
||
| if (Py_REFCNT(object) == 1) { | ||
| if (PyDict_CheckExact(object)) { | ||
| // Exact dictionaries do not execute arbitrary code as it's |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@serhiy-storchaka is this assumption correct? namely, here I don't need to incref object temporarily right?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
PyDict_Next() does not use __iter__, so this comment is redundant. PyDict_Next() does not call any user code.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| if (Py_REFCNT(object) == 1) { | ||
| if (PyDict_CheckExact(object)) { | ||
| // Exact dictionaries do not execute arbitrary code as it's |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
PyDict_Next() does not use __iter__, so this comment is redundant. PyDict_Next() does not call any user code.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Actually, it's much more tricky than what I thought. Even with the INCREF/DECREF and the additional checks, the following still crashes, but not during class Evil(ET.Element): def __deepcopy__(self, memo): root.append(ET.Element('y')) root.append(ET.Element('z')) return self Y = Evil('y') root = ET.Element('a') root.extend([Evil('x'), ET.Element('t'), Y]) c = deepcopy(root) print(list(c)) print("ok") assert 0 So I'll need a bit more work. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
#133010 (comment) should help. It is good that you already have a reproducer. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Ah, you have a different issue -- growing children, not attributes. The solution should be the same -- either ignore new items or resize the array in process. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Yes, actually I found a way to fix it in the meantime (but the same can be said) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 👍
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| root = ET.Element('a') | ||
| evil = X('x') | ||
| root.extend([evil, ET.Element('y')]) | ||
| if is_python_implementation(): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We could also make the C implementation raising RuntimeError. It is fine either way.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'll postpone this for a future PR as I want to backport this one to 3.13 and 3.14 first.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @picnixz for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…__` (pythonGH-133010) (cherry picked from commit 116a9f9) Co-authored-by: Bénédikt Tran <[email protected]>
…__` (pythonGH-133010) (cherry picked from commit 116a9f9) Co-authored-by: Bénédikt Tran <[email protected]>
|
GH-133805 is a backport of this pull request to the 3.14 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
GH-133806 is a backport of this pull request to the 3.13 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.