[issue25019] xmlparse_setattro() Type Confusion

2015-09-18 Thread Arfrever Frehtes Taifersar Arahesis

Changes by Arfrever Frehtes Taifersar Arahesis :


--
nosy: +Arfrever

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25019] xmlparse_setattro() Type Confusion

2015-09-07 Thread John Leitch

Changes by John Leitch :


--
nosy: +brycedarling

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25019] xmlparse_setattro() Type Confusion

2015-09-07 Thread John Leitch

Changes by John Leitch :


--
nosy: +christian.heimes

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25019] xmlparse_setattro() Type Confusion

2015-09-07 Thread John Leitch

Changes by John Leitch :


--
keywords: +patch
Added file: 
http://bugs.python.org/file40395/xmlparse_setattro_Type_Confusion.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25019] xmlparse_setattro() Type Confusion

2015-09-07 Thread John Leitch

New submission from John Leitch:

Python 3.4 and 3.5 suffer from a vulnerability caused by the behavior of the 
xmlparse_setattro() function. When called, the function uses the provided name 
argument in several conditional statements which assume that the name argument 
is a string.

However, if a name argument is provided that is not a string, this logic will 
make several calls to PyUnicode_CompareWithASCIIString that expect a string, 
yet receive some other type of object, leading to a type confusion 
vulnerability:

static int
xmlparse_setattro(xmlparseobject *self, PyObject *name, PyObject *v)
{
/* Set attribute 'name' to value 'v'. v==NULL means delete */
if (v == NULL) {
PyErr_SetString(PyExc_RuntimeError, "Cannot delete attribute");
return -1;
}
assert(PyUnicode_Check(name));
if (PyUnicode_CompareWithASCIIString(name, "buffer_text") == 0) {
[...]
}


In some applications, it may be possible to exploit this behavior to achieve 
arbitrary code execution. The type confusion can be observed by running the 
following script:

from xml.parsers.expat import *
p = ParserCreate()
p.__setattr__(range(0xF), 0)

Which, depending on the arrangement of memory, may produce an exception such as 
this:

0:000> g
(d84.ce0): Access violation - code c005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=0086f904 ebx=0086f8fc ecx=0050005c edx=00b60138 esi=0050005e edi=00b60138
eip=61e9a967 esp=0086f8c8 ebp=0086f8e0 iopl=0 nv up ei ng nz na pe cy
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b efl=00010287
python35!find_maxchar_surrogates+0x37:
61e9a967 0fb701  movzx   eax,word ptr [ecx]   ds:002b:0050005c=
0:000> k3
ChildEBP RetAddr  
0086f8e0 61e9aa35 python35!find_maxchar_surrogates+0x37 
[c:\build\cpython\objects\unicodeobject.c @ 1417]
0086f908 61eabcf3 python35!_PyUnicode_Ready+0x35 
[c:\build\cpython\objects\unicodeobject.c @ 1466]
0086f918 61c547c3 python35!PyUnicode_CompareWithASCIIString+0x13 
[c:\build\cpython\objects\unicodeobject.c @ 10784]


To fix this issue, it is recommended that xmlparse_setattro() be updated to 
validate that the name argument is a string and return out of the function 
early if it is not. A proposed patch is attached.

Credit: John Leitch (johnlei...@outlook.com), Bryce Darling 
(darlingbr...@gmail.com)

--
components: XML
files: xmlparse_setattro_Type_Confusion.py
messages: 250116
nosy: JohnLeitch
priority: normal
severity: normal
status: open
title: xmlparse_setattro() Type Confusion
type: security
versions: Python 3.4, Python 3.5
Added file: http://bugs.python.org/file40394/xmlparse_setattro_Type_Confusion.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25019] xmlparse_setattro() Type Confusion

2015-09-07 Thread Serhiy Storchaka

Changes by Serhiy Storchaka :


--
assignee:  -> serhiy.storchaka
nosy: +serhiy.storchaka
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25019] xmlparse_setattro() Type Confusion

2015-09-07 Thread Roundup Robot

Roundup Robot added the comment:

New changeset ff2c4f281720 by Serhiy Storchaka in branch '3.4':
Issue #25019: Fixed a crash caused by setting non-string key of expat parser.
https://hg.python.org/cpython/rev/ff2c4f281720

New changeset 6006231dcaae by Serhiy Storchaka in branch '3.5':
Issue #25019: Fixed a crash caused by setting non-string key of expat parser.
https://hg.python.org/cpython/rev/6006231dcaae

New changeset edf25acae637 by Serhiy Storchaka in branch 'default':
Issue #25019: Fixed a crash caused by setting non-string key of expat parser.
https://hg.python.org/cpython/rev/edf25acae637

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25019] xmlparse_setattro() Type Confusion

2015-09-07 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Thank you for your contribution John.

The committed patch slightly differs from the proposed patch. Error message now 
is the same as in setattr() and general __setattr__(). Tests are moved to 
existing test class for testing of attribute setting. Improved tests for valid 
attributes.

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed
type: security -> crash
versions: +Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com