Skip to contentSkip to conversation

ALSA: hda/intel: Add sanity check for BAR0 size

PATCH New Takashi Iwai 1 participant 1 message Aug 13 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: hda/intel: Add sanity check for BAR0 size

The recent reports from syzkaller showed that we can bind any wild PCI device to HD-audio controller, and if PCI BAR of the device is too small, it may lead to a crash, as the driver believes as if the full register range were accessible.

For avoiding such a problem, add a safeguard before the actual probe to check the available BAR0 size.

Note that the threshold (0x200) is chosen to cover all needed registers at probing. But this doesn't mean that it would cover fully for all features including the extended ones.

---
 sound/hda/controllers/intel.c | 9 +++++++++
 1 file changed, 9 insertions(+)
sound/hda/controllers/intel.c +9 -0
index 8f592032ac15..1e6d97e08fee 100644
@@ -2197,6 +2197,15 @@ static int azx_probe(struct pci_dev *pci,
 		dev_warn(&pci->dev, "dmic_detect option is deprecated, pass snd-intel-dspcfg.dsp_driver=1 option instead\n");
 	}
 
+	/* A sanity check against wild device binding;
+	 * here the range 0x200 is enough for the registers used at probe,
+	 * but it doesn't mean covering all HD-audio registers
+	 */
+	if (pci_resource_len(pci, 0) < 0x200) {
+		dev_err(&pci->dev, "Too small PCI BAR0\n");
+		return -EINVAL;
+	}
+
 	err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
 			   0, &card);
 	if (err < 0) {
Signature · 1 line
2.55.0