1 From a3aa60d511746bd6c0d0366d4eb90a7998bcde8b Mon Sep 17 00:00:00 2001
2 From: Bo Chen <chenbo@pdx.edu>
3 Date: Thu, 31 May 2018 15:35:18 -0700
4 Subject: ALSA: hda - Handle kzalloc() failure in snd_hda_attach_pcm_stream()
6 From: Bo Chen <chenbo@pdx.edu>
8 commit a3aa60d511746bd6c0d0366d4eb90a7998bcde8b upstream.
10 When 'kzalloc()' fails in 'snd_hda_attach_pcm_stream()', a new pcm instance is
11 created without setting its operators via 'snd_pcm_set_ops()'. Following
12 operations on the new pcm instance can trigger kernel null pointer dereferences
13 and cause kernel oops.
15 This bug was found with my work on building a gray-box fault-injection tool for
16 linux-kernel-module binaries. A kernel null pointer dereference was confirmed
17 from line 'substream->ops->open()' in function 'snd_pcm_open_substream()' in
18 file 'sound/core/pcm_native.c'.
20 This patch fixes the bug by calling 'snd_device_free()' in the error handling
21 path of 'kzalloc()', which removes the new pcm instance from the snd card before
22 returns with an error code.
24 Signed-off-by: Bo Chen <chenbo@pdx.edu>
25 Cc: <stable@vger.kernel.org>
26 Signed-off-by: Takashi Iwai <tiwai@suse.de>
27 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
30 sound/pci/hda/hda_controller.c | 4 +++-
31 1 file changed, 3 insertions(+), 1 deletion(-)
33 --- a/sound/pci/hda/hda_controller.c
34 +++ b/sound/pci/hda/hda_controller.c
35 @@ -915,8 +915,10 @@ static int azx_attach_pcm_stream(struct
37 strlcpy(pcm->name, cpcm->name, sizeof(pcm->name));
38 apcm = kzalloc(sizeof(*apcm), GFP_KERNEL);
41 + snd_device_free(chip->card, pcm);