Commit 435c0d4
committed
platform: posix: fix MAILBOX_*_BASE byte-pointer units
On every other SOF platform, MAILBOX_HOSTBOX_BASE, MAILBOX_DSPBOX_BASE,
MAILBOX_STREAM_BASE and MAILBOX_TRACE_BASE expand to a byte address
(an integer literal or SRAM_INBOX_BASE), so the generic mailbox API in
sof/src/include/sof/lib/mailbox.h can do plain byte arithmetic --
`MAILBOX_HOSTBOX_BASE + offset` and `memcpy(_s)(..., bytes)` -- and
land on the intended byte.
On POSIX, the bases were defined as `(&posix_hostbox[0])` etc., i.e.
plain `uint32_t *` expressions. Pointer arithmetic on a `uint32_t *`
scales the addend by `sizeof(uint32_t) == 4`, so
`MAILBOX_HOSTBOX_BASE + offset` silently addressed byte
`offset * 4`, four times further into the buffer than the API
contract.
This was latent for years because MAILBOX_HOSTBOX_SIZE was hard-coded
to 1024 on POSIX while the largest byte offset used through
mailbox_hostbox_read() in IPC3 mailbox_validate() (offset = 8, bytes =
SOF_IPC_MSG_MAX_SIZE - 8 = 376) stays within 32 + 376 = 408 bytes,
comfortably under 1024. After commit "fuzz: posix: size MAILBOX_HOSTBOX
from SOF_IPC_MSG_MAX_SIZE" (384 in IPC3 builds, 4096 in IPC4 builds),
the scaled IPC3 read overruns the now exactly right-sized backing buffer
by 24 bytes, which AddressSanitizer catches as a global-buffer-overflow
inside libc memcpy called from mailbox_hostbox_read() -> memcpy_s().
Reproducer (with the new 2-byte framing): two-byte fuzz input "\x80\x01"
(msgsz=384, header-only message).
Cast each base to `(uint8_t *)` so byte-offset arithmetic is honoured
and the macro semantics match every other platform. The `uint32_t[]`
backing storage is kept for natural alignment; only how the macro
exposes that storage changes.
Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>1 parent 3ed1b24 commit 435c0d4
1 file changed
Lines changed: 16 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
15 | 27 | | |
16 | 28 | | |
17 | | - | |
| 29 | + | |
18 | 30 | | |
19 | 31 | | |
20 | 32 | | |
21 | | - | |
| 33 | + | |
22 | 34 | | |
23 | 35 | | |
24 | 36 | | |
25 | | - | |
| 37 | + | |
26 | 38 | | |
27 | 39 | | |
28 | | - | |
| 40 | + | |
29 | 41 | | |
30 | 42 | | |
31 | 43 | | |
| |||
0 commit comments