Skip to content

Commit 2a46e84

Browse files
Bruce Xuwebgeek1234
Bruce Xu
authored andcommitted
ALSA: core: Fix card races between register and disconnect
commit 2a3f7221acddfe1caa9ff09b3a8158c39b2fdeac upstream. There is a small race window in the card disconnection code that allows the registration of another card with the very same card id. This leads to a warning in procfs creation as caught by syzkaller. The problem is that we delete snd_cards and snd_cards_lock entries at the very beginning of the disconnection procedure. This makes the slot available to be assigned for another card object while the disconnection procedure is being processed. Then it becomes possible to issue a procfs registration with the existing file name although we check the conflict beforehand. The fix is simply to move the snd_cards and snd_cards_lock clearances at the end of the disconnection procedure. The references to these entries are merely either from the global proc files like /proc/asound/cards or from the card registration / disconnection, so it should be fine to shift at the very end. Bug 2802685 CVE-2019-15214 Change-Id: Ie78b2026ec500e1c6057b4fc02590c4884682a4d Reported-by: [email protected] Cc: <[email protected]> Signed-off-by: Takashi Iwai <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Reviewed-on: https://git-master.nvidia.com/r/c/linux-4.9/+/2274090 (cherry picked from commit d0227abb6db4b91f72d3bf2607a43dc1613cbe62) Reviewed-on: https://git-master.nvidia.com/r/c/linux-4.9/+/2337659 Reviewed-by: automaticguardword <[email protected]> Reviewed-by: Bibek Basu <[email protected]> Reviewed-by: mobile promotions <[email protected]> GVS: Gerrit_Virtual_Submit Tested-by: Amulya Yarlagadda <[email protected]> Tested-by: mobile promotions <[email protected]>
1 parent a128ec3 commit 2a46e84

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Diff for: sound/core/init.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -408,14 +408,7 @@ int snd_card_disconnect(struct snd_card *card)
408408
card->shutdown = 1;
409409
spin_unlock(&card->files_lock);
410410

411-
/* phase 1: disable fops (user space) operations for ALSA API */
412-
mutex_lock(&snd_card_mutex);
413-
snd_cards[card->number] = NULL;
414-
clear_bit(card->number, snd_cards_lock);
415-
mutex_unlock(&snd_card_mutex);
416-
417-
/* phase 2: replace file->f_op with special dummy operations */
418-
411+
/* replace file->f_op with special dummy operations */
419412
spin_lock(&card->files_lock);
420413
list_for_each_entry(mfile, &card->files_list, list) {
421414
/* it's critical part, use endless loop */
@@ -431,7 +424,7 @@ int snd_card_disconnect(struct snd_card *card)
431424
}
432425
spin_unlock(&card->files_lock);
433426

434-
/* phase 3: notify all connected devices about disconnection */
427+
/* notify all connected devices about disconnection */
435428
/* at this point, they cannot respond to any calls except release() */
436429

437430
#if IS_ENABLED(CONFIG_SND_MIXER_OSS)
@@ -447,6 +440,13 @@ int snd_card_disconnect(struct snd_card *card)
447440
device_del(&card->card_dev);
448441
card->registered = false;
449442
}
443+
444+
/* disable fops (user space) operations for ALSA API */
445+
mutex_lock(&snd_card_mutex);
446+
snd_cards[card->number] = NULL;
447+
clear_bit(card->number, snd_cards_lock);
448+
mutex_unlock(&snd_card_mutex);
449+
450450
#ifdef CONFIG_PM
451451
wake_up(&card->power_sleep);
452452
#endif

0 commit comments

Comments
 (0)