git-annex-shell, remotedaemon, git remote: Fix some memory DOS attacks.
The attacker could just send a very lot of data, with no \n and it would all be buffered in memory until the kernel killed git-annex or perhaps OOM killed some other more valuable process. This is a low impact security hole, only affecting communication between local git-annex and git-annex-shell on the remote system. (With either able to be the attacker). Only those with the right ssh key can do it. And, there are probably lots of ways to construct git repositories that make git use a lot of memory in various ways, which would have similar impact as this attack. The fix in P2P/IO.hs would have been higher impact, if it had made it to a released version, since it would have allowed DOSing the tor hidden service without needing to authenticate. (The LockContent and NotifyChanges instances may not be really exploitable; since the line is read and ignored, it probably gets read lazily and does not end up staying buffered in memory.)
This commit is contained in:
parent
3d759a0322
commit
15be5c04a6
8 changed files with 49 additions and 19 deletions
|
@ -1,6 +1,6 @@
|
|||
{- Simple line-based protocols.
|
||||
-
|
||||
- Copyright 2013-2014 Joey Hess <id@joeyh.name>
|
||||
- Copyright 2013-2016 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- License: BSD-2-clause
|
||||
-}
|
||||
|
@ -20,6 +20,7 @@ module Utility.SimpleProtocol (
|
|||
parse2,
|
||||
parse3,
|
||||
dupIoHandles,
|
||||
getProtocolLine,
|
||||
) where
|
||||
|
||||
import Data.Char
|
||||
|
@ -48,6 +49,16 @@ class Serializable a where
|
|||
serialize :: a -> String
|
||||
deserialize :: String -> Maybe a
|
||||
|
||||
instance Serializable [Char] where
|
||||
serialize = id
|
||||
deserialize = Just
|
||||
|
||||
instance Serializable ExitCode where
|
||||
serialize ExitSuccess = "0"
|
||||
serialize (ExitFailure n) = show n
|
||||
deserialize "0" = Just ExitSuccess
|
||||
deserialize s = ExitFailure <$> readish s
|
||||
|
||||
{- Parsing the parameters of messages. Using the right parseN ensures
|
||||
- that the string is split into exactly the requested number of words,
|
||||
- which allows the last parameter of a message to contain arbitrary
|
||||
|
@ -93,12 +104,25 @@ dupIoHandles = do
|
|||
stderr `hDuplicateTo` stdout
|
||||
return (readh, writeh)
|
||||
|
||||
instance Serializable [Char] where
|
||||
serialize = id
|
||||
deserialize = Just
|
||||
|
||||
instance Serializable ExitCode where
|
||||
serialize ExitSuccess = "0"
|
||||
serialize (ExitFailure n) = show n
|
||||
deserialize "0" = Just ExitSuccess
|
||||
deserialize s = ExitFailure <$> readish s
|
||||
{- Reads a line, but to avoid super-long lines eating memory, returns
|
||||
- Nothing if 32 kb have been read without seeing a '\n'
|
||||
-
|
||||
- If there is a '\r' before the '\n', it is removed, to support
|
||||
- systems using "\r\n" at ends of lines
|
||||
-
|
||||
- This implementation is not super efficient, but as long as the Handle
|
||||
- supports buffering, it avoids reading a character at a time at the
|
||||
- syscall level.
|
||||
-}
|
||||
getProtocolLine :: Handle -> IO (Maybe String)
|
||||
getProtocolLine h = go (32768 :: Int) []
|
||||
where
|
||||
go 0 _ = return Nothing
|
||||
go n l = do
|
||||
c <- hGetChar h
|
||||
if c == '\n'
|
||||
then return $ Just $ reverse $
|
||||
case l of
|
||||
('\r':rest) -> rest
|
||||
_ -> l
|
||||
else go (n-1) (c:l)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue