ALSA: pcm: unconditionally check if appl_ptr is in 0..boundary range
authorPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Fri, 19 Nov 2021 23:08:49 +0000 (17:08 -0600)
committerMark Brown <broonie@kernel.org>
Wed, 24 Nov 2021 12:57:17 +0000 (12:57 +0000)
In some cases, the appl_ptr passed by userspace is not checked before
being used. This patch adds an unconditional check and returns an
error code should the appl_ptr exceed the ALSA 'boundary'.

Suggested-by: Takashi Iwai <tiwai@suse.de>
Reviewed-by: Takashi Iwai <tiwai@suse.de>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/20211119230852.206310-2-pierre-louis.bossart@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/core/pcm_lib.c

index 4f4b4739f9871813353ca7183ff3b89e5d5766b6..fdd992772b20c4e1eec27ebcde4e6e582db4afe1 100644 (file)
@@ -2133,6 +2133,9 @@ int pcm_lib_apply_appl_ptr(struct snd_pcm_substream *substream,
        if (old_appl_ptr == appl_ptr)
                return 0;
 
+       if (appl_ptr >= runtime->boundary)
+               return -EINVAL;
+
        runtime->control->appl_ptr = appl_ptr;
        if (substream->ops->ack) {
                ret = substream->ops->ack(substream);