* [PATCH] sound/isa/sb/emu8000: Fix a use after free in snd_emu8000_create_mixer
@ 2021-04-26 13:11 Lv Yunlong
2021-04-26 14:23 ` Takashi Iwai
0 siblings, 1 reply; 3+ messages in thread
From: Lv Yunlong @ 2021-04-26 13:11 UTC (permalink / raw)
To: perex, tiwai; +Cc: alsa-devel, linux-kernel, Lv Yunlong
Our code analyzer reported a uaf.
In snd_emu8000_create_mixer, the callee snd_ctl_add(..,emu->controls[i])
calls snd_ctl_add_replace(.., kcontrol,..). Inside snd_ctl_add_replace(),
if error happens, kcontrol will be freed by snd_ctl_free_one(kcontrol).
Then emu->controls[i] points to a freed memory, and the execution comes
to __error branch of snd_emu8000_create_mixer. The freed emu->controls[i]
is used in snd_ctl_remove(card, emu->controls[i]).
My patch set emu->controls[i] to NULL if snd_ctl_add() failed to avoid
the uaf.
Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
---
sound/isa/sb/emu8000.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/sound/isa/sb/emu8000.c b/sound/isa/sb/emu8000.c
index 0aa545ac6e60..1c90421a88dc 100644
--- a/sound/isa/sb/emu8000.c
+++ b/sound/isa/sb/emu8000.c
@@ -1029,8 +1029,10 @@ snd_emu8000_create_mixer(struct snd_card *card, struct snd_emu8000 *emu)
memset(emu->controls, 0, sizeof(emu->controls));
for (i = 0; i < EMU8000_NUM_CONTROLS; i++) {
- if ((err = snd_ctl_add(card, emu->controls[i] = snd_ctl_new1(mixer_defs[i], emu))) < 0)
+ if ((err = snd_ctl_add(card, emu->controls[i] = snd_ctl_new1(mixer_defs[i], emu))) < 0) {
+ emu->controls[i] = NULL;
goto __error;
+ }
}
return 0;
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] sound/isa/sb/emu8000: Fix a use after free in snd_emu8000_create_mixer
2021-04-26 13:11 [PATCH] sound/isa/sb/emu8000: Fix a use after free in snd_emu8000_create_mixer Lv Yunlong
@ 2021-04-26 14:23 ` Takashi Iwai
2021-04-26 14:38 ` Jaroslav Kysela
0 siblings, 1 reply; 3+ messages in thread
From: Takashi Iwai @ 2021-04-26 14:23 UTC (permalink / raw)
To: Lv Yunlong; +Cc: perex, tiwai, alsa-devel, linux-kernel
On Mon, 26 Apr 2021 15:11:29 +0200,
Lv Yunlong wrote:
>
> Our code analyzer reported a uaf.
>
> In snd_emu8000_create_mixer, the callee snd_ctl_add(..,emu->controls[i])
> calls snd_ctl_add_replace(.., kcontrol,..). Inside snd_ctl_add_replace(),
> if error happens, kcontrol will be freed by snd_ctl_free_one(kcontrol).
> Then emu->controls[i] points to a freed memory, and the execution comes
> to __error branch of snd_emu8000_create_mixer. The freed emu->controls[i]
> is used in snd_ctl_remove(card, emu->controls[i]).
>
> My patch set emu->controls[i] to NULL if snd_ctl_add() failed to avoid
> the uaf.
>
> Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
Thanks, applied now.
The bug was hard to be seen due to the coding style, so we'd need a
cleanup, but it's a different story...
Takashi
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] sound/isa/sb/emu8000: Fix a use after free in snd_emu8000_create_mixer
2021-04-26 14:23 ` Takashi Iwai
@ 2021-04-26 14:38 ` Jaroslav Kysela
0 siblings, 0 replies; 3+ messages in thread
From: Jaroslav Kysela @ 2021-04-26 14:38 UTC (permalink / raw)
To: Takashi Iwai, Lv Yunlong; +Cc: tiwai, alsa-devel, linux-kernel
Dne 26. 04. 21 v 16:23 Takashi Iwai napsal(a):
> On Mon, 26 Apr 2021 15:11:29 +0200,
> Lv Yunlong wrote:
>>
>> Our code analyzer reported a uaf.
>>
>> In snd_emu8000_create_mixer, the callee snd_ctl_add(..,emu->controls[i])
>> calls snd_ctl_add_replace(.., kcontrol,..). Inside snd_ctl_add_replace(),
>> if error happens, kcontrol will be freed by snd_ctl_free_one(kcontrol).
>> Then emu->controls[i] points to a freed memory, and the execution comes
>> to __error branch of snd_emu8000_create_mixer. The freed emu->controls[i]
>> is used in snd_ctl_remove(card, emu->controls[i]).
>>
>> My patch set emu->controls[i] to NULL if snd_ctl_add() failed to avoid
>> the uaf.
>>
>> Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
>
> Thanks, applied now.
>
> The bug was hard to be seen due to the coding style, so we'd need a
> cleanup, but it's a different story...
Yes, it would be better to assign the return value from snd_ctl_new1 to a
local variable and set emu->controls[i] only when everything succeeds.
Jaroslav
--
Jaroslav Kysela <perex@perex.cz>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-04-26 14:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-26 13:11 [PATCH] sound/isa/sb/emu8000: Fix a use after free in snd_emu8000_create_mixer Lv Yunlong
2021-04-26 14:23 ` Takashi Iwai
2021-04-26 14:38 ` Jaroslav Kysela
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).