Skip to content

Commit a3aa60d

Browse files
likebreathtiwai
authored andcommitted
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: Bo Chen <[email protected]> Cc: <[email protected]> Signed-off-by: Takashi Iwai <[email protected]>
1 parent 9ee92f5 commit a3aa60d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

sound/pci/hda/hda_controller.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,8 +748,10 @@ int snd_hda_attach_pcm_stream(struct hda_bus *_bus, struct hda_codec *codec,
748748
return err;
749749
strlcpy(pcm->name, cpcm->name, sizeof(pcm->name));
750750
apcm = kzalloc(sizeof(*apcm), GFP_KERNEL);
751-
if (apcm == NULL)
751+
if (apcm == NULL) {
752+
snd_device_free(chip->card, pcm);
752753
return -ENOMEM;
754+
}
753755
apcm->chip = chip;
754756
apcm->pcm = pcm;
755757
apcm->codec = codec;

0 commit comments

Comments
 (0)