firmware: cs_dsp: Don't allow writes to read-only controls
authorRichard Fitzgerald <rf@opensource.cirrus.com>
Tue, 2 Jul 2024 11:08:09 +0000 (12:08 +0100)
committerMark Brown <broonie@kernel.org>
Tue, 2 Jul 2024 12:59:35 +0000 (13:59 +0100)
Add a check to cs_dsp_coeff_write_ctrl() to abort if the control
is not writeable.

The cs_dsp code originated as an ASoC driver (wm_adsp) where all
controls were exported as ALSA controls. It relied on ALSA to
enforce the read-only permission. Now that the code has been
separated from ALSA/ASoC it must perform its own permission check.

This isn't currently causing any problems so there shouldn't be any
need to backport this. If the client of cs_dsp exposes the control as
an ALSA control, it should set permissions on that ALSA control to
protect it. The few uses of cs_dsp_coeff_write_ctrl() inside drivers
are for writable controls.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Link: https://patch.msgid.link/20240702110809.16836-1-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/firmware/cirrus/cs_dsp.c

index 0d139e4de37c786c4a0fbbc3829cf8c79c90bbf0..d2aa0980ed78006241a1019a076a6f4b35acf174 100644 (file)
@@ -796,6 +796,9 @@ int cs_dsp_coeff_write_ctrl(struct cs_dsp_coeff_ctl *ctl,
 
        lockdep_assert_held(&ctl->dsp->pwr_lock);
 
+       if (ctl->flags && !(ctl->flags & WMFW_CTL_FLAG_WRITEABLE))
+               return -EPERM;
+
        if (len + off * sizeof(u32) > ctl->len)
                return -EINVAL;