Skip to content

PIOLib security audit - #233

Merged
pelwell merged 4 commits into
masterfrom
piosecure
Nov 19, 2026
Merged

pelwell merged 4 commits into
masterfrom
piosecure

Conversation

@pelwell

@pelwell pelwell commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

Fix a number of issues found by a security audit of PIOLib.

pelwell and others added 4 commits November 18, 2026 11:31
O_CLOEXEC was being passed to open() as the mode, where it is ignored,
rather than as one of the flags. As a result the PIO device was
inherited by any program that the application went on to execute.

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
The instructions of a program are copied into the fixed-size buffer in
the ioctl arguments, but the only checks on the length of the program
were parameter assertions, which are normally compiled out. A program
of more than 32 instructions would therefore overflow the buffer on the
stack by up to 446 bytes.

Add a real check, and fail the operation if the program is too big or
doesn't fit at the requested offset.

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
An IRQ thread was created for every PIO instance as soon as it was
opened, and it then blocked indefinitely in the kernel, waiting for an
interrupt. pio_close did nothing to stop it, and because the thread was
still using the device, closing the file descriptor didn't release the
device either - any state machines, programs and DMA channels remained
claimed until the process exited. Should the thread ever wake up, it
would then use a file descriptor number that could by then refer to a
completely different file.

Instead, only start the thread when the first IRQ is mapped, make it
wait with a timeout so that it can notice a request to stop, and have
pio_close stop it and wait for it before closing the device. Forget the
file descriptor once it has been closed.

While here:
- don't call a NULL handler if an interrupt arrives when no handler is
  registered,
- remove the leftover debug thread in the RP1 backend, which competed
  with the real IRQ thread for interrupts and discarded any it got,
- initialise the handle lock statically, so that it can also protect
  pio_init against concurrent callers.

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
pio_irq_map indexes the per-instance IRQ table with a value that was
only checked by a parameter assertion, which is normally compiled out
(and was off by one). Make it a real check, and also check the IRQ
number returned by the kernel.

Make sure that pio_init stays within the instance and IRQ handler
tables, however many devices and IRQs there are, and that
pio_open_helper doesn't read beyond the end of the instance table.

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
@pelwell
pelwell merged commit 0ed52a9 into master Nov 19, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant