From b9e130fd8c4893368613fb57ec87a0d70460f6b5 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Fri, 10 Jan 2025 21:09:37 +0200 Subject: [PATCH] spa: alsa: do not allow setting Route that is not in current profile When setting Route param, check that the route actually is part of the active profile. Also, check that the device given corresponds to the given route, before setting properties. acp_device_set_port() also checks this, but we shouldn't allow updating properties of Routes in non-active profiles. Setting ports or applying props on devices not part of the profile can do unexpected things e.g. alter mixer settings. --- spa/plugins/alsa/alsa-acp-device.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/spa/plugins/alsa/alsa-acp-device.c b/spa/plugins/alsa/alsa-acp-device.c index b145ecf78..5d46feed4 100644 --- a/spa/plugins/alsa/alsa-acp-device.c +++ b/spa/plugins/alsa/alsa-acp-device.c @@ -761,6 +761,32 @@ static uint32_t find_route_by_name(struct acp_card *card, const char *name) return SPA_ID_INVALID; } +static bool check_active_profile_port(struct impl *this, uint32_t device, uint32_t port_index) +{ + struct acp_port *p; + uint32_t i; + + if (port_index >= this->card->n_ports) + return false; + p = this->card->ports[port_index]; + + /* Port must be in active profile */ + for (i = 0; i < p->n_profiles; i++) + if (p->profiles[i]->index == this->card->active_profile_index) + break; + if (i == p->n_profiles) + return false; + + /* Port must correspond to the device */ + for (i = 0; i< p->n_devices; i++) + if (p->devices[i]->index == device) + break; + if (i == p->n_devices) + return false; + + return true; +} + static int impl_set_param(void *object, uint32_t id, uint32_t flags, const struct spa_pod *param) @@ -838,6 +864,8 @@ static int impl_set_param(void *object, idx = find_route_by_name(this->card, name); if (idx == SPA_ID_INVALID) return -EINVAL; + if (!check_active_profile_port(this, device, idx)) + return -EINVAL; acp_device_set_port(dev, idx, save ? ACP_PORT_SAVE : 0); if (props)