diff options
| author | Denys Fedoryshchenko <denys.f@collabora.com> | 2026-08-04 17:40:34 +0300 |
|---|---|---|
| committer | Denys Fedoryshchenko <denys.f@collabora.com> | 2026-08-12 10:42:35 +0300 |
| commit | 9554ce05e13fdb8c55a54e259b4154c9aeaca58d (patch) | |
| tree | c9a086d1490f3083ea4ec4fe3d7f12d23ff118fa /.github | |
| parent | 36c440758fc9fd606fbdfe342a4b3fd842d05c4e (diff) | |
| download | accel-ppp-9554ce05e13fdb8c55a54e259b4154c9aeaca58d.tar.gz accel-ppp-9554ce05e13fdb8c55a54e259b4154c9aeaca58d.zip | |
l2tp: validate the deciphered length of hidden AVPs
decode_avp() only checked the 2 bytes length prefix of the Hidden AVP
Subformat when the ciphered attribute spanned more than one MD5 block.
For an attribute of at most 16 bytes it deciphered the single block and
returned straight away, leaving l2tp_recv() to take the prefix at face
value:
orig_avp_len = ntohs(*(uint16_t *)avp->val) + sizeof(*avp);
...
attr->length = orig_avp_len - sizeof(*avp);
That prefix is an output of the cipher, so a peer which does not know
the secret (i.e. anyone able to reach the L2TP socket, no handshake
needed beyond a preceding Random-Vector AVP) turns it into 16 random
bits. Worse than an over-read: orig_avp_len is a uint16_t, so a prefix
of 0xffff wraps to 5, attr->length becomes -1, and the ATTR_TYPE_STRING
and ATTR_TYPE_OCTETS cases then run
attr->val.string = _malloc(attr->length + 1); /* _malloc(0) */
memcpy(attr->val.string, orig_avp_val, attr->length); /* SIZE_MAX */
that is an unbounded memcpy() into a zero sized allocation. Remotely
triggerable heap corruption on any tunnel with a secret configured. The
accel-ppp encoder always pads hidden AVPs by at least 16 bytes, so it
never produces an attribute short enough to reach this path; only a
crafted packet does.
Fix it at the source rather than at the call site: decode_avp() now
returns the deciphered length through an output parameter, and the
length is bounded against the room actually available in the received
AVP on every path out of the function, single block included. Callers
can no longer re-derive it from the AVP body and get it wrong, and the
existing multi-block check keeps guarding the deciphering loop itself.
Add packet_test.c, a standalone test which drives the real parser
through a real UDP socket: hand-crafted packets cover the length prefix
checks (including the boundaries of what fits and the single block path
the encoder cannot produce), and l2tp_packet_send()/l2tp_recv() round
trips cover the multi-block cipher and the unaligned AVP accessors. It
reproduces the corruption above under ASan on unpatched code. Wire it,
and the so far unused bitpool_test.c, into the ASAN/UBSAN workflow.
Inspired by the equivalent hardening in accel-ppp-ng (commit a8ca0f3f),
which bounds the length at the call site; the fix here is placed inside
decode_avp() and covered by a regression test.
Diffstat (limited to '.github')
| -rw-r--r-- | .github/workflows/run-tests-asan-ubsan.yml | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/.github/workflows/run-tests-asan-ubsan.yml b/.github/workflows/run-tests-asan-ubsan.yml index 12bf748d..8b25701e 100644 --- a/.github/workflows/run-tests-asan-ubsan.yml +++ b/.github/workflows/run-tests-asan-ubsan.yml @@ -60,6 +60,21 @@ jobs: working-directory: ./build run: make && sudo make install + - name: Run standalone unit tests (with ${{ matrix.sanitizer }}) + env: + ${{ matrix.env_name }}: ${{ matrix.env_value }} + run: | + gcc -O1 -g -Wall -fno-strict-aliasing -D_GNU_SOURCE \ + -DOPENSSL_API_COMPAT=0x10100000L \ + -fsanitize=${{ matrix.sanitizer }} -fno-sanitize-recover=all \ + -I accel-pppd/include -I accel-pppd/ctrl/l2tp \ + -o /tmp/l2tp_packet_test \ + accel-pppd/ctrl/l2tp/packet_test.c accel-pppd/ctrl/l2tp/packet.c \ + -lcrypto + /tmp/l2tp_packet_test + gcc -O2 -Wall -o /tmp/bitpool_test accel-pppd/extra/bitpool_test.c + /tmp/bitpool_test + - name: Insert and check kernel modules (ipoe, vlan-mon, ppposeq) # if: ${{ false }} run: | |
