Skip to content

multikernel: read a message's sizes once from its ring slot - #59

Merged
congwang-mk merged 1 commit into
multikernel:masterfrom
pro-utkarshM:fix/mk-msg-len-snapshot
Nov 24, 2026
Merged

congwang-mk merged 1 commit into
multikernel:masterfrom
pro-utkarshM:fix/mk-msg-len-snapshot

Conversation

@pro-utkarshM

@pro-utkarshM pro-utkarshM commented Nov 24, 2026 •

Copy link
Copy Markdown

mk_message_type_ipi_callback() works on the ring slot itself, which the sending kernel can still write. It checks payload_len against data_size, then reads both again to compute the bound and to pass the length to the handler. A sender that rewrites either between the check and the use makes the handler read past the slot, in hard IRQ context of the receiving kernel.

Read each size once with READ_ONCE(), check that copy against both bounds, and pass it on.

Tested: RISC-V QEMU virt (aia=aplic-imsic, OpenSBI v1.8.1), #49 head b4be1bf with #55–#59 applied: all message traffic (halts, hotplug requests and ACKs, NIC lending) still works, 28 spawns. A sender that rewrites the sizes was not tested at runtime. Builds on current master (fca2f47): x86_64 clang W=1 with no new warnings, also with PCI=n and with MULTIKERNEL=n; checkpatch --strict clean.

mk_message_type_ipi_callback() runs on the ring slot itself, which
the sending kernel can still write. It checks payload_len against
data_size and then reads both again: to compute the bound, and to
hand the length to the handler. A sender that rewrites either one
between the check and the use makes the handler read past the slot,
from hard IRQ context of the receiving kernel. data_size was checked
against MK_MAX_DATA_SIZE by the drain, but is read again here too.

Read each size once with READ_ONCE(), check that copy against both
bounds, and pass it on.

Fixes: 4f676d2 ("multikernel: Add messaging layer for inter-kernel communication")
Signed-off-by: Utkarsh Maurya <projects.utkarshMaurya@gmail.com>
@pro-utkarshM

Copy link
Copy Markdown
Author

Tested at runtime on RISC-V QEMU (#49 head + #55–#59): a test-only hook in the spawn sent 2000 messages with payload_len = 0xffffff00 and flipped the slot's data_size between its real value and 4 GiB until the host consumed it. Without this patch, 506 of them reached the handler with payload_len 4294967040, because the drain checks data_size and the callback reads it again. With it: 0, and halt still works afterwards. clang already merged the repeated reads inside the callback; the re-read after the drain is the one that matters. A handler like vsock's copies payload_len bytes.

@congwang-mk
congwang-mk merged commit 235301f into multikernel:master Nov 24, 2026
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.

2 participants