ALSA: Check card index validity at probe
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
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
@@ -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
PATCH 2/6 ALSA: mpu401: Check card index validity at probe
In reply to Takashi Iwaimpu401 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
@@ -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
PATCH 3/6 ALSA: serial-u16550: Check card index validity at probe
In reply to Takashi Iwaiserial-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
@@ -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
PATCH 4/6 ALSA: virmidi: Check card index validity at probe
In reply to Takashi Iwaivirmidi 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
@@ -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
PATCH 5/6 ALSA: mts64: Check card index validity at probe
In reply to Takashi IwaiAlthough 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
@@ -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
PATCH 6/6 ALSA: portman2x4: Check card index validity at probe
In reply to Takashi IwaiAlthough 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
@@ -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