Skip to content

Commit 5f8cf71

Browse files
benquiketiwai
authored andcommitted
ALSA: usb-audio: Fix UAF decrement if card has no live interfaces in card.c
If a USB sound card reports 0 interfaces, an error condition is triggered and the function usb_audio_probe errors out. In the error path, there was a use-after-free vulnerability where the memory object of the card was first freed, followed by a decrement of the number of active chips. Moving the decrement above the atomic_dec fixes the UAF. [ The original problem was introduced in 3.1 kernel, while it was developed in a different form. The Fixes tag below indicates the original commit but it doesn't mean that the patch is applicable cleanly. -- tiwai ] Fixes: 362e4e4 ("ALSA: usb-audio - clear chip->probing on error exit") Reported-by: Hui Peng <benquike@gmail.com> Reported-by: Mathias Payer <mathias.payer@nebelwelt.net> Signed-off-by: Hui Peng <benquike@gmail.com> Signed-off-by: Mathias Payer <mathias.payer@nebelwelt.net> Cc: <stable@vger.kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 54947cd commit 5f8cf71

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

sound/usb/card.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,9 +682,12 @@ static int usb_audio_probe(struct usb_interface *intf,
682682

683683
__error:
684684
if (chip) {
685+
/* chip->active is inside the chip->card object,
686+
* decrement before memory is possibly returned.
687+
*/
688+
atomic_dec(&chip->active);
685689
if (!chip->num_interfaces)
686690
snd_card_free(chip->card);
687-
atomic_dec(&chip->active);
688691
}
689692
mutex_unlock(&register_mutex);
690693
return err;

0 commit comments

Comments
 (0)