linux-stable/sound
Duoming Zhou 61d4787692 ALSA: sh: aica: reorder cleanup operations to avoid UAF bugs
commit 051e0840ff upstream.

The dreamcastcard->timer could schedule the spu_dma_work and the
spu_dma_work could also arm the dreamcastcard->timer.

When the snd_pcm_substream is closing, the aica_channel will be
deallocated. But it could still be dereferenced in the worker
thread. The reason is that del_timer() will return directly
regardless of whether the timer handler is running or not and
the worker could be rescheduled in the timer handler. As a result,
the UAF bug will happen. The racy situation is shown below:

      (Thread 1)                 |      (Thread 2)
snd_aicapcm_pcm_close()          |
 ...                             |  run_spu_dma() //worker
                                 |    mod_timer()
  flush_work()                   |
  del_timer()                    |  aica_period_elapsed() //timer
  kfree(dreamcastcard->channel)  |    schedule_work()
                                 |  run_spu_dma() //worker
  ...                            |    dreamcastcard->channel-> //USE

In order to mitigate this bug and other possible corner cases,
call mod_timer() conditionally in run_spu_dma(), then implement
PCM sync_stop op to cancel both the timer and worker. The sync_stop
op will be called from PCM core appropriately when needed.

Fixes: 198de43d75 ("[ALSA] Add ALSA support for the SEGA Dreamcast PCM device")
Suggested-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Message-ID: <20240326094238.95442-1-duoming@zju.edu.cn>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-04-03 15:28:59 +02:00
..
ac97 ALSA: ac97: set variables dev_attr_vendor_id to static 2023-08-02 09:27:39 +02:00
aoa ALSA: aoa: Fix typos in PCM fix patch 2023-08-18 09:09:39 +02:00
arm
atmel ALSA: Explicitly include correct DT includes 2023-07-16 14:50:56 +02:00
core ALSA: seq: fix function cast warnings 2024-03-26 18:19:47 -04:00
drivers ALSA: pcmtest: stop timer before buffer is released 2024-01-20 11:51:42 +01:00
firewire ALSA: firewire-lib: fix to check cycle continuity 2024-03-06 14:48:39 +00:00
hda ALSA: hda: intel-dspcfg: add filters for ARL-S and ARL 2024-02-05 20:14:27 +00:00
i2c
isa ALSA: cs4231: Fix -Wformat-truncation warning for longname string 2023-09-15 13:23:01 +02:00
mips
oss
parisc
pci ALSA: hda/tas2781: add locks to kcontrols 2024-04-03 15:28:53 +02:00
pcmcia
ppc ALSA: Explicitly include correct DT includes 2023-07-16 14:50:56 +02:00
sh ALSA: sh: aica: reorder cleanup operations to avoid UAF bugs 2024-04-03 15:28:59 +02:00
soc ASoC: amd: yc: Revert "Fix non-functional mic on Lenovo 21J2" 2024-04-03 15:28:46 +02:00
sparc ALSA: Explicitly include correct DT includes 2023-07-16 14:50:56 +02:00
spi
synth
usb ALSA: usb-audio: Stop parsing channels bits when all channels are found. 2024-03-26 18:19:58 -04:00
virtio
x86
xen ALSA: xen: Fix -Wformat-truncation warning 2023-09-15 13:21:35 +02:00
Kconfig This pull request contains the following changes for UML: 2023-09-04 11:32:21 -07:00
Makefile
ac97_bus.c
last.c
sound_core.c sound: make all 'class' structures const 2023-06-21 07:29:10 +02:00