-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The function that shortcuts is the function that reinterpret_casts\n\nbitsery is a header-only C++ serialization library. The vulnerable function in CVE-2026-9521 is `SmartPtrOwnerManager::loadFromSharedState` in `include/bitsery/ext/std_smart_ptr.h`. The mechanism is shared-pointer dedup without type identity.\n\nWhen the deserializer reads a `shared_ptr`, it reads a numeric `id` from the buffer first. If the `id` has not been seen on this deserialization pass, the deserializer reads the pointee bytes off the wire and registers the result in `_idMap[id]`. If the `id` HAS been seen, the deserializer takes the shortcut: it reuses the `state.obj` already in the map and hands it to the caller. The shortcut, in v5.2.4, was this:\n\n```cpp\nstatic void loadFromSharedState(TSharedState& state, T& obj)\n{\n // reinterpret_pointer_cast is only since c++17\n auto p = reinterpret_cast(state.obj.get());\n obj = std::shared_ptr(state.obj, p);\n}\n```\n\nThe comment above the cast is testimony. The author considered the C++17 `reinterpret_pointer_cast`, decided the codebase needed pre-C++17 compatibility, and reached for the older `reinterpret_cast`. Nowhere in the function is the type that was stored when `state.obj` was first registered checked against `TElement`, the type the current field expects. The cast happens. The caller receives a `shared_ptr` aimed at bytes that were never a `TElement`.\n\n`TElement` is whatever the current call expects. The buffer chooses what `state.obj` originally held by choosing the type of the field at `id`'s first appearance. The buffer chooses both halves of the type confusion.\n\n## example_addr_leak_1.cpp\n\nThe gist's first PoC serializes a `MyData` struct with four `shared_ptr` fields:\n\n```cpp\nstruct A { std::string data = \"AAAABBBBCCCC\"; };\nstruct B { std::vector data = {0x11, 0x12, 0x13}; };\nstruct C { uint64_t data = 42; };\n\nstruct MyData\n{\n std::shared_ptr a;\n std::shared_ptr b;\n std::shared_ptr c;\n std::shared_ptr c2;\n};\n```\n\nThe exploit buffer is twenty-one bytes:\n\n```\n0x01,0x0c,0x41,0x41,0x41,0x41,0x42,0x42, 0x42,0x42,0x43,0x43,0x43,0x43,0x02,0x03,\n0x11,0x12,0x13,0x01,0x02,\n```\n\nThe first three fields decode normally: `a` gets `id=1` and the string \"AAAABBBBCCCC\", `b` gets `id=2` and the vector `{0x11, 0x12, 0x13}`, `c` gets `id=3` and the value `42`. The last two bytes are the assignment for `c2`: the buffer claims `c2` is `id=1` (already registered under `A`) and then runs out. The deserializer reads `c2`'s `id=1`, finds the slot in `_idMap`, and short-circuits through `loadFromSharedState`.\n\n`loadFromSharedState` runs with `state.obj` holding the `A` instance and `TElement=C`. `reinterpret_cast(state.obj.get())` returns a pointer that aims `C::data` (a `uint64_t`) at the first eight bytes of `A` (the `std::string` header, the first field of which is the heap pointer to the string's character buffer). The application reads `c2->data` and sees a heap address.\n\nRun the file and the last lines of output are:\n\n```\nc: 55e5c1a5d780\nc2: 55e5c1a5dab0\n```\n\nASLR bypassed. The deserializer raised no error. The PoC's own assertion clause passes verbatim: `assert(des.adapter().error() == bitsery::ReaderError::NoError && des.adapter().isCompletedSuccessfully())`.\n\n## example_vtable_hijack.cpp and pwned()\n\nThe vtable hijack is in `example_vtable_hijack.cpp`. It defines:\n\n```cpp\nvoid pwned() {\n std::cout << \"pwned!\" << std::endl;\n system(\"/bin/sh\");\n}\nvoid* table[] = {(void*)pwned};\n```\n\nThe exploit buffer declares two `shared_ptr` fields, an `A` (plain struct with one `uint64_t`) and a `B` (polymorphic, has `virtual void foo()`). The buffer assigns `id=1` to the `A` and re-uses `id=1` for the `B`. The serializer wrote `A`'s eight bytes as the literal pointer value of `&table`. On the second `id=1` resolution, `loadFromSharedState` runs with `state.obj` holding the `A` storage and `TElement=B`. The reinterpret_cast turns the `A`'s eight bytes into a `B*`. The first eight bytes of any polymorphic class instance are the vtable pointer. The deserializer assigns `data.b = shared_ptr(...)` aiming at the `A`'s bytes, which now claim to be a `B` whose vtable lives at `&table`.\n\nThe next line of the program is `data.b->foo()`. C++ dispatches a virtual call through the object's vtable: it reads the first eight bytes of `*data.b`, treats those eight bytes as a pointer to a vtable, and calls the first function in that vtable. The first eight bytes are `&table`. The first function in `table` is `pwned`. `pwned()` calls `system(\"/bin/sh\")`. The shell runs in the deserializer's process.\n\nThe library's deserializer assertion passes. No error was raised.\n\nCVSS 7.3, vector `CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:L`. Each of confidentiality, integrity, and availability rated Low. The gist linked from the CHANGELOG defines a function called `pwned`. The two records describe different exploits.\n\n## The CHANGELOG was the disclosure\n\nThe fix commit `66d16516e24893bebc1c8af52bf2fe9ad0735061` landed on the bitsery master branch on October 2, 2025. The commit message reads \"Fix shared polymorphic poiner like type serialization/deserialization.\" Six days later, on October 8, 2025, the maintainer wrote the CHANGELOG section for the next release. The CHANGELOG.md diff in that commit added these lines verbatim:\n\n```markdown\n# [5.2.5](https://github.com/fraillt/bitsery/compare/v5.2.4...v5.2.5) (2025-10-09)\n\n### Bug fixes\n* fix security issue during deserialization where a crafted payload could cause a shared pointer to be assigned to a different type. More information is [here](https://gist.github.com/TrebledJ/750abc64a826f19dd2d6774724629b71). (huge thanks to [Johnathan](https://github.com/TrebledJ))\n```\n\nThe phrase \"security issue\" is named. The bug class is described in one sentence. The link points to TrebledJ's gist, which contains `cvd_bitsery_20250830.md` (the coordinated-disclosure document), `example_addr_leak_1.cpp`, `example_addr_leak_2.cpp`, `example_mem_read.cpp`, and `example_vtable_hijack.cpp`. The link is markdown. It rendered on github.com from the day the v5.2.5 tag was cut.\n\nThe 5.2.5 tag was cut on October 9, 2025. CVE-2026-9521 was published on NVD on May 26, 2026. From release-day to CVE-assignment, 229 days elapsed.\n\nDuring those 229 days, the CHANGELOG paragraph was the project's public statement that this release fixed a security issue. Consumers reading the changelog when deciding whether to upgrade saw a security note and a link to four runnable exploit primitives. Consumers reading CVE feeds during the same window saw nothing about bitsery.\n\nThis is release-lag-disclosure in a sharper form than the canonical shape. The fix landed in trunk and shipped in a tag in the same week. The CHANGELOG carried the disclosure for 229 days while MITRE caught up.\n\n## What the CVE record left out\n\nThe NVD description for CVE-2026-9521, in full:\n\n> A security vulnerability has been detected in fraillt bitsery up to 5.2.4. Affected is the function loadFromSharedState in the library include/bitsery/ext/std_smart_ptr.h. Such manipulation leads to improper validation of specified type of input. It is possible to launch the attack remotely. The exploit has been disclosed publicly and may be used.\n\nWords the NVD description does not include: \"shared pointer,\" \"type confusion,\" \"ASLR,\" \"memory disclosure,\" \"vtable,\" \"RCE.\" The phrase \"improper validation of specified type of input\" is the boilerplate text for CWE-20, the generic category MITRE assigns when no more specific category is identified. CWE-843 (Access of Resource Using Incompatible Type, the canonical entry for type confusion) is not referenced. The CHANGELOG entry the filer had access to was more technically specific than the CVE description that resulted from it.\n\nCVSS rates the impact `C:L/I:L/A:L`. The PoC the CHANGELOG links includes vtable hijack to arbitrary code execution. The rating and the linked artifact disagree about what the bug does.\n\n## The patch wraps the cast, then ships a TODO for the next one\n\nThe fix commit adds a `sharedTypeId` field to `PLCInfoDeserializer` and a `canAssignToShared` helper. The check decides whether to enter `loadFromSharedState`. The cast site itself is unchanged:\n\n```cpp\nstatic void loadFromSharedState(TSharedState& state, T& obj)\n{\n // reinterpret_pointer_cast is only since c++17\n auto v = state.obj.get();\n auto p = reinterpret_cast(v);\n obj = std::shared_ptr(state.obj, p);\n}\n```\n\nThe reinterpret_cast remains. The new code decides whether to reach it. In the non-polymorphic deserialization branch, the new gate is a one-line equality check; in the polymorphic branch, it walks the inheritance chain so subtypes still resolve.\n\nThe same commit adds a sibling function for the polymorphic path:\n\n```cpp\nstatic void loadFromSharedStatePolymorphic(TSharedState& state, T& obj)\n{\n // TODO Fix pointer addresses in case objects are deserialized using\n // different bases\n\n // reinterpret_pointer_cast is only since c++17\n auto v = state.obj.get();\n auto p = reinterpret_cast(v);\n obj = std::shared_ptr(state.obj, p);\n}\n```\n\nThe new function is identical to the fixed one except for the TODO. The TODO names what the polymorphic case still gets wrong: when a class hierarchy uses multiple inheritance, casting between a `Base*` and a `Derived*` requires adjusting the pointer by the offset of the `Base` subobject within `Derived`. `reinterpret_cast` does not do that. The TODO acknowledges this. The function shipped.\n\nSix days after the named fix, two more commits landed touching the same files. `ff841d6` \"check type information before assigning to observer pointer\" added type-check coverage to a sibling code path. `5e7eced` \"cast from polymorphic owner pointer-like type to observer during assignment\" added the corresponding cast adjustment. Three patches in one release cycle, all addressing the type-check gap in the same component. The bug class recurred twice inside the patch window before 5.2.5 went out.\n\n## Why this exists\n\nbitsery's documentation positions it as a library for \"trusted bus\" contexts: game state replication, IPC between processes the same operator owns. The README and examples do not describe the deserialization input as adversarial. Within that threat model, the absence of type checking at the cast site reads as performance discipline, not negligence. The buffer is trusted; the producer's `Serializer` is the only thing that ever wrote it. Why check?\n\nCVE-2026-9521's `AV:N` (Attack Vector Network) marks the threat model the library was not designed for. Consumers consuming attacker-supplied buffers (network protocols, on-disk cache files written by user processes, IPC across trust boundaries) had reached for `StdSmartPtr` under the older assumption. The CHANGELOG entry for 5.2.5 is the moment the project updated its threat model in writing. The README, today, still describes bitsery as a serializer for game state and similar use cases.\n\nPoC: [TrebledJ/cvd_bitsery_20250830.md](https://gist.github.com/TrebledJ/750abc64a826f19dd2d6774724629b71)","closing_line":"The CHANGELOG was the disclosure. The CVE was the receipt.","hook_md":"bitsery's CHANGELOG entry for v5.2.5, dated October 9, 2025, contains the sentence \"fix security issue during deserialization where a crafted payload could cause a shared pointer to be assigned to a different type\" and a markdown link. The link goes to a public gist. The gist has four runnable C++ files. One of them defines a function called `pwned()`, fills the deserializer's buffer with a pointer to it, and gets it called through a virtual dispatch. CVE-2026-9521 was published on NVD 229 days later. The CVE description says \"improper validation of specified type of input.\" It does not name shared pointers, type confusion, vtable hijack, or the gist the CHANGELOG already linked.","post_id":606,"slug":"bitsery-cve-2026-9521-changelog-was-the-disclosure","title":"CVE-2026-9521: bitsery's CHANGELOG Disclosed The Type Confusion 229 Days Before MITRE","type":"initial","unreadable_sentence":"The gist linked from the CHANGELOG defines a function called `pwned`. CVSS rates this `C:L/I:L/A:L`."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCas03KwAKCRDeZjl4jgkQ JknTAP4kBO1cj8tA8xRI6uquESAFbLJofzOwD4lMqemKjd6sxQEAhNVemDakXGNM xx66MUdRHZrnDFOqHfhrphNwRmeoWww= =vnL8 -----END PGP SIGNATURE-----