diff options
| author | Takashi Iwai <tiwai@suse.de> | 2026-08-06 17:32:21 +0200 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2026-09-07 17:18:23 +0200 |
| commit | 43f161c53279adac0517cf1c443e531e738b54ce (patch) | |
| tree | 5ef2b2b598a39da92efce40f5af6488878eddba7 | |
| parent | fbf3fb097e66fc1874e54ecc46d600d9325480d6 (diff) | |
| download | linux-43f161c53279adac0517cf1c443e531e738b54ce.tar.gz linux-43f161c53279adac0517cf1c443e531e738b54ce.zip | |
ALSA: virmidi: Check card index validity at probe
commit b65d5182ecd6b7a24a83d980a0d06e809ef876c5 upstream.
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.
Cc: stable@vger.kernel.org
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20260806153227.1460166-5-tiwai@suse.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
| -rw-r--r-- | sound/drivers/virmidi.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/sound/drivers/virmidi.c b/sound/drivers/virmidi.c index 5f7b65ad63e3..266643abfea8 100644 --- a/sound/drivers/virmidi.c +++ b/sound/drivers/virmidi.c @@ -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) |
