serial: bounds-check transaction index in bitbang drivers - #26336
Draft
arcaartem wants to merge 1 commit into
Draft
serial: bounds-check transaction index in bitbang drivers#26336arcaartem wants to merge 1 commit into
arcaartem wants to merge 1 commit into
Conversation
The wire-supplied transaction index in the ChibiOS bitbang ISR (interrupt_handler in platforms/chibios/drivers/serial.c) was used to index split_transaction_table with no bounds check at all, allowing an out-of-bounds struct read and an arbitrary function-pointer call via trans->slave_callback. Add a check that bails out before the table is indexed. The bail-out releases the serial line back to input and the chSysLockFromISR critical section the same way the normal exit path does, since sync_send() earlier in the handler leaves the pin driven as output; skipping that release would leave the line stuck driven and prevent the peer's falling-edge ISR from ever firing again. Also fix `>` vs `>=` off-by-one bounds checks against NUM_TOTAL_TRANSACTIONS in initiate_transaction() (ChibiOS) and in both the target ISR and soft_serial_transaction() (AVR), each of which allowed indexing one entry past the end of split_transaction_table. The vendor UART driver (platforms/chibios/drivers/serial_protocol.c) already checks correctly with `>=`; this brings the bitbang drivers to parity with it.
arcaartem
force-pushed
the
fix-bitbang-serial-index-bounds
branch
from
July 16, 2026 17:38
d9e0073 to
c59a788
Compare
Author
|
Fixed a defect in the new early-out path: it released the ISR critical section but left the serial line driven as output (sync_send() leaves the pin as output), so on a corrupted index the target's falling-edge interrupt could never fire again and the link would wedge. The bail-out now calls serial_input() first, mirroring the normal exit path. Both targets re-compiled. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The bitbang split serial drivers index
split_transaction_tablewith values that are either taken straight off the wire or insufficiently bounded:platforms/chibios/drivers/serial.c,interrupt_handler()(the target-side ISR) read the transaction index from the wire withserial_read_byte()and used it to indexsplit_transaction_tablewith no bounds check at all. A corrupted or hostile index results in an out-of-bounds struct read and an arbitrary function-pointer call throughtrans->slave_callback.initiate_transaction()in the same file checked the index with>instead of>=againstNUM_TOTAL_TRANSACTIONS, allowing an index one entry past the end of the table.platforms/avr/drivers/serial.chad the same>vs>=off-by-one in both the target ISR andsoft_serial_transaction().The new ISR check bails out before the table is indexed. The early-out releases the serial line back to input and the
chSysLockFromISR()critical section the same way the normal exit path does (the shared-memory lock is a cleanup-attribute guard and releases itself);sync_send()earlier in the handler leaves the pin driven as output, so skipping that release would leave the line stuck driven and prevent the target's falling-edge interrupt from ever firing again. Dropping the transaction on the target side causes the initiator's transaction to fail, the same outcome as any other corrupt transaction.The vendor UART driver (
platforms/chibios/drivers/serial_protocol.c) already performs this check correctly with>=; this change brings the bitbang drivers to parity with it.Types of Changes
Checklist
qmk format-capplied, diff is noise-free.developbranch.crkbd/rev1:default(AVR soft serial, buildsplatforms/avr/drivers/serial.c) andhandwired/splittest/bluepill:bitbang(ChibiOS withSERIAL_DRIVER = bitbang, buildsplatforms/chibios/drivers/serial.c).