Skip to content

Commit

Permalink
ALSA: sb: Fix potential double-free of CSP mixer elements
Browse files Browse the repository at this point in the history
snd_sb_qsound_destroy() contains the calls of removing the previously
created mixer controls, but it doesn't clear the pointers.  As
snd_sb_qsound_destroy() itself may be repeatedly called via ioctl,
this could lead to double-free potentially.

Fix it by clearing the struct fields properly afterwards.

Link: https://lore.kernel.org/r/20210608140540.17885-4-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
  • Loading branch information
tiwai committed Jun 9, 2021
1 parent 36e7b12 commit c305366
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions sound/isa/sb/sb16_csp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1077,10 +1077,14 @@ static void snd_sb_qsound_destroy(struct snd_sb_csp * p)
card = p->chip->card;

down_write(&card->controls_rwsem);
if (p->qsound_switch)
if (p->qsound_switch) {
snd_ctl_remove(card, p->qsound_switch);
if (p->qsound_space)
p->qsound_switch = NULL;
}
if (p->qsound_space) {
snd_ctl_remove(card, p->qsound_space);
p->qsound_space = NULL;
}
up_write(&card->controls_rwsem);

/* cancel pending transfer of QSound parameters */
Expand Down

0 comments on commit c305366

Please sign in to comment.