Skip to contentSkip to conversation

ALSA: Check card index validity at probe

PATCH New Takashi Iwai 1 participant 7 messages Aug 6 Sound

lore
Share & tools
lore
#0 lore raw

cover ALSA: Check card index validity at probe

There are a few other platform-based drivers that don't check the validity of the dev->id value as the card index, which may lead to OOB accesses. Let's paper over them all.

Takashi

===

Takashi Iwai (6):
ALSA: aloop: Check card index validity at probe
ALSA: mpu401: Check card index validity at probe
ALSA: serial-u16550: Check card index validity at probe
ALSA: virmidi: Check card index validity at probe
ALSA: mts64: Check card index validity at probe
ALSA: portman2x4: Check card index validity at probe

 sound/drivers/aloop.c         | 6 ++++++
 sound/drivers/mpu401/mpu401.c | 6 ++++++
 sound/drivers/mts64.c         | 6 ++++++
 sound/drivers/portman2x4.c    | 6 ++++++
 sound/drivers/serial-u16550.c | 6 ++++++
 sound/drivers/virmidi.c       | 6 ++++++
 6 files changed, 36 insertions(+)
Signature · 1 line
2.55.0
#1 lore raw

PATCH 1/6 ALSA: aloop: Check card index validity at probe

aloop driver blindly trusts that the given devptr->id value is within the proper card index range at probe. It's OK for the devices the driver itself creates at the module probe time, but if the device is bound manually via sysfs interface, this could be -1 as "none", and this leads to OOB access for index[] and other parameters.

Add a sanity check for the card index and warn/correct it if it's a value out of the range.

---
 sound/drivers/aloop.c | 6 ++++++
 1 file changed, 6 insertions(+)
sound/drivers/aloop.c +6 -0
index d520d83c2577..92ef821ddbeb 100644
@@ -1914,6 +1914,12 @@ static int loopback_probe(struct platform_device *devptr)
 	int dev = devptr->id;
 	int err;
 
+	if (dev < 0 || dev >= SNDRV_CARDS) {
+		dev_warn(&devptr->dev,
+			 "Invalid card index %d, using default 0\n", dev);
+		dev = 0;
+	}
+
 	err = snd_devm_card_new(&devptr->dev, index[dev], id[dev], THIS_MODULE,
 				sizeof(struct loopback), &card);
 	if (err < 0)
Signature · 1 line
2.55.0
#2 lore raw

PATCH 2/6 ALSA: mpu401: Check card index validity at probe

In reply to Takashi Iwai

mpu401 driver blindly trusts that the given devptr->id value is within the proper card index range at probe. It's OK for the devices the driver itself creates at the module probe time, but if the device is bound manually via sysfs interface, this could be -1 as "none", and this leads to OOB access for index[] and other parameters.

Add a sanity check for the card index and warn/correct it if it's a value out of the range.

---
 sound/drivers/mpu401/mpu401.c | 6 ++++++
 1 file changed, 6 insertions(+)
sound/drivers/mpu401/mpu401.c +6 -0
index c217c427bf1e..b93291ad067a 100644
@@ -89,6 +89,12 @@ static int snd_mpu401_probe(struct platform_device *devptr)
 	int err;
 	struct snd_card *card;
 
+	if (dev < 0 || dev >= SNDRV_CARDS) {
+		dev_warn(&devptr->dev,
+			 "Invalid card index %d, using default 0\n", dev);
+		dev = 0;
+	}
+
 	if (port[dev] == SNDRV_AUTO_PORT) {
 		dev_err(&devptr->dev, "specify port\n");
 		return -EINVAL;
Signature · 1 line
2.55.0
#3 lore raw

PATCH 3/6 ALSA: serial-u16550: Check card index validity at probe

In reply to Takashi Iwai

serial-u16550 driver blindly trusts that the given devptr->id value is within the proper card index range at probe. It's OK for the devices the driver itself creates at the module probe time, but if the device is bound manually via sysfs interface, this could be -1 as "none", and this leads to OOB access for index[] and other parameters.

Add a sanity check for the card index and warn/correct it if it's a value out of the range.

---
 sound/drivers/serial-u16550.c | 6 ++++++
 1 file changed, 6 insertions(+)
sound/drivers/serial-u16550.c +6 -0
index 3c28961091b1..cc9c325df910 100644
@@ -846,6 +846,12 @@ static int snd_serial_probe(struct platform_device *devptr)
 	int err;
 	int dev = devptr->id;
 
+	if (dev < 0 || dev >= SNDRV_CARDS) {
+		dev_warn(&devptr->dev,
+			 "Invalid card index %d, using default 0\n", dev);
+		dev = 0;
+	}
+
 	switch (adaptor[dev]) {
 	case SNDRV_SERIAL_SOUNDCANVAS:
 		ins[dev] = 1;
Signature · 1 line
2.55.0
#4 lore raw

PATCH 4/6 ALSA: virmidi: Check card index validity at probe

In reply to Takashi Iwai

virmidi driver blindly trusts that the given devptr->id value is within the proper card index range at probe. It's OK for the devices the driver itself creates at the module probe time, but if the device is bound manually via sysfs interface, this could be -1 as "none", and this leads to OOB access for index[] and other parameters.

Add a sanity check for the card index and warn/correct it if it's a value out of the range.

---
 sound/drivers/virmidi.c | 6 ++++++
 1 file changed, 6 insertions(+)
sound/drivers/virmidi.c +6 -0
index a204f42d1026..70e16105f1c4 100644
@@ -75,6 +75,12 @@ static int snd_virmidi_probe(struct platform_device *devptr)
 	int idx, err;
 	int dev = devptr->id;
 
+	if (dev < 0 || dev >= SNDRV_CARDS) {
+		dev_warn(&devptr->dev,
+			 "Invalid card index %d, using default 0\n", dev);
+		dev = 0;
+	}
+
 	err = snd_devm_card_new(&devptr->dev, index[dev], id[dev], THIS_MODULE,
 				sizeof(struct snd_card_virmidi), &card);
 	if (err < 0)
Signature · 1 line
2.55.0
#5 lore raw

PATCH 5/6 ALSA: mts64: Check card index validity at probe

In reply to Takashi Iwai

Although mts64 driver has a check of the given devptr->id value, it doesn't check for a negative id, which is often given as "none" or such value when bound via sysfs. This may lead to OOB access for index[] and other parameters.

Add a sanity check for the card index and warn/correct it if it's a value out of the range.

---
 sound/drivers/mts64.c | 6 ++++++
 1 file changed, 6 insertions(+)
sound/drivers/mts64.c +6 -0
index 36e9eab204ca..cefaa00b83e7 100644
@@ -900,6 +900,12 @@ static int snd_mts64_probe(struct platform_device *pdev)
 	p = platform_get_drvdata(pdev);
 	platform_set_drvdata(pdev, NULL);
 
+	if (dev < 0) {
+		dev_warn(&pdev->dev,
+			 "Invalid card index %d, using default 0\n", dev);
+		dev = 0;
+	}
+
 	if (dev >= SNDRV_CARDS)
 		return -ENODEV;
 	if (!enable[dev]) 
Signature · 1 line
2.55.0
#6 lore raw

PATCH 6/6 ALSA: portman2x4: Check card index validity at probe

In reply to Takashi Iwai

Although portman2x4 driver has a check of the given devptr->id value, it doesn't check for a negative id, which is often given as "none" or such value when bound via sysfs. This may lead to OOB access for index[] and other parameters.

Add a sanity check for the card index and warn/correct it if it's a value out of the range.

---
 sound/drivers/portman2x4.c | 6 ++++++
 1 file changed, 6 insertions(+)
sound/drivers/portman2x4.c +6 -0
index dcc0899cfb99..03ed3c3c27fb 100644
@@ -697,6 +697,12 @@ static int snd_portman_probe(struct platform_device *pdev)
 	p = platform_get_drvdata(pdev);
 	platform_set_drvdata(pdev, NULL);
 
+	if (dev < 0) {
+		dev_warn(&pdev->dev,
+			 "Invalid card index %d, using default 0\n", dev);
+		dev = 0;
+	}
+
 	if (dev >= SNDRV_CARDS)
 		return -ENODEV;
 	if (!enable[dev]) 
Signature · 1 line
2.55.0