linux_dsm_epyc7002/sound/pci
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_res_table definition 2020-01-03 09:24:37 +01:00
ali5451 ALSA: pci: Constify snd_kcontrol_new items 2020-01-03 09:24:28 +01:00
asihpi ALSA: asihpi: Drop superfluous ioctl PCM ops 2019-12-11 07:25:30 +01:00
au88x0 ALSA: pci: Constify snd_kcontrol_new items 2020-01-03 09:24:28 +01:00
aw2 ALSA: pci: Constify snd_device_ops definitions 2020-01-03 09:23:56 +01:00
ca0106 ALSA: ca0106: Constify snd_ca0106_details 2020-01-03 09:24:38 +01:00
cs46xx ALSA: pci: Constify snd_kcontrol_new items 2020-01-03 09:24:28 +01:00
cs5535audio ALSA: pci: Constify snd_kcontrol_new items 2020-01-03 09:24:28 +01:00
ctxfi ALSA: pci: Constify snd_pci_quirk tables 2020-01-03 09:24:45 +01:00
echoaudio ALSA: pci: Constify snd_device_ops definitions 2020-01-03 09:23:56 +01:00
emu10k1 ALSA: emu10k1: Constify snd_emu_chip_details 2020-01-03 09:24:43 +01:00
hda ALSA: control: Add verification for kctl accesses 2020-01-04 09:37:59 +01:00
ice1712 ALSA: ice1712: Constify wm-specific tables 2020-01-03 09:24:39 +01:00
korg1212 ALSA: pci: Constify snd_kcontrol_new items 2020-01-03 09:24:28 +01:00
lola ALSA: pci: Constify snd_device_ops definitions 2020-01-03 09:23:56 +01:00
lx6464es ALSA: pci: Constify snd_device_ops definitions 2020-01-03 09:23:56 +01:00
mixart ALSA: info: Make snd_info_entry_ops as const 2020-01-03 09:24:18 +01:00
nm256 ALSA: pci: Constify snd_pci_quirk tables 2020-01-03 09:24:45 +01:00
oxygen ALSA: oxygen: Support PCM sync_stop 2019-12-11 07:25:50 +01:00
pcxhr ALSA: pci: Constify snd_device_ops definitions 2020-01-03 09:23:56 +01:00
riptide ALSA: pci: Constify snd_ac97_bus_ops definitions 2020-01-03 09:24:13 +01:00
rme9652 ALSA: pci: Constify snd_kcontrol_new items 2020-01-03 09:24:28 +01:00
trident ALSA: pci: Constify snd_ac97_bus_ops definitions 2020-01-03 09:24:13 +01:00
vx222 ALSA: vx: Constify snd_vx_hardware and snd_vx_ops definitions 2020-01-03 09:24:20 +01:00
ymfpci ALSA: pci: Constify snd_kcontrol_new items 2020-01-03 09:24:28 +01:00
ad1889.c ALSA: pci: Constify snd_ac97_bus_ops definitions 2020-01-03 09:24:13 +01:00
ad1889.h
ak4531_codec.c ALSA: pci: Constify snd_kcontrol_new items 2020-01-03 09:24:28 +01:00
als300.c ALSA: pci: Constify snd_ac97_bus_ops definitions 2020-01-03 09:24:13 +01:00
als4000.c ALSA: pci: Drop superfluous ioctl PCM ops 2019-12-11 07:25:31 +01:00
atiixp_modem.c ALSA: pci: Constify snd_ac97_bus_ops definitions 2020-01-03 09:24:13 +01:00
atiixp.c ALSA: pci: Constify snd_pci_quirk tables 2020-01-03 09:24:45 +01:00
azt3328.c ALSA: pci: Constify snd_kcontrol_new items 2020-01-03 09:24:28 +01:00
azt3328.h
bt87x.c ALSA: bt87x: Constify snd_bt87x_boards 2020-01-03 09:24:42 +01:00
cmipci.c ALSA: pci: Constify snd_kcontrol_new items 2020-01-03 09:24:28 +01:00
cs4281.c ALSA: info: Make snd_info_entry_ops as const 2020-01-03 09:24:18 +01:00
cs5530.c ALSA: pci: Constify snd_device_ops definitions 2020-01-03 09:23:56 +01:00
ens1370.c ALSA: pci: Constify snd_pci_quirk tables 2020-01-03 09:24:45 +01:00
ens1371.c
es1938.c ALSA: pci: Constify snd_kcontrol_new items 2020-01-03 09:24:28 +01:00
es1968.c ALSA: es1968: Constify snd_es1968_tea575x_gpios 2020-01-03 09:24:43 +01:00
fm801.c ALSA: fm801: Constify snd_fm801_tea575x_gpios 2020-01-03 09:24:44 +01:00
intel8x0.c ALSA: pci: Constify snd_pci_quirk tables 2020-01-03 09:24:45 +01:00
intel8x0m.c ALSA: pci: Constify snd_ac97_bus_ops definitions 2020-01-03 09:24:13 +01:00
Kconfig
maestro3.c ALSA: pci: Constify snd_pci_quirk tables 2020-01-03 09:24:45 +01:00
Makefile
rme32.c ALSA: pci: Constify snd_kcontrol_new items 2020-01-03 09:24:28 +01:00
rme96.c ALSA: pci: Constify snd_kcontrol_new items 2020-01-03 09:24:28 +01:00
sis7019.c ALSA: pci: Constify snd_ac97_bus_ops definitions 2020-01-03 09:24:13 +01:00
sis7019.h
sonicvibes.c ALSA: pci: Constify snd_kcontrol_new items 2020-01-03 09:24:28 +01:00
via82xx_modem.c ALSA: pci: Constify snd_ac97_bus_ops definitions 2020-01-03 09:24:13 +01:00
via82xx.c ALSA: pci: Constify snd_pci_quirk tables 2020-01-03 09:24:45 +01:00