Skip to content

Commit 3331bcd

Browse files
plbossartbroonie
authored andcommitted
ASoC: SOF: control: fix size checks for ext_bytes control .get()
cppcheck complains twice: sound/soc/sof/control.c:436:2: style: Assignment of function parameter has no effect outside the function. [uselessAssignmentArg] size -= sizeof(const struct snd_ctl_tlv); ^ sound/soc/sof/control.c:436:7: style: Variable 'size' is assigned a value that is never used. [unreadVariable] size -= sizeof(const struct snd_ctl_tlv); Somehow we dropped the checks for the size argument when upstreaming the code, somewhere between v5 and v6. Re-add a size check to avoid providing userspace with more data that it asked for. Also fix all error codes, we should return -ENOSPC instead of -EINVAL. Fixes: c3078f5 ('ASoC: SOF: Add Sound Open Firmware KControl support') Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com> Reviewed-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com> Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com> Link: https://lore.kernel.org/r/20200921110814.2910477-2-kai.vehmanen@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 97ee967 commit 3331bcd

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎sound/soc/sof/control.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,9 @@ int snd_sof_bytes_ext_get(struct snd_kcontrol *kcontrol,
432432
* Decrement the limit by ext bytes header size to
433433
* ensure the user space buffer is not exceeded.
434434
*/
435-
size -= sizeof(const struct snd_ctl_tlv);
435+
if (size < sizeof(struct snd_ctl_tlv))
436+
return -ENOSPC;
437+
size -= sizeof(struct snd_ctl_tlv);
436438

437439
/* set the ABI header values */
438440
cdata->data->magic = SOF_ABI_MAGIC;
@@ -448,6 +450,10 @@ int snd_sof_bytes_ext_get(struct snd_kcontrol *kcontrol,
448450

449451
data_size = cdata->data->size + sizeof(const struct sof_abi_hdr);
450452

453+
/* make sure we don't exceed size provided by user space for data */
454+
if (data_size > size)
455+
return -ENOSPC;
456+
451457
header.numid = scontrol->cmd;
452458
header.length = data_size;
453459
if (copy_to_user(tlvd, &header, sizeof(const struct snd_ctl_tlv)))

0 commit comments

Comments
 (0)