security-advisories/2022-11-30-0-pointer-list-bounds.md
Out-of-bounds read due to logic error handling list-of-list.
David Renshaw <[email protected]>, the maintainer of Cap'n Proto's Rust implementation, which is affected by the same bug. David discovered this bug while running his own fuzzer.
2022-11-30
CVE-2022-46149
Unfortunately, the bug is present in inlined code, therefore the fix will require rebuilding dependent applications.
C++ fix:
Rust fix:
capnp crate version 0.15.2, 0.14.11, or 0.13.7.A specially-crafted pointer could escape bounds checking by exploiting inconsistent handling of pointers when a list-of-structs is downgraded to a list-of-pointers.
For an in-depth explanation of how this bug works, see David Renshaw's blog post. This details below focus only on determining whether an application is vulnerable.
In order to be vulnerable, an application must have certain properties.
First, the application must accept messages with a schema in which a field has
list-of-pointer type. This includes List(Text), List(Data),
List(List(T)), or List(C) where C is an interface type. In the following
discussion, we will assume this field is named foo.
Second, the application must accept a message of this schema from a malicious
source, where the attacker can maliciously encode the pointer representing the
field foo.
Third, the application must call getFoo() to obtain a List<T>::Reader for
the field, and then use it in one of the following two ways:
Pass it as the parameter to another message's setFoo(), thus copying the
field into a new message. Note that copying the parent struct as a whole
will not trigger the bug; the bug only occurs if the specific field foo
is get/set on its own.
Convert it into AnyList::Reader, and then attempt to access it through
that. This is much less likely; very few apps use the AnyList API.
The dynamic API equivalents of these actions (capnp/dynamic.h) are also
affected.
If the application does these steps, the attacker may be able to cause the Cap'n Proto implementation to read beyond the end of the message. This could induce a segmentation fault. Or, worse, data that happened to be in memory immediately after the message might be returned as if it were part of the message. In the latter case, if the application then forwards that data back to the attacker or sends it to another third party, this could result in exfiltration of secrets.
Any exfiltration of data would have the following limitations:
-fno-exceptions and not registering an
alternative exception callback) then the attack may be able to proceed
anyway.