Vim 7.2c.002 Fixes Arbitrary Command Execution when Handling Tar Archives

From: Jan Minář <rdancer@rdancer.org>
To: bugtraq@securityfocus.com
Cc:
Subject: Vim 7.2c.002 Fixes Arbitrary Command Execution when Handling Tar Archives
Date:


Vim 7.2c.002 Fixes Arbitrary Command Execution when Handling Tar Archives

1. SUMMARY

Product  : Vim -- Vi IMproved
Version  : Vim >= 7.0 (possibly older), fixed in 7.2c.002
          autoload/tar.vim version >= 9 (possibly older)
Impact   : Arbitrary code execution
Wherefrom: Local, remote
Original : http://www.rdancer.org/vulnerablevim-tarplugin.v3.html

Vim update fixes a vulnerability that can lead to potential arbitrary
code execution when handling tar archives.  The fnameescape() function
does not sanitize input properly, which renders code that uses it
vulnerable.  Patch 7.2c.002 fixes the vulnerability.


2. BACKGROUND

 ``Vim is an almost compatible version of the UNIX editor Vi.  Many new
   features have been added: multi-level undo, syntax highlighting,
   command line history, on-line help, spell checking, filename
   completion, block operations, etc.''

               -- Vim README.txt

 ``When one edits a *.tar file, this plugin will handle displaying a
  contents page.  Select a file to edit by moving the cursor atop
  the desired file, then hit the <return> key.  After editing, one may
  also write to the file.''

               -- Tar File Interface (pi_tar.txt)


3. VULNERABILITY

In statements such as the ones in ``$VIMRUNTIME/autoload/tar.vim'' on
lines 163, 308, 368, 407, and 419 (tar.vim version 20 (2008-07-30)):

   163    exe "r ".fnameescape(a:tarfile)
   308    exe "cd ".fnameescape(tmpdir)
   368    exe "w! ".fnameescape(fname)
   407     exe "e! ".fnameescape(tarfile)
   419   exe "cd ".fnameescape(curdir)

fnameescape() makes the untrusted file name safe as an argument to
``execute''.  However, the commands called by ``execute'' will in turn
each interpret the untrusted file name again.  This can be still used
for arbitrary command execution.  Another level of sanitizing/escaping
is needed in order to make the statements safe.


4. EXPLOIT

No exploit code is provided.


5. FIX

Fixed by patch 7.2c.002[2]: fnameescape() was updated to escape a
leading '+' and '>', and a single '-'.


6. REFERENCES

[1] Collection of Vulnerabilities in Fully Patched Vim 7.1
   http://www.rdancer.org/vulnerablevim.html
[2] Patch 7.2c.002
   http://groups.google.com/group/vim_dev/msg/80882b9ee9293139
   http://ftp.vim.org/pub/vim/unstable/patches/7.2c/7.2c.002


7. COPYRIGHT

This advisory is Copyright 2008 Jan Minar <rdancer@rdancer.org>

Copying welcome, under the Creative Commons ``Attribution-Share Alike''
License http://creativecommons.org/licenses/by-sa/2.0/uk/

Code included herein, and accompanying this advisory, may be copied
according to the GNU General Public License version 2, or the Vim
license.  See the subdirectory ``licenses''.

Various portions of the accompanying code were written by various
parties.  Those parties may hold copyright, and those portions may be
copied according to their respective licenses.


8. HISTORY

2008-08-08 Sent to: <vim-dev@vim.org>,
          <full-disclosure@lists.grok.org.uk>,
          <bugtraq@securityfocus.com>
2008-08-08 Patch 7.2c.002 released, fixing the vulnerability
2008-08-06 Reported to Vim maintainer





Copyright © 1995-2021 LinuxRocket.net. All rights reserved.