You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Security bug in tkinter allows for untrusted, arbitrary code execution. #60452
Because tkinter.py uses exec to execute code from a file, it has a security bug. It searches for the file in the home dir. Apparently, on my system (don't know if its the same on others), the $HOME variable is the same as the non-root one when running Python with root priveleges
Steps to reproduce:
create a file called .Tk.py in your home folder
Whatever code is in that file will be executed.
specifically, when running Python using sudo (not in a root shell), the $HOME variable is preserved.
RamchandraApte commented on Oct 17, 2012
RamchandraAptemannequin
MannequinAuthor
More actions
I made many mistakes in the original bug report. Here is a fixed one:
Because Lib/tkinter/init.py:1801 uses exec to execute code from a file, it has a security bug. It searches for the file in the home dir. Apparently, on my system, the $HOME variable is the same as the non-root one when running Python with root privileges using sudo.
Steps to reproduce:
create a file called .Tk.py in your home folder
Whatever code is in that file will be executed.
run these three lines of code in Python using sudo:
importtkinterw=tkinter.Tk()
And the code in the .Tk.py will be executed (unless if you change the baseName for the Tk object)
There may be similar ways of running Python with root privileges preserving the environment variables in other OS'es
Using Kubuntu Linux (variant of Ubuntu Linux) 12.04
changed the title [-]Security bug in tkinter allows for untrusted code execution.[/-][+]Security bug in tkinter allows for untrusted, arbitrary code execution.[/+]on Oct 17, 2012
gpolo commented on Oct 17, 2012
gpolomannequin
Mannequin
More actions
It is a well known fact that the readprofile function uses exec, and it has been like that for more than 18 years. The parameters baseName and className defines the execution of the files $HOME/.{className}.tcl, $HOME/.{className}.py, $HOME/.{baseName}.tcl, and $HOME/.{baseName}.py. The function's docstring actually say that.
Said that, I never needed to load custom code during the creation of a Tk instance. To me the existence of readprofile is unneeded.
It is a well known fact that the readprofile function uses exec, and it
has been like that for more than 18 years. The parameters baseName and
className defines the execution of the files $HOME/.{className}.tcl,
$HOME/.{className}.py, $HOME/.{baseName}.tcl, and $HOME/.{baseName}.py. The
function's docstring actually say that.
Said that, I never needed to load custom code during the creation of a Tk
instance. To me the existence of readprofile is unneeded.
Simply remove the readprofile code (it is not documented and I never had to
use it)
RamchandraApte commented on Oct 18, 2012
RamchandraAptemannequin
MannequinAuthor
More actions
Apparently when replying by email my old account name is shown ("mani and ram") Just so you know that "mani and ram" is me.
gpolo commented on Oct 18, 2012
gpolomannequin
Mannequin
More actions
For something that has been around for so long, I would be a little more careful.
My suggestion is: no longer declare readprofile as an internal function; remove the direct call to readprofile from Tk.__init__; tell users about the new behavior, and the need to call readprofile themselves if they wish to.
In some years we might be able to estimate if readprofile is used at all, and then decide about removing it. Since I haven't been active as a Python committer, I will let the final decision to someone else.
RamchandraApte commented on Oct 31, 2012
RamchandraAptemannequin
MannequinAuthor
More actions
It is possible with this bug to make a sudo IDLE edit a root-file.
RamchandraApte commented on Oct 31, 2012
RamchandraAptemannequin
MannequinAuthor
More actions
oops ignore last msg
gpolo commented on Oct 31, 2012
gpolomannequin
Mannequin
More actions
I can ignore it, but let us be honest. If you got sudo privilege already, why are you bothering to break (or whatever else) the system using IDLE ? The issue here did not give you the sudo privilege. If it did, then we have an actual security bug.
Applied the fix to 2.6 and null merged into 2.7. This didn't need a NEWS entry because the regression hadn't been released yet. I'll remove 2.6 from the Versions now.
Activity
RamchandraApte commentedon Oct 16, 2012
Because tkinter.py uses exec to execute code from a file, it has a security bug. It searches for the file in the home dir. Apparently, on my system (don't know if its the same on others), the $HOME variable is the same as the non-root one when running Python with root priveleges
Steps to reproduce:
create a file called .Tk.py in your home folder
Whatever code is in that file will be executed.
run these three lines of code in Python:
I will add more details in later comments.
RamchandraApte commentedon Oct 16, 2012
s/tkinter.py/tkinter.__init__
RamchandraApte commentedon Oct 16, 2012
In Lib/tkinter/init.py:1801 , the readprofile function executes untrusted code.
RamchandraApte commentedon Oct 16, 2012
specifically, when running Python using sudo (not in a root shell), the $HOME variable is preserved.
RamchandraApte commentedon Oct 17, 2012
I made many mistakes in the original bug report. Here is a fixed one:
Because Lib/tkinter/init.py:1801 uses exec to execute code from a file, it has a security bug. It searches for the file in the home dir. Apparently, on my system, the $HOME variable is the same as the non-root one when running Python with root privileges using sudo.
Steps to reproduce:
create a file called .Tk.py in your home folder
Whatever code is in that file will be executed.
run these three lines of code in Python using sudo:
And the code in the .Tk.py will be executed (unless if you change the baseName for the Tk object)
There may be similar ways of running Python with root privileges preserving the environment variables in other OS'es
Using Kubuntu Linux (variant of Ubuntu Linux) 12.04
[-]Security bug in tkinter allows for untrusted code execution.[/-][+]Security bug in tkinter allows for untrusted, arbitrary code execution.[/+]gpolo commentedon Oct 17, 2012
It is a well known fact that the readprofile function uses exec, and it has been like that for more than 18 years. The parameters baseName and className defines the execution of the files $HOME/.{className}.tcl, $HOME/.{className}.py, $HOME/.{baseName}.tcl, and $HOME/.{baseName}.py. The function's docstring actually say that.
Said that, I never needed to load custom code during the creation of a Tk instance. To me the existence of readprofile is unneeded.
But what is your proposal to the issue ?
WanttoDeleteThisAccount commentedon Oct 18, 2012
On 17 October 2012 23:46, Guilherme Polo <report@bugs.python.org> wrote:
Simply remove the readprofile code (it is not documented and I never had to
use it)
RamchandraApte commentedon Oct 18, 2012
Apparently when replying by email my old account name is shown ("mani and ram") Just so you know that "mani and ram" is me.
gpolo commentedon Oct 18, 2012
For something that has been around for so long, I would be a little more careful.
My suggestion is: no longer declare readprofile as an internal function; remove the direct call to readprofile from Tk.__init__; tell users about the new behavior, and the need to call readprofile themselves if they wish to.
In some years we might be able to estimate if readprofile is used at all, and then decide about removing it. Since I haven't been active as a Python committer, I will let the final decision to someone else.
RamchandraApte commentedon Oct 31, 2012
It is possible with this bug to make a sudo IDLE edit a root-file.
RamchandraApte commentedon Oct 31, 2012
oops ignore last msg
gpolo commentedon Oct 31, 2012
I can ignore it, but let us be honest. If you got sudo privilege already, why are you bothering to break (or whatever else) the system using IDLE ? The issue here did not give you the sudo privilege. If it did, then we have an actual security bug.
52 remaining items
benjaminp commentedon Aug 19, 2013
3.2 is owned by Georg.
benjaminp commentedon Aug 19, 2013
As for 3.1, feel free to apply. There will likely be a source release of it at some point.
python-dev commentedon Aug 21, 2013
New changeset 84f40562669f by Barry Warsaw in branch '2.6':
Fix UnboundLocalError regression due to previous incorrect fix for
http://hg.python.org/cpython/rev/84f40562669f
warsaw commentedon Aug 21, 2013
Applied the fix to 2.6 and null merged into 2.7. This didn't need a NEWS entry because the regression hadn't been released yet. I'll remove 2.6 from the Versions now.
birkenfeld commentedon Sep 14, 2013
Should be fixed now in 3.2 too.
python-dev commentedon Sep 14, 2013
New changeset c18c18774e24 by Georg Brandl in branch '3.2':
Fix tkinter regression introduced by the security fix in bpo-16248.
http://hg.python.org/cpython/rev/c18c18774e24
Arfrever commentedon Sep 14, 2013
Fix still needs to be applied on 3.1 branch.
python-dev commentedon Sep 15, 2013
New changeset c39f42f46a05 by Georg Brandl in branch '3.1':
Fix tkinter regression introduced by the security fix in bpo-16248.
http://hg.python.org/cpython/rev/c39f42f46a05
pitrou commentedon Sep 15, 2013
Fix backported to 3.1, closing.