OSS: keep index within bounds of midi_devs[]
PATCH 1/1 OSS: keep index within bounds of midi_devs[]
When the {orig,midi}_dev equals num_midis, that's one too large already.
---
In MIDIbuf_open() sound/oss/midibuf.c:166
if (num_midis > MAX_MIDI_DEV)
{
printk(KERN_ERR "midi: Too many midi interfaces\n");
num_midis = MAX_MIDI_DEV;
}num_midis is at most MAX_MIDI_DEV.
`git grep -n MAX_MIDI_DEV' and note that when the index equals num_midis this causes reads/writes outside array bounds for midi_devs, midi2synth, dev_conf and others (below check in patch).
sound/oss/midi_synth.c | 2 +- sound/oss/mpu401.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
sound/oss/midi_synth.c +1 -1
@@ -426,7 +426,7 @@ midi_synth_open(int dev, int mode)int err;struct midi_input_info *inc; -if (orig_dev <0 || orig_dev > num_midis || midi_devs[orig_dev] ==NULL ) +if (orig_dev <0 || orig_dev >= num_midis || midi_devs[orig_dev] ==NULL )return -ENXIO ; midi2synth[orig_dev] = dev;
sound/oss/mpu401.c +1 -1
@@ -770,7 +770,7 @@ static int mpu_synth_ioctl(int dev, unsigned int cmd, void __user *arg) midi_dev = synth_devs[dev]->midi_dev; -if (midi_dev <0 || midi_dev > num_midis || midi_devs[midi_dev] ==NULL ) +if (midi_dev <0 || midi_dev >= num_midis || midi_devs[midi_dev] ==NULL )return -ENXIO ; devc = &dev_conf[midi_dev];
At Mon, 16 Nov 2009 17:05:02 +0100,
Quoted 14 lines · Roel Kluin
When the {orig,midi}_dev equals
num_midis, that's one too large already.Signed-off-by Roel Kluin <[email protected]>---
InMIDIbuf_open()sound/oss/midibuf.c:166if (num_midis > MAX_MIDI_DEV) { printk(KERN_ERR "midi: Too many midi interfaces\n"); num_midis = MAX_MIDI_DEV; }
Quoted 5 lines
num_midisis at mostMAX_MIDI_DEV.`git grep -n
MAX_MIDI_DEV' and note that when the index equalsnum_midisthis causes reads/writes outside array bounds formidi_devs, midi2synth,dev_confand others (below check in patch).
The fix looks correct to me. Applied now.
Thanks.
Takashi
Quoted 32 lines
sound/oss/midi_synth.c | 2 +- sound/oss/mpu401.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)sound/oss/midi_synth.c +1
-1@@ -426,7 +426,7 @@ midi_synth_open(int dev, int mode)int err;struct midi_input_info *inc; -if (orig_dev <0 || orig_dev > num_midis || midi_devs[orig_dev] ==NULL ) +if (orig_dev <0 || orig_dev >= num_midis || midi_devs[orig_dev] ==NULL )return -ENXIO ; midi2synth[orig_dev] = dev;sound/oss/mpu401.c +1
-1@@ -770,7 +770,7 @@ static int mpu_synth_ioctl(int dev, unsigned int cmd, void __user *arg) midi_dev = synth_devs[dev]->midi_dev; -if (midi_dev <0 || midi_dev > num_midis || midi_devs[midi_dev] ==NULL ) +if (midi_dev <0 || midi_dev >= num_midis || midi_devs[midi_dev] ==NULL )return -ENXIO ; devc = &dev_conf[midi_dev];