Skip to content

Commit 7146f83

Browse files
author
Jyri Sarha
committed
ipc3: get_drv: Check comp_type also when driver is matched with UUID
Add a safe guard against malformed SOF_IPC_TPLG_COMP_NEW messages where the UUID matched driver type does not match the component type in the message. Also moves the !drv check outside of &drivers->lock block. Reported-by: Curtis Malainey <cujomalainey@chromium.org> Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent b267012 commit 7146f83

4 files changed

Lines changed: 22 additions & 7 deletions

File tree

src/audio/module_adapter/module/volume/volume.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1671,7 +1671,7 @@ static struct module_interface gain_interface = {
16711671
.free = volume_free
16721672
};
16731673

1674-
DECLARE_MODULE_ADAPTER(gain_interface, gain_uuid, gain_tr);
1674+
DECLARE_MODULE_ADAPTER_WITH_TYPE(gain_interface, gain_uuid, gain_tr, SOF_COMP_VOLUME);
16751675
SOF_MODULE_INIT(gain, sys_comp_module_gain_interface_init);
16761676
#endif
16771677
#endif

src/audio/src/src.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,5 +1058,5 @@ static struct module_interface src_interface = {
10581058
.free = src_free,
10591059
};
10601060

1061-
DECLARE_MODULE_ADAPTER(src_interface, src_uuid, src_tr);
1061+
DECLARE_MODULE_ADAPTER_WITH_TYPE(src_interface, src_uuid, src_tr, SOF_COMP_SRC);
10621062
SOF_MODULE_INIT(src, sys_comp_module_src_interface_init);

src/include/sof/audio/module_adapter/module/generic.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
(value)); \
3434
} while (0)
3535

36-
#define DECLARE_MODULE_ADAPTER(adapter, uuid, tr) \
36+
#define DECLARE_MODULE_ADAPTER_WITH_TYPE(adapter, uuid, tr, comp_type) \
3737
static struct comp_dev *module_##adapter##_shim_new(const struct comp_driver *drv, \
3838
const struct comp_ipc_config *config, \
3939
const void *spec) \
@@ -42,7 +42,7 @@ static struct comp_dev *module_##adapter##_shim_new(const struct comp_driver *dr
4242
} \
4343
\
4444
static const struct comp_driver comp_##adapter##_module = { \
45-
.type = SOF_COMP_MODULE_ADAPTER, \
45+
.type = comp_type, \
4646
.uid = SOF_RT_UUID(uuid), \
4747
.tctx = &(tr), \
4848
.ops = { \
@@ -75,6 +75,9 @@ UT_STATIC void sys_comp_module_##adapter##_init(void) \
7575
\
7676
DECLARE_MODULE(sys_comp_module_##adapter##_init)
7777

78+
#define DECLARE_MODULE_ADAPTER(adapter, uuid, tr) \
79+
DECLARE_MODULE_ADAPTER_WITH_TYPE(adapter, uuid, tr, SOF_COMP_MODULE_ADAPTER)
80+
7881
/**
7982
* \enum module_state
8083
* \brief Module-specific states

src/ipc/ipc3/helper.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ static const struct comp_driver *get_drv(struct sof_ipc_comp *comp)
121121
goto out;
122122
}
123123

124+
if (comp->type > SOF_COMP_MODULE_ADAPTER) {
125+
tr_err(&comp_tr, "Bad component type: %d\n", comp->type);
126+
goto out;
127+
}
128+
124129
/* search driver list with UUID */
125130
key = k_spin_lock(&drivers->lock);
126131

@@ -134,16 +139,23 @@ static const struct comp_driver *get_drv(struct sof_ipc_comp *comp)
134139
}
135140
}
136141

137-
if (!drv)
142+
k_spin_unlock(&drivers->lock, key);
143+
144+
if (!drv) {
138145
tr_err(&comp_tr,
139146
"get_drv(): the provided UUID (%8x%8x%8x%8x) doesn't match to any driver!",
140147
*(uint32_t *)(&comp_ext->uuid[0]),
141148
*(uint32_t *)(&comp_ext->uuid[4]),
142149
*(uint32_t *)(&comp_ext->uuid[8]),
143150
*(uint32_t *)(&comp_ext->uuid[12]));
151+
goto out;
152+
}
144153

145-
k_spin_unlock(&drivers->lock, key);
146-
154+
if (drv->type != comp->type && drv->type != SOF_COMP_MODULE_ADAPTER) {
155+
tr_err(&comp_tr, "get_drv(): Found %pU driver and IPC type differ %d != %d",
156+
drv->tctx->uuid_p, drv->type, comp->type);
157+
drv = NULL;
158+
}
147159
out:
148160
if (drv)
149161
tr_dbg(&comp_tr, "get_drv(), found driver type %d, uuid %pU",

0 commit comments

Comments
 (0)