MiniTransceiver memory corruption: FD-count mismatch stack overflow and unbounded message size heap overflow
Categories
(Core :: IPC, defect)
Tracking
()
People
(Reporter: trongpham1803, Unassigned)
Details
(Keywords: reporter-external)
Attachments
(1 file)
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36
Steps to reproduce:
-
Verify the affected source in ipc/glue/MiniTransceiver.cpp:
- kMaxDataSize = 8 * 1024
- kMaxNumFds = 16
- MiniTransceiver::Recv() allocates int all_fds[kMaxNumFds]
- Recv() calls RecvData(..., all_fds, kMaxDataSize, ...)
- RecvFDs() uses a debug-only MOZ_ASSERT before memcpy()
- RecvData() uses msgsz from IPC::Message::MessageSize() to set iov_len without checking msgsz <= aBufSize
-
Reproduce Bug 1 with the attached C PoC:
gcc -O0 -fno-stack-protector -Wall -Wextra -o poc_fd minitransceiver_fd_overflow.c
./poc_fd 24 -
Reproduce Bug 2 with the attached Python PoC:
PYTHONUNBUFFERED=1 python3 minitransceiver_heap_overflow.py 16384
-
Runtime verification:
Downloaded official Firefox 153.0 Linux64 from Mozilla.
/tmp/firefox/firefox --version
Mozilla Firefox 153.0Started Firefox 153.0 headless with a temporary profile and confirmed the forkserver process exists.
Actual results:
Bug 1: Stack out-of-bounds write via FD count mismatch
MiniTransceiver::Recv() creates a stack buffer:
int all_fds[kMaxNumFds]; // kMaxNumFds = 16
but calls:
RecvData(databuf.get(), kMaxDataSize, &msgsz, all_fds, kMaxDataSize, &num_all_fds)
The fifth argument is aMaxFds, but kMaxDataSize (8192) is passed instead of kMaxNumFds (16). RecvData() then initializes a control buffer large enough for 8192 FDs, and RecvFDs() copies received FDs into all_fds.
The only guard is:
MOZ_ASSERT(num_all_fds + num_part_fds <= aMaxFds);
This is compiled out in release builds.
Observed PoC output:
[parent] received 24 fds in cmsg
[parent] buffer overflow? YES - STACK OVERFLOW!
[parent] sentinel_before=0000001b sentinel_after=0000001a
*** STACK CORRUPTED (before buffer) ***
*** STACK CORRUPTED (after buffer) ***
Bug 2: Heap out-of-bounds write via unbounded IPC message size
RecvData() parses msgsz from the IPC message header using IPC::Message::MessageSize(), then uses it to set:
hdr.msg_iov->iov_base = aDataBuf + total_readed;
hdr.msg_iov->iov_len = (msgsz == 0 ? aBufSize : msgsz) - total_readed;
There is no runtime check that msgsz <= aBufSize before recvmsg().
Observed PoC output:
[receiver] parsed msgsz=16416 from crafted header
[receiver] iter=2 total_readed=8192 iov_base=PAST_BUFFER iov_len=8224
*** HEAP BUFFER OVERFLOW DETECTED ***
8224 bytes written past heap buffer
free(): invalid next size (normal)
Impact context:
Firefox 153.0 runtime inspection showed the forkserver running with Seccomp=0, while Web Content processes ran with Seccomp=2 and NoNewPrivs=1. That makes this a memory corruption issue in a security-sensitive IPC boundary. Direct web-content triggering / sandbox escape is not demonstrated.
Expected results:
MiniTransceiver should reject malformed IPC messages instead of writing past fixed-size buffers.
Expected behavior:
-
Recv() should pass kMaxNumFds as the aMaxFds argument:
RecvData(databuf.get(), kMaxDataSize, &msgsz, all_fds, kMaxNumFds, &num_all_fds)
-
RecvData() should reject any message size greater than the receive buffer capacity before setting iov_len:
if (msgsz != 0 && msgsz - total_readed > aBufSize - total_readed) {
return false;
} -
Security-critical bounds checks should be runtime checks, not MOZ_ASSERT only:
if (num_all_fds + num_part_fds > aMaxFds) return 0;
if (total_readed > aBufSize) return false;
Updated•4 months ago
|
Comment 1•4 months ago
|
||
Thank you for the report. This issue has been determined to be a duplicate of bug 2029466.
Hi Smith,
I submitted two bugs. Do you mean they're both duplicates?
Updated•2 months ago
|
Updated•2 months ago
|
Description
•