linux_dsm_epyc7002/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
aoa ALSA: aoa: Constify snd_kcontrol_new items 2020-01-03 09:24:22 +01:00
arm
atmel
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
hda
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
oss
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
soc
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
xen
ac97_bus.c
Kconfig
last.c
Makefile
sound_core.c