Commit dcde013
committed
audio: module_adapter: fix sizeof(pointer) and underflow in module_ext_init_decode
Three weaknesses compose into a single chain in module_ext_init_decode()
that allows a crafted IPC4 ModuleInit payload to corrupt spec->size and
spec->data before they are consumed by module_adapter_init_data().
The size guard used the wrong sizeof operand:
if (spec->size < sizeof(ext_init)) /* sizeof(pointer) = 4, not 12 */
This accepted any payload >= 4 bytes even though the struct header is 12
bytes. Additionally, ext_init->data_obj_array was dereferenced before
the guard ran, allowing the object-walk loop to be skipped with no size
validation. When the loop is skipped, the unconditional spec->size
adjustment:
spec->size -= (unsigned char *)obj - spec->data; /* obj = data + 12 */
produces an unsigned underflow for spec->size in [4, 11], yielding
values around 0xFFFFFFFC. The corrupted spec is then passed to
module_adapter_init_data() where the inflated size bypasses the base_cfg
guard and dst->base_cfg is populated from mailbox bytes beyond the
declared payload boundary.
Found by semgrep static analysis, confirmed by manual review of the
caller chain through module_adapter_init_data(), and verified with
prepared tests.
Fixes:
1. Move size guard before ext_init dereference so spec->size is
validated against sizeof(*ext_init) before any field is read.
2. Correct sizeof operand from sizeof(ext_init) to sizeof(*ext_init)
(4 bytes → 12 bytes).
3. Guard the unconditional spec adjustment — compute consumed bytes and
return -EINVAL if consumed > spec->size before subtracting.
4. Add upper-bound check in module_adapter_init_data() — reject cfgsz
greater than MAILBOX_HOSTBOX_SIZE as a defense-in-depth measure.
Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>1 parent 8d75e2c commit dcde013
1 file changed
Lines changed: 23 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
31 | | - | |
32 | | - | |
33 | | - | |
| 32 | + | |
34 | 33 | | |
| 34 | + | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
38 | 41 | | |
39 | | - | |
| 42 | + | |
40 | 43 | | |
41 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
42 | 48 | | |
43 | 49 | | |
44 | 50 | | |
| |||
103 | 109 | | |
104 | 110 | | |
105 | 111 | | |
106 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
107 | 121 | | |
108 | 122 | | |
109 | 123 | | |
| |||
132 | 146 | | |
133 | 147 | | |
134 | 148 | | |
135 | | - | |
| 149 | + | |
| 150 | + | |
136 | 151 | | |
| 152 | + | |
137 | 153 | | |
138 | 154 | | |
139 | 155 | | |
| |||
0 commit comments