Commit a3aa60d5 authored by Bo Chen's avatar Bo Chen Committed by Takashi Iwai

ALSA: hda - Handle kzalloc() failure in snd_hda_attach_pcm_stream()

When 'kzalloc()' fails in 'snd_hda_attach_pcm_stream()', a new pcm instance is
created without setting its operators via 'snd_pcm_set_ops()'. Following
operations on the new pcm instance can trigger kernel null pointer dereferences
and cause kernel oops.

This bug was found with my work on building a gray-box fault-injection tool for
linux-kernel-module binaries. A kernel null pointer dereference was confirmed
from line 'substream->ops->open()' in function 'snd_pcm_open_substream()' in
file 'sound/core/pcm_native.c'.

This patch fixes the bug by calling 'snd_device_free()' in the error handling
path of 'kzalloc()', which removes the new pcm instance from the snd card before
returns with an error code.
Signed-off-by: default avatarBo Chen <chenbo@pdx.edu>
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 9ee92f53
...@@ -748,8 +748,10 @@ int snd_hda_attach_pcm_stream(struct hda_bus *_bus, struct hda_codec *codec, ...@@ -748,8 +748,10 @@ int snd_hda_attach_pcm_stream(struct hda_bus *_bus, struct hda_codec *codec,
return err; return err;
strlcpy(pcm->name, cpcm->name, sizeof(pcm->name)); strlcpy(pcm->name, cpcm->name, sizeof(pcm->name));
apcm = kzalloc(sizeof(*apcm), GFP_KERNEL); apcm = kzalloc(sizeof(*apcm), GFP_KERNEL);
if (apcm == NULL) if (apcm == NULL) {
snd_device_free(chip->card, pcm);
return -ENOMEM; return -ENOMEM;
}
apcm->chip = chip; apcm->chip = chip;
apcm->pcm = pcm; apcm->pcm = pcm;
apcm->codec = codec; apcm->codec = codec;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment