kernel_samsung_a53x/sound/core
Takashi Iwai c6bb997852 ALSA: info: Fix potential deadlock at disconnection
commit c7a60651953359f98dbf24b43e1bf561e1573ed4 upstream.

As reported recently, ALSA core info helper may cause a deadlock at
the forced device disconnection during the procfs operation.

The proc_remove() (that is called from the snd_card_disconnect()
helper) has a synchronization of the pending procfs accesses via
wait_for_completion().  Meanwhile, ALSA procfs helper takes the global
mutex_lock(&info_mutex) at both the proc_open callback and
snd_card_info_disconnect() helper.  Since the proc_open can't finish
due to the mutex lock, wait_for_completion() never returns, either,
hence it deadlocks.

	TASK#1				TASK#2
	proc_reg_open()
	  takes use_pde()
	snd_info_text_entry_open()
					snd_card_disconnect()
					snd_info_card_disconnect()
					  takes mutex_lock(&info_mutex)
					proc_remove()
					wait_for_completion(unused_pde)
					  ... waiting task#1 closes
	mutex_lock(&info_mutex)
		=> DEADLOCK

This patch is a workaround for avoiding the deadlock scenario above.

The basic strategy is to move proc_remove() call outside the mutex
lock.  proc_remove() can work gracefully without extra locking, and it
can delete the tree recursively alone.  So, we call proc_remove() at
snd_info_card_disconnection() at first, then delete the rest resources
recursively within the info_mutex lock.

After the change, the function snd_info_disconnect() doesn't do
disconnection by itself any longer, but it merely clears the procfs
pointer.  So rename the function to snd_info_clear_entries() for
avoiding confusion.

The similar change is applied to snd_info_free_entry(), too.  Since
the proc_remove() is called only conditionally with the non-NULL
entry->p, it's skipped after the snd_info_clear_entries() call.

Reported-by: Shinhyung Kang <s47.kang@samsung.com>
Closes: https://lore.kernel.org/r/664457955.21699345385931.JavaMail.epsvc@epcpadp4
Reviewed-by: Jaroslav Kysela <perex@perex.cz>
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20231109141954.4283-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-11-18 11:43:26 +01:00
..
oss Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
seq Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
compress_offload.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
control.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
control_compat.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ctljack.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
device.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
hrtimer.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
hwdep.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
hwdep_compat.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
info.c ALSA: info: Fix potential deadlock at disconnection 2024-11-18 11:43:26 +01:00
info_oss.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
init.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
isadma.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
jack.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
Kconfig Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
Makefile Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
memalloc.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
memory.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
misc.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pcm.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pcm_compat.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pcm_dmaengine.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pcm_drm_eld.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pcm_iec958.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pcm_lib.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pcm_local.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pcm_memory.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pcm_misc.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pcm_native.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pcm_param_trace.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pcm_timer.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pcm_trace.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
rawmidi.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
rawmidi_compat.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
seq_device.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sgbuf.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sound.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sound_oss.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
timer.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
timer_compat.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
vmaster.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00