linux/sound
Takashi Iwai fbd3eb7f66 ALSA: control: Add verification for kctl accesses
The current implementation of ALSA control API fully relies on the
callbacks of each driver, and there is no verification of the values
passed via API.  This patch is an attempt to improve the situation
slightly by adding the validation code for the values stored via info
and get callbacks.

The patch adds a new kconfig, CONFIG_SND_CTL_VALIDATION.  It depends
on CONFIG_SND_DEBUG and off as default since the validation would
require a slight overhead including the additional call of info
callback at each get callback invocation.

When this config is enabled, the values stored by each info callback
invocation are verified, namely:
- Whether the info type is valid
- Whether the number of enum items is non-zero
- Whether the given info count is within the allowed boundary

Similarly, the values stored at each get callback are verified as
well:
- Whether the values are within the given range
- Whether the values are aligned with the given step
- Whether any further changes are seen in the data array over the
  given info count

The last point helps identifying a possibly invalid data type access,
typically a case where the info callback declares the type being
SNDRV_CTL_ELEM_TYPE_ENUMERATED while the get/put callbacks store
the values in value.integer.value[] array.

When a validation fails, the ALSA core logs an error message including
the device and the control ID, and the API call also returns an
error.  So, with the new validation turned on, the driver behavior
difference may be visible on user-space, too -- it's intentional,
though, so that we can catch an error more clearly.

The patch also introduces a new ctl access type,
SNDRV_CTL_ELEM_ACCESS_SKIP_CHECK.  A driver may pass this flag with
other access bits to indicate that the ctl element won't be verified.
It's useful when a driver code is specially written to access the data
greater than info->count size by some reason.  For example, this flag
is actually set now in HD-audio HDMI codec driver which needs to clear
the data array in the case of the disconnected monitor.

Also, the PCM channel-map helper code is slightly modified to avoid
the false-positive hit by this validation code, too.

Link: https://lore.kernel.org/r/20200104083556.27789-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2020-01-04 09:37:59 +01:00
..
ac97 ALSA: ac97: Constify snd_ac97_bus_ops definitions 2020-01-03 09:24:11 +01:00
aoa ALSA: aoa: Constify snd_kcontrol_new items 2020-01-03 09:24:22 +01:00
arm ALSA: arm: Constify snd_ac97_bus_ops definitions 2020-01-03 09:24:11 +01:00
atmel ALSA: atmel: Constify snd_ac97_bus_ops definitions 2020-01-03 09:24:12 +01:00
core ALSA: control: Add verification for kctl accesses 2020-01-04 09:37:59 +01:00
drivers ALSA: seq: oss: Constify snd_seq_oss_callback definitions 2020-01-03 09:24:41 +01:00
firewire ALSA: firewire: Drop superfluous ioctl PCM ops 2019-12-11 07:25:27 +01:00
hda Merge branch 'for-linus' into for-next 2019-12-18 20:07:43 +01:00
i2c ALSA: i2c: Constify snd_kcontrol_new items 2020-01-03 09:24:24 +01:00
isa ALSA: isa: Constify snd_kcontrol_new items 2020-01-03 09:24:25 +01:00
mips ALSA: mips: Constify snd_device_ops definitions 2020-01-03 09:24:02 +01:00
oss compat_ioctl: remove translation for sound ioctls 2019-10-23 17:23:45 +02:00
parisc ALSA: parisc: Constify snd_kcontrol_new items 2020-01-03 09:24:35 +01:00
pci ALSA: control: Add verification for kctl accesses 2020-01-04 09:37:59 +01:00
pcmcia ALSA: vx: Constify snd_vx_hardware and snd_vx_ops definitions 2020-01-03 09:24:20 +01:00
ppc ALSA: ppc: Constify snd_kcontrol_new items 2020-01-03 09:24:32 +01:00
sh ALSA: sh: Constify snd_device_ops definitions 2020-01-03 09:24:05 +01:00
soc Merge branch 'for-linus' into for-next 2019-12-18 20:07:43 +01:00
sparc ALSA: sparc: Constify snd_kcontrol_new items 2020-01-03 09:24:33 +01:00
spi ALSA: spi: Constify snd_kcontrol_new items 2020-01-03 09:24:34 +01:00
synth ALSA: seq: oss: Constify snd_seq_oss_callback definitions 2020-01-03 09:24:41 +01:00
usb ALSA: usx2y: Constify struct snd_usb_audio_quirk entries 2020-01-03 09:24:41 +01:00
x86 ALSA: x86: Drop superfluous ioctl PCM ops 2019-12-11 07:25:34 +01:00
xen ALSA: xen: Drop superfluous ioctl PCM ops 2019-12-11 07:25:35 +01:00
ac97_bus.c ALSA: ac97: Treat snd_ac97_bus_ops as const 2020-01-03 09:24:08 +01:00
Kconfig treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
last.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
Makefile
sound_core.c sound: fix a memory leak bug 2019-08-08 08:18:32 +02:00