Skip to content

Commit 2ca2101

Browse files
plbossartbroonie
authored andcommitted
ASoC: SOF: control: add size checks for ext_bytes control .put()
Make sure the TLV header and size are consistent before copying from userspace. 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-4-kai.vehmanen@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent ec5a976 commit 2ca2101

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎sound/soc/sof/control.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ int snd_sof_bytes_ext_put(struct snd_kcontrol *kcontrol,
300300
const struct snd_ctl_tlv __user *tlvd =
301301
(const struct snd_ctl_tlv __user *)binary_data;
302302

303+
/* make sure we have at least a header */
304+
if (size < sizeof(struct snd_ctl_tlv))
305+
return -EINVAL;
306+
303307
/*
304308
* The beginning of bytes data contains a header from where
305309
* the length (as bytes) is needed to know the correct copy
@@ -308,6 +312,13 @@ int snd_sof_bytes_ext_put(struct snd_kcontrol *kcontrol,
308312
if (copy_from_user(&header, tlvd, sizeof(const struct snd_ctl_tlv)))
309313
return -EFAULT;
310314

315+
/* make sure TLV info is consistent */
316+
if (header.length + sizeof(struct snd_ctl_tlv) > size) {
317+
dev_err_ratelimited(scomp->dev, "error: inconsistent TLV, data %d + header %zu > %d\n",
318+
header.length, sizeof(struct snd_ctl_tlv), size);
319+
return -EINVAL;
320+
}
321+
311322
/* be->max is coming from topology */
312323
if (header.length > be->max) {
313324
dev_err_ratelimited(scomp->dev, "error: Bytes data size %d exceeds max %d.\n",

0 commit comments

Comments
 (0)