git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: fix mktemp (remove mktemp ;)

From
DJDave Jones <davej@redhat.com>
Date
Apr 17, 2005, 00:33 UTC
Message-ID
<20050417003325.GA15608@redhat.com>
In-Reply-To
<20050416170221.38b3e66c.pj@sgi.com>
On Sat, Apr 16, 2005 at 05:02:21PM -0700, Paul Jackson wrote:
 > > And racy. And not guaranteed to come up with fresh new files.
 > 
 > In theory perhaps.  In practice no.
 > 
 > Even mktemp(1) can collide, in theory, since there is no practical way
 > in shell scripts to hold open and locked the file from the instant of it
 > is determined to be a unique name.

Using the pid as a 'random' number is a bad idea. all an attacker has to do is create 65535 symlinks in /usr/tmp, and he can now overwrite any file you own.

mktemp is being used here to provide randomness in the filename, not just a uniqueness.

 > The window of vulnerability for shell script tmp files is the lifetime
 > of the script - while the file sits there unlocked.  Anyone else with
 > permissions can mess with it.

Attacker doesnt need to touch the script. Just take advantage of flaws in it, and wait for someone to run it.

 > More people will fail, and are already failing, using mktemp than I have
 > ever seen using $$ (I've never seen a documented case, and since such
 > files are not writable to other user accounts, such a collision would
 > typically not go hidden.)
 > 
 > Fast, simple portable solutions that work win over solutions with some
 > theoretical advantage that don't matter in practice, but also that are
 > less portable or less efficient.

I'd suggest fixing your distributions mktemp over going with an inferior solution.

		Dave
Previous: Paul JacksonNext: Paul Jackson
Message 14 of 25 in “fix mktemp (remove mktemp ;)”
  1. fix mktemp (remove mktemp ;)Paul Jackson, Apr 16, 2005
  2. missing mkdir -p flag in gitdiff-doPaul Jackson, Apr 16, 2005
  3. optimize gitdiff-do scriptPaul Jackson, Apr 16, 2005
  4. Petr BaudisApr 16, 2005
  5. Paul JacksonApr 17, 2005
  6. Paul JacksonApr 18, 2005
  7. Petr BaudisApr 18, 2005
  8. Paul JacksonApr 18, 2005
  9. Paul JacksonMay 10, 2005
  10. Jan-Benedict GlawApr 16, 2005
  11. Paul JacksonApr 16, 2005
  12. Petr BaudisApr 16, 2005
  13. Paul JacksonApr 17, 2005
  14. Dave JonesApr 17, 2005
  15. Paul JacksonApr 17, 2005
  16. Dave JonesApr 17, 2005
  17. David LangApr 17, 2005
  18. Paul JacksonApr 17, 2005
  19. Brian O'MahoneyApr 17, 2005
  20. Paul JacksonApr 17, 2005
  21. Erik van KonijnenburgApr 17, 2005
  22. Paul JacksonApr 17, 2005
  23. Herbert XuApr 18, 2005
  24. Paul JacksonApr 18, 2005
  25. Florian WeimerApr 18, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.