This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Niels.Heinen
Recipients Niels.Heinen
Date 2011-06-02.11:57:38
SpamBayes Score 1.11022e-16
Marked as misclassified No
Message-id <>
Running the python binary without a script or using the -i flag will
start the process in interactive mode. The interactive mode requires an
external module to be loaded: readline.

Per default behavior, Python also tries to load this module from the current working directory (see also trace below)

strcpy(0x7fff17609ed8, ".so")                  = 0x7fff17609ed8
fopen64("", "rb" <unfinished ...>
SYS_open("", 0, 0666)               = -2
<... fopen64 resumed> )                        = 0
strcpy(0x7fff17609ed8, "")            = 0x7fff17609ed8
fopen64("", "rb" <unfinished ...>
SYS_open("", 0, 0666)

The module is imported in Modules/main.c line 663:

  if ((Py_InspectFlag || ......
    isatty(fileno(stdin))) {
      PyObject *v;
      v = PyImport_ImportModule("readline");

Why consider this a security bug: basically because you don't expect a
program to import a shared library from your current directory _unless_
you explicitly tell it to (e.g. import blah).

On a multi user system, someone could plant a malicious shared libraries
named "" in an attempt to hack a user that runs python in
interactive mode.

The risk obviously _very_ low but nevertheless worth to consider improving by, for example, loading readline with a more strict path? (e.g.  python lib directories only?)


The code below is compiled to and stored in /tmp:

  void __attribute__ ((constructor)) _load();
  void _load() {
      printf("DING DONG!\n");


foo@foo:/tmp$ ls -l /tmp/ 
-rwxr-x--- 1 nnnnn nnn 7952 Mar 29 16:24 /tmp/
foo@foo:/tmp$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Date User Action Args
2011-06-02 11:57:40Niels.Heinensetrecipients: + Niels.Heinen
2011-06-02 11:57:40Niels.Heinensetmessageid: <>
2011-06-02 11:57:39Niels.Heinenlinkissue12238 messages
2011-06-02 11:57:38Niels.Heinencreate