annotate src/capnproto-0.6.0/security-advisories/2015-03-02-1-c++-integer-underflow.md @ 62:0994c39f1e94

Cap'n Proto v0.6 + build for OSX
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 22 May 2017 10:01:37 +0100
parents
children
rev   line source
cannam@62 1 Problem
cannam@62 2 =======
cannam@62 3
cannam@62 4 Integer underflow in pointer validation.
cannam@62 5
cannam@62 6 Discovered by
cannam@62 7 =============
cannam@62 8
cannam@62 9 Kenton Varda &lt;kenton@sandstorm.io>
cannam@62 10
cannam@62 11 Announced
cannam@62 12 =========
cannam@62 13
cannam@62 14 2015-03-02
cannam@62 15
cannam@62 16 CVE
cannam@62 17 ===
cannam@62 18
cannam@62 19 CVE-2015-2311
cannam@62 20
cannam@62 21 Impact
cannam@62 22 ======
cannam@62 23
cannam@62 24 - Remotely segfault a peer by sending it a malicious message.
cannam@62 25 - Possible exfiltration of memory, depending on application behavior.
cannam@62 26 - If the application performs a sequence of operations that "probably" no
cannam@62 27 application does (see below), possible memory corruption / code execution.
cannam@62 28
cannam@62 29 Fixed in
cannam@62 30 ========
cannam@62 31
cannam@62 32 - git commit [26bcceda72372211063d62aab7e45665faa83633][0]
cannam@62 33 - release 0.5.1.1:
cannam@62 34 - Unix: https://capnproto.org/capnproto-c++-0.5.1.1.tar.gz
cannam@62 35 - Windows: https://capnproto.org/capnproto-c++-win32-0.5.1.1.zip
cannam@62 36 - release 0.4.1.1:
cannam@62 37 - Unix: https://capnproto.org/capnproto-c++-0.4.1.1.tar.gz
cannam@62 38 - release 0.6 (future)
cannam@62 39
cannam@62 40 [0]: https://github.com/sandstorm-io/capnproto/commit/26bcceda72372211063d62aab7e45665faa83633
cannam@62 41
cannam@62 42 Details
cannam@62 43 =======
cannam@62 44
cannam@62 45 *The following text contains speculation about the exploitability of this
cannam@62 46 bug. This is provided for informational purposes, but as such speculation is
cannam@62 47 often shown to be wrong, you should not rely on the accuracy of this
cannam@62 48 section for the safety of your service. Please update your library.*
cannam@62 49
cannam@62 50 A `Text` pointer, when non-null, must point to a NUL-terminated string, meaning
cannam@62 51 it must have a size of at least 1. Under most circumstances, Cap'n Proto will
cannam@62 52 reject zero-size text objects. However, if an application performs the
cannam@62 53 following sequence, they may hit a code path that was missing a check:
cannam@62 54
cannam@62 55 1. Receive a message containing a `Text` value, but do not actually look at
cannam@62 56 that value.
cannam@62 57 2. Copy the message into a `MessageBuilder`.
cannam@62 58 3. Call the `get()` method for the `Text` value within the `MessageBuilder`,
cannam@62 59 obtaining a `Text::Builder` for the *copy*.
cannam@62 60
cannam@62 61 In this case, the `Text::Builder` will appear to point at a string with size
cannam@62 62 2^32-1, starting at a location within the Cap'n Proto message.
cannam@62 63
cannam@62 64 The `Text::Builder` is writable. If the application decided to overwrite the
cannam@62 65 text in-place, it could overwrite arbitrary memory in the next 4GB of virtual
cannam@62 66 address space. However, there are several reasons to believe this is unusual:
cannam@62 67
cannam@62 68 - Usually, when an application `get()`s a text field, it only intends to
cannam@62 69 read it. Overwriting the text in-place is unusual.
cannam@62 70 - Calling `set()` on the field -- the usual way to overwrite text -- will
cannam@62 71 create an all-new text object and harmlessly discard the old, invalid
cannam@62 72 pointer.
cannam@62 73
cannam@62 74 Note that even if an application does overwrite the text, it would still be
cannam@62 75 hard for the attacker to exploit this for code execution unless the attacker
cannam@62 76 also controls the data that the application writes into the field.
cannam@62 77
cannam@62 78 This vulnerability is somewhat more likely to allow exfiltration of memory.
cannam@62 79 However, this requires the app to additionally echo the text back to the
cannam@62 80 attacker. To do this without segfaulting, the app would either need to attempt
cannam@62 81 to read only a subset of the text, or would need to have 2^32 contiguous bytes
cannam@62 82 of virtual memory mapped into its address space.
cannam@62 83
cannam@62 84 A related problem, also fixed in this change, occurs when a `Text` value
cannam@62 85 has non-zero size but lacks a NUL terminator. Again, if an application
cannam@62 86 performs the series of operations described above, the NUL terminator check
cannam@62 87 may be bypassed. If the app then passes the string to an API that assumes
cannam@62 88 NUL-terminated strings, the contents of memory after the text blob may be
cannam@62 89 interpreted as being part of the string, up to the next zero-valued byte.
cannam@62 90 This again could lead to exfiltration of data, this time without the high
cannam@62 91 chance of segfault, although only up to the next zero-valued byte, which
cannam@62 92 are typically quite common.
cannam@62 93
cannam@62 94 Preventative measures
cannam@62 95 =====================
cannam@62 96
cannam@62 97 This problem was discovered through preventative measures implemented after
cannam@62 98 the security problem discussed in the [previous advisory][1]. Specifically, this
cannam@62 99 problem was found by using template metaprogramming to implement integer
cannam@62 100 bounds analysis in order to effectively "prove" that there are no integer
cannam@62 101 overflows in the core pointer validation code (capnp/layout.c++).
cannam@62 102 Tentatively, I believe that this analysis exhaustively covers this file.
cannam@62 103 The instrumentation has not been merged into master yet as it requires some
cannam@62 104 cleanup, but [check the Cap'n Proto blog for an in-depth discussion][2].
cannam@62 105
cannam@62 106 This problem is also caught by capnp/fuzz-test.c++, which *has* been
cannam@62 107 merged into master but likely doesn't have as broad coverage.
cannam@62 108
cannam@62 109 [1]: https://github.com/sandstorm-io/capnproto/tree/master/security-advisories/2015-03-02-0-c++-integer-overflow.md
cannam@62 110 [2]: https://capnproto.org/news/2015-03-02-security-advisory-and-integer-overflow-protection.html