Out-of-bounds read in XML archive signature check (basic_xml_grammar::init) — missed twin of #257
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 65/100
Rechercherichtung
Der fehlerhafte Vergleich befindet sich in basic_xml_grammar<CharType>::init in libs/serialization/src/basic_xml_grammar.ipp etwa in Zeile 457, wo std::equal das geparste class_name mit BOOST_ARCHIVE_SIGNATURE() vergleicht. Vergleiche ihn mit dem Fix für #257 in basic_xml_iarchive.ipp (load_end), damit der Ansatz übereinstimmt. Fertig ist, wenn die Länge vor dem Vergleich geprüft wird und das angehängte 189-Byte-PoC unter clang mit ASan keinen AddressSanitizer-Lesezugriff mehr auslöst.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Summary
Constructing a boost::archive::xml_iarchive over untrusted input can read out of bounds
of a global constant string during the archive-header signature check. The check uses the
three-iterator form of std::equal, which reads the fixed signature constant for as many
characters as the attacker-controlled parsed signature — so a signature longer than the
constant reads past its end.
This is the same defect class as issue #257 (fixed in basic_xml_iarchive.ipp::load_end),
at a sibling call site that was not fixed.
Affected file / line
libs/serialization/src/basic_xml_grammar.ipp:457 (Boost 1.92.0); the same line is present
on current develop (there at :464). Reached from
xml_iarchive_impl::init() → xml_iarchive constructor, i.e. during archive construction,
before any user data is deserialized.
// basic_xml_grammar<CharType>::init(...)
if(! std::equal(rv.class_name.begin(), rv.class_name.end(), BOOST_ARCHIVE_SIGNATURE()))
boost::serialization::throw_exception(
archive_exception(archive_exception::invalid_signature));
rv.class_name is parsed from the untrusted signature="..." attribute of the archive
header. BOOST_ARCHIVE_SIGNATURE() returns the fixed 22-character string
"serialization::archive" (23 bytes incl. NUL). The 3-iterator std::equal reads the
second range for distance(class_name.begin(), class_name.end()) elements, with no bound
on the constant, so a class_name longer than 22 chars reads past the constant.
Impact
Global-buffer-overflow read (not a write). Realistic worst case is a crash / denial of
service when the parsed signature is long enough to run off the mapped page; for shorter
over-length signatures it typically reads adjacent static data and then simply reports a
signature mismatch. No memory corruption and no code execution. Low severity, but a genuine
out-of-bounds access and a straightforward std::equal misuse.
Precondition
An application constructs an xml_iarchive over data from an untrusted source. No other
configuration is required; the trigger is entirely in the header, before any user types are
loaded.
Reproduction (confirmed by building and running, not by code reading only)
Built against Boost 1.92.0 with clang 18 + AddressSanitizer. Constructing an xml_iarchive
over the attached 189-byte file reproduces deterministically at both -O0 and -O1:
ERROR: AddressSanitizer: global-buffer-overflow READ of size 53
0 bytes after global variable '.str' (size 23) [ = BOOST_ARCHIVE_SIGNATURE() ]
#? boost::archive::basic_xml_grammar<char>::init(std::istream&)
libs/serialization/src/basic_xml_grammar.ipp:457
PoC (ser_xml_signature_oob_read.xml) — a valid-looking header whose signature
attribute is 53 characters long:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>
<boost_serialization signature="serialization::archive_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" version="20">
Suggested fix (mirror the #257 fix)
Check the length before std::equal, or use the four-iterator std::equal (C++14):
const char* sig = BOOST_ARCHIVE_SIGNATURE();
if(rv.class_name.size() != std::char_traits<char>::length(sig)
|| ! std::equal(rv.class_name.begin(), rv.class_name.end(), sig))
boost::serialization::throw_exception(
archive_exception(archive_exception::invalid_signature));
Note on trust model
Boost.Serialization documents that loading untrusted archives is not supported. This bug is
nonetheless in the signature-validation path whose job is to reject bad input, and it is the
unfixed sibling of a defect you already accepted and fixed in #257, so it seems in scope for
the same treatment. Severity is low (read-only).
- Vorherrschende Sprache
- C++
- Sterne
- 136
- Forks
- 150
- Ø Merge
- 23 Std. 20 Min.
- Gemergte PRs (30 T.)
- 3
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus boostorg/serialization
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 15/100
boostorg/serialization#331 ·
Alle Issues in boostorg/serialization
Ähnliche Issues
-
agent:WSL code-review linux pri:medium refactoring
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
Maintainer antworten meist innerhalb von 1 Tag
-
kind/enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 82/100
psi29a/d2decomped#691 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
CachyOS/packageinstaller#144 ·
Maintainer antworten meist innerhalb von 1 Tag
-
(S1 - Need confirmation)
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
CleverRaven/Cataclysm-DDA#89715 ·
Maintainer antworten meist innerhalb von 1 Tag