Commit cf4682f
committed
Simplify ordering on unordered interleaved streams
This fixes a vulnerability where an attacker could cause a panic by
sending unordered interleaved stream fragments with Message Identifiers
(MIDs) chosen exactly 2^31 apart.
The unordered stream reassembler uses IntervalList, which relies on
slice::partition_point. This standard library method requires a strict
linear total order to perform binary search. RFC1982 sequence spaces
are circular, meaning they violate total ordering at their maximum
distance (e.g. A < B < C < A). When chunks arrive with MIDs exactly at
this maximum boundary, partition_point fails its invariants and panics.
Ordered streams are immune to this panic because they drop chunks that
fall outside a strictly validated forward half-space window (via
next_mid and is_valid_successor). This constrains their queued chunks to
a narrow slice of the circle where the math never wraps around, allowing
partition_point to sort them safely.
Unordered streams, however, have no such delivery window and accept
chunks from anywhere on the sequence circle. But for unordered chunks,
the MIDs have no real ordering; The MID is used exclusively as a
correlation ID to group fragments of the same message together. The
relative order of different unordered MIDs is completely irrelevant.
This commit introduces a dedicated UnorderedInterleavedKey that bypasses
RFC1982 ordering and instead derives standard linear u32 ordering. This
satisfies partition_point's strict total ordering requirement and
prevents the vulnerability.1 parent f648f61 commit cf4682f
2 files changed
Lines changed: 50 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
77 | 106 | | |
78 | 107 | | |
79 | 108 | | |
| |||
127 | 156 | | |
128 | 157 | | |
129 | 158 | | |
130 | | - | |
| 159 | + | |
131 | 160 | | |
132 | 161 | | |
133 | 162 | | |
| |||
142 | 171 | | |
143 | 172 | | |
144 | 173 | | |
145 | | - | |
| 174 | + | |
146 | 175 | | |
147 | 176 | | |
148 | 177 | | |
| |||
653 | 682 | | |
654 | 683 | | |
655 | 684 | | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
656 | 703 | | |
0 commit comments