]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/3.18.114/alsa-hda-handle-kzalloc-failure-in-snd_hda_attach_pcm_stream.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 3.18.114 / alsa-hda-handle-kzalloc-failure-in-snd_hda_attach_pcm_stream.patch
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()
5
6 From: Bo Chen <chenbo@pdx.edu>
7
8 commit a3aa60d511746bd6c0d0366d4eb90a7998bcde8b upstream.
9
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.
14
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'.
19
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.
23
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>
28
29 ---
30 sound/pci/hda/hda_controller.c | 4 +++-
31 1 file changed, 3 insertions(+), 1 deletion(-)
32
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
36 return err;
37 strlcpy(pcm->name, cpcm->name, sizeof(pcm->name));
38 apcm = kzalloc(sizeof(*apcm), GFP_KERNEL);
39 - if (apcm == NULL)
40 + if (apcm == NULL) {
41 + snd_device_free(chip->card, pcm);
42 return -ENOMEM;
43 + }
44 apcm->chip = chip;
45 apcm->pcm = pcm;
46 apcm->codec = codec;