[GHC] #10940: Random number chosen by openTempFile is always 1804289383846930886

#10940: Random number chosen by openTempFile is always 1804289383846930886 -------------------------------------+------------------------------------- Reporter: andersk | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: | Version: 7.10.2 libraries/base | Keywords: | Operating System: Linux Architecture: | Type of failure: Incorrect result Unknown/Multiple | at runtime Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | -------------------------------------+------------------------------------- {{{#!hs import System.Directory import System.IO main = do (p, _) <- openTempFile "/tmp" "" print p removeFile p }}} {{{#!console $ runghc temp.hs "/tmp/1804289383846930886" $ runghc temp.hs "/tmp/1804289383846930886" $ runghc temp.hs "/tmp/1804289383846930886" $ runghc temp.hs "/tmp/1804289383846930886" }}} This “random” number is the concatenation of the first two numbers 1804289383, 846930886 returned by glibc’s `rand()` when not seeded (or seeded with 1). This is not immediately a library security bug, I think: the file is created with `O_EXCL`, and if it already exists, `openTempFile` will move onto the next value 16816927771714636915, and so on. However, the predictable filenames make a potential application security bug that much more likely. (For your amusement, [https://www.google.com/search?q=1804289383846930886 Google 1804289383846930886].) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10940 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10940: Random number chosen by openTempFile is always 1804289383846930886 -------------------------------------+------------------------------------- Reporter: andersk | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 7.10.2 Resolution: | Keywords: Operating System: Linux | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: #9058 | Differential Rev(s): -------------------------------------+------------------------------------- Changes (by thomie): * cc: slyfox (added) * related: => #9058 Comment: The code for `openTempFile` was added in f510c7cac5b2e9afe0ebde2766a671c59137f3cc (#9058). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10940#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10940: Random number chosen by openTempFile is always 1804289383846930886 -------------------------------------+------------------------------------- Reporter: andersk | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 7.10.2 Resolution: | Keywords: Operating System: Linux | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: #9058 | Differential Rev(s): -------------------------------------+------------------------------------- Comment (by slyfox): I agree it's a problem. Posting '''ghc-7.8.4''' results for comparison: {{{ $ runhaskell a.hs "/tmp/47" $ runhaskell a.hs "/tmp/59" $ runhaskell a.hs "/tmp/71" $ runhaskell a.hs "/tmp/83" $ runhaskell a.hs "/tmp/95" $ runhaskell a.hs "/tmp/107" }}} (nice +12 steps) The question is what to use so it would work on modern systems. I see the following routes: 1. use something portable and insecure like seeding with '''srand(time())''': will not behave nicely after '''fork()''' from haskell program, still predictable 2. introduce OS-specific branches to use '''mkstemp''' / '''mkostemp''' / '''mkostemps''' / '''GetTempFileName''' / '''GetTempPath'''. Is there a nicer way? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10940#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10940: Random number chosen by openTempFile is always 1804289383846930886 -------------------------------------+------------------------------------- Reporter: andersk | Owner: bgamari Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 7.10.2 Resolution: | Keywords: Operating System: Linux | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: #9058 | Differential Rev(s): Phab:D3188 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * owner: (none) => bgamari * differential: => Phab:D3188 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10940#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10940: Random number chosen by openTempFile is always 1804289383846930886 -------------------------------------+------------------------------------- Reporter: andersk | Owner: bgamari Type: bug | Status: patch Priority: normal | Milestone: Component: libraries/base | Version: 7.10.2 Resolution: | Keywords: Operating System: Linux | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: #9058 | Differential Rev(s): Phab:D3188 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => patch -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10940#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10940: Random number chosen by openTempFile is always 1804289383846930886 -------------------------------------+------------------------------------- Reporter: andersk | Owner: bgamari Type: bug | Status: closed Priority: normal | Milestone: Component: libraries/base | Version: 7.10.2 Resolution: fixed | Keywords: Operating System: Linux | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: #9058 | Differential Rev(s): Phab:D3188 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * resolution: => fixed Comment: This was merged in ad617a3edf832b5368146e0bbf0cf2780d9355e1. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10940#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC