linux/sound/pci
Kai Vehmanen e81478bbe7 ALSA: hda: fix general protection fault in azx_runtime_idle
Fix a corner case between PCI device driver remove callback and
runtime PM idle callback.

Following sequence of events can happen:
  - at azx_create, context is allocated with devm_kzalloc() and
    stored as pci_set_drvdata()
  - user-space requests to unbind audio driver
  - dd.c:__device_release_driver() calls PCI remove
  - pci-driver.c:pci_device_remove() calls the audio
    driver azx_remove() callback and this is completed
  - pci-driver.c:pm_runtime_put_sync() leads to a call
    to rpm_idle() which again calls azx_runtime_idle()
  - the azx context object, as returned by dev_get_drvdata(),
    is no longer valid
  -> access fault in azx_runtime_idle when executing
	struct snd_card *card = dev_get_drvdata(dev);
	chip = card->private_data;
	if (chip->disabled || hda->init_failed)

This was discovered by i915_module_load test with 5.15.0 based
linux-next tree.

Example log caught by i915_module_load test with linux-next
https://intel-gfx-ci.01.org/tree/linux-next/

<4> [264.038232] general protection fault, probably for non-canonical address 0x6b6b6b6b6b6b73f0: 0000 [#1] PREEMPT SMP NOPTI
<4> [264.038248] CPU: 0 PID: 5374 Comm: i915_module_loa Not tainted 5.15.0-next-20211109-gc8109c2ba35e-next-20211109 #1
[...]
<4> [264.038267] RIP: 0010:azx_runtime_idle+0x12/0x60 [snd_hda_intel]
[...]
<4> [264.038355] Call Trace:
<4> [264.038359]  <TASK>
<4> [264.038362]  __rpm_callback+0x3d/0x110
<4> [264.038371]  rpm_idle+0x27f/0x380
<4> [264.038376]  __pm_runtime_idle+0x3b/0x100
<4> [264.038382]  pci_device_remove+0x6d/0xa0
<4> [264.038388]  device_release_driver_internal+0xef/0x1e0
<4> [264.038395]  unbind_store+0xeb/0x120
<4> [264.038400]  kernfs_fop_write_iter+0x11a/0x1c0

Fix the issue by setting drvdata to NULL at end of azx_remove().

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Link: https://lore.kernel.org/r/20211110210307.1172004-1-kai.vehmanen@linux.intel.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2021-11-10 22:48:31 +01:00
..
ac97 ALSA: ac97: Fix assignment in if condition 2021-06-09 17:30:02 +02:00
ali5451 ALSA: ali5451: Allocate resources with device-managed APIs 2021-07-19 16:17:00 +02:00
asihpi ALSA: asihpi: fix comment syntax in file headers 2021-03-18 10:13:25 +01:00
au88x0 ALSA: au88x0: Allocate resources with device-managed APIs 2021-07-19 16:16:51 +02:00
aw2 ALSA: aw2: Allocate resources with device-managed APIs 2021-07-19 16:16:52 +02:00
ca0106 ALSA: ca0106: Allocate resources with device-managed APIs 2021-07-19 16:16:53 +02:00
cs46xx ALSA: pci: cs46xx: Fix set up buffer type properly 2021-08-09 10:04:05 +02:00
cs5535audio ALSA: cs5535audio: Allocate resources with device-managed APIs 2021-07-19 16:16:55 +02:00
ctxfi ALSA: control - add generic LED API 2021-03-30 17:42:40 +02:00
echoaudio ALSA: echoaudio: Allocate resources with device-managed APIs 2021-07-19 16:16:55 +02:00
emu10k1 ALSA: emu10k1x: Allocate resources with device-managed APIs 2021-07-19 16:16:58 +02:00
hda ALSA: hda: fix general protection fault in azx_runtime_idle 2021-11-10 22:48:31 +01:00
ice1712 ALSA: ice1724: Allocate resources with device-managed APIs 2021-07-19 16:17:00 +02:00
korg1212 ALSA: pci/korg1212: completely remove 'set but not used' warnings 2021-08-05 08:23:38 +02:00
lola ALSA: lola: Allocate resources with device-managed APIs 2021-07-19 16:17:02 +02:00
lx6464es ALSA: lx6464es: Allocate resources with device-managed APIs 2021-07-19 16:17:03 +02:00
mixart ALSA: mixart: Fix assignment in if condition 2021-06-09 17:30:15 +02:00
nm256 ALSA: nm256: Fix error return code in snd_nm256_create() 2021-07-20 16:08:21 +02:00
oxygen ALSA: oxygen: Allocate resources with device-managed APIs 2021-07-19 16:17:04 +02:00
pcxhr ALSA: pcxhr: "fix" PCXHR_REG_TO_PORT definition 2021-09-16 11:09:04 +02:00
riptide ALSA: riptide: Allocate resources with device-managed APIs 2021-07-19 16:17:05 +02:00
rme9652 ALSA: pci: rme: Fix unaligned buffer addresses 2021-11-08 15:58:31 +01:00
trident ALSA: trident: Allocate resources with device-managed APIs 2021-07-19 16:17:08 +02:00
vx222 ALSA: vx222: fix null-ptr-deref 2021-09-07 07:13:19 +02:00
ymfpci ALSA: ymfpci: Allocate resources with device-managed APIs 2021-07-19 16:17:11 +02:00
ad1889.c ALSA: ad1889: Allocate resources with device-managed APIs 2021-07-19 16:16:38 +02:00
ad1889.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
ak4531_codec.c ALSA: ak4531: Fix assignment in if condition 2021-06-09 17:29:49 +02:00
als300.c ALSA: als300: Fix missing chip initialization 2021-07-21 00:31:56 +02:00
als4000.c ALSA: als4000: Allocate resources with device-managed APIs 2021-07-19 16:16:40 +02:00
atiixp_modem.c ALSA: atiixp: Allocate resources with device-managed APIs 2021-07-19 16:16:37 +02:00
atiixp.c ALSA: atiixp: Allocate resources with device-managed APIs 2021-07-19 16:16:37 +02:00
azt3328.c ALSA: azt3328: Allocate resources with device-managed APIs 2021-07-19 16:16:40 +02:00
azt3328.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
bt87x.c ALSA: bt87x: Allocate resources with device-managed APIs 2021-07-19 16:16:41 +02:00
cmipci.c ALSA: cmipci: Allocate resources with device-managed APIs 2021-07-19 16:16:42 +02:00
cs4281.c ALSA: cs4281: Fix missing chip initialization 2021-07-21 00:31:39 +02:00
cs5530.c ALSA: cs5530: Allocate resources with device-managed APIs 2021-07-19 16:16:43 +02:00
ens1370.c ALSA: ens137x: Allocate resources with device-managed APIs 2021-07-19 16:16:44 +02:00
ens1371.c
es1938.c ALSA: es1938: Allocate resources with device-managed APIs 2021-07-19 16:16:44 +02:00
es1968.c ALSA: es1968: Allocate resources with device-managed APIs 2021-07-19 16:16:45 +02:00
fm801.c ALSA: fm801: Allocate resources with device-managed APIs 2021-07-19 16:16:46 +02:00
intel8x0.c ALSA: memalloc: Correctly name as WC 2021-08-04 08:07:58 +02:00
intel8x0m.c ALSA: intel8x0: Allocate resources with device-managed APIs 2021-07-19 16:16:36 +02:00
Kconfig ALSA: ISA: not for M68K 2021-10-17 09:03:20 +02:00
maestro3.c ALSA: maestro3: Allocate resources with device-managed APIs 2021-07-19 16:16:46 +02:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
rme32.c ALSA: rme32: Allocate resources with device-managed APIs 2021-07-19 16:16:47 +02:00
rme96.c ALSA: rme96: Allocate resources with device-managed APIs 2021-07-19 16:16:48 +02:00
sis7019.c ALSA: sis7019: Allocate resources with device-managed APIs 2021-07-19 16:16:48 +02:00
sis7019.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 274 2019-06-05 17:30:30 +02:00
sonicvibes.c ALSA: sonicvibes: Allocate resources with device-managed APIs 2021-07-19 16:16:49 +02:00
via82xx_modem.c ALSA: via82xx: Allocate resources with device-managed APIs 2021-07-19 16:16:50 +02:00
via82xx.c ALSA: via82xx: Allocate resources with device-managed APIs 2021-07-19 16:16:50 +02:00