aboutsummaryrefslogtreecommitdiffstats
path: root/sound/oss
diff options
context:
space:
mode:
authorDan Rosenberg <drosenberg@vsecurity.com>2011-03-23 10:53:41 -0400
committerTakashi Iwai <tiwai@suse.de>2011-03-23 17:47:46 -0400
commitb769f49463711205d57286e64cf535ed4daf59e9 (patch)
tree1c674fdbed533434d2ba9b7b1b3646243160e55c /sound/oss
parentce24f58a1187ca3058d72c3f897e3b574209ab20 (diff)
sound/oss: remove offset from load_patch callbacks
Was: [PATCH] sound/oss/midi_synth: prevent underflow, use of uninitialized value, and signedness issue The offset passed to midi_synth_load_patch() can be essentially arbitrary. If it's greater than the header length, this will result in a copy_from_user(dst, src, negative_val). While this will just return -EFAULT on x86, on other architectures this may cause memory corruption. Additionally, the length field of the sysex_info structure may not be initialized prior to its use. Finally, a signed comparison may result in an unintentionally large loop. On suggestion by Takashi Iwai, version two removes the offset argument from the load_patch callbacks entirely, which also resolves similar issues in opl3. Compile tested only. v3 adjusts comments and hopefully gets copy offsets right. Signed-off-by: Dan Rosenberg <drosenberg@vsecurity.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/oss')
-rw-r--r--sound/oss/dev_table.h2
-rw-r--r--sound/oss/midi_synth.c30
-rw-r--r--sound/oss/midi_synth.h2
-rw-r--r--sound/oss/opl3.c8
-rw-r--r--sound/oss/sequencer.c2
5 files changed, 18 insertions, 26 deletions
diff --git a/sound/oss/dev_table.h b/sound/oss/dev_table.h
index b7617bee6388..0199a317c5a9 100644
--- a/sound/oss/dev_table.h
+++ b/sound/oss/dev_table.h
@@ -271,7 +271,7 @@ struct synth_operations
271 void (*reset) (int dev); 271 void (*reset) (int dev);
272 void (*hw_control) (int dev, unsigned char *event); 272 void (*hw_control) (int dev, unsigned char *event);
273 int (*load_patch) (int dev, int format, const char __user *addr, 273 int (*load_patch) (int dev, int format, const char __user *addr,
274 int offs, int count, int pmgr_flag); 274 int count, int pmgr_flag);
275 void (*aftertouch) (int dev, int voice, int pressure); 275 void (*aftertouch) (int dev, int voice, int pressure);
276 void (*controller) (int dev, int voice, int ctrl_num, int value); 276 void (*controller) (int dev, int voice, int ctrl_num, int value);
277 void (*panning) (int dev, int voice, int value); 277 void (*panning) (int dev, int voice, int value);
diff --git a/sound/oss/midi_synth.c b/sound/oss/midi_synth.c
index 3c09374ea5bf..2292c230d7e6 100644
--- a/sound/oss/midi_synth.c
+++ b/sound/oss/midi_synth.c
@@ -476,7 +476,7 @@ EXPORT_SYMBOL(midi_synth_hw_control);
476 476
477int 477int
478midi_synth_load_patch(int dev, int format, const char __user *addr, 478midi_synth_load_patch(int dev, int format, const char __user *addr,
479 int offs, int count, int pmgr_flag) 479 int count, int pmgr_flag)
480{ 480{
481 int orig_dev = synth_devs[dev]->midi_dev; 481 int orig_dev = synth_devs[dev]->midi_dev;
482 482
@@ -491,33 +491,29 @@ midi_synth_load_patch(int dev, int format, const char __user *addr,
491 if (!prefix_cmd(orig_dev, 0xf0)) 491 if (!prefix_cmd(orig_dev, 0xf0))
492 return 0; 492 return 0;
493 493
494 /* Invalid patch format */
494 if (format != SYSEX_PATCH) 495 if (format != SYSEX_PATCH)
495 {
496/* printk("MIDI Error: Invalid patch format (key) 0x%x\n", format);*/
497 return -EINVAL; 496 return -EINVAL;
498 } 497
498 /* Patch header too short */
499 if (count < hdr_size) 499 if (count < hdr_size)
500 {
501/* printk("MIDI Error: Patch header too short\n");*/
502 return -EINVAL; 500 return -EINVAL;
503 } 501
504 count -= hdr_size; 502 count -= hdr_size;
505 503
506 /* 504 /*
507 * Copy the header from user space but ignore the first bytes which have 505 * Copy the header from user space
508 * been transferred already.
509 */ 506 */
510 507
511 if(copy_from_user(&((char *) &sysex)[offs], &(addr)[offs], hdr_size - offs)) 508 if (copy_from_user(&sysex, addr, hdr_size))
512 return -EFAULT; 509 return -EFAULT;
513 510
514 if (count < sysex.len) 511 /* Sysex record too short */
515 { 512 if ((unsigned)count < (unsigned)sysex.len)
516/* printk(KERN_WARNING "MIDI Warning: Sysex record too short (%d<%d)\n", count, (int) sysex.len);*/
517 sysex.len = count; 513 sysex.len = count;
518 } 514
519 left = sysex.len; 515 left = sysex.len;
520 src_offs = 0; 516 src_offs = 0;
521 517
522 for (i = 0; i < left && !signal_pending(current); i++) 518 for (i = 0; i < left && !signal_pending(current); i++)
523 { 519 {
diff --git a/sound/oss/midi_synth.h b/sound/oss/midi_synth.h
index 6bc9d00bc77c..b64ddd6c4abc 100644
--- a/sound/oss/midi_synth.h
+++ b/sound/oss/midi_synth.h
@@ -8,7 +8,7 @@ int midi_synth_open (int dev, int mode);
8void midi_synth_close (int dev); 8void midi_synth_close (int dev);
9void midi_synth_hw_control (int dev, unsigned char *event); 9void midi_synth_hw_control (int dev, unsigned char *event);
10int midi_synth_load_patch (int dev, int format, const char __user * addr, 10int midi_synth_load_patch (int dev, int format, const char __user * addr,
11 int offs, int count, int pmgr_flag); 11 int count, int pmgr_flag);
12void midi_synth_panning (int dev, int channel, int pressure); 12void midi_synth_panning (int dev, int channel, int pressure);
13void midi_synth_aftertouch (int dev, int channel, int pressure); 13void midi_synth_aftertouch (int dev, int channel, int pressure);
14void midi_synth_controller (int dev, int channel, int ctrl_num, int value); 14void midi_synth_controller (int dev, int channel, int ctrl_num, int value);
diff --git a/sound/oss/opl3.c b/sound/oss/opl3.c
index 938c48c43585..cbf957424d5c 100644
--- a/sound/oss/opl3.c
+++ b/sound/oss/opl3.c
@@ -820,7 +820,7 @@ static void opl3_hw_control(int dev, unsigned char *event)
820} 820}
821 821
822static int opl3_load_patch(int dev, int format, const char __user *addr, 822static int opl3_load_patch(int dev, int format, const char __user *addr,
823 int offs, int count, int pmgr_flag) 823 int count, int pmgr_flag)
824{ 824{
825 struct sbi_instrument ins; 825 struct sbi_instrument ins;
826 826
@@ -830,11 +830,7 @@ static int opl3_load_patch(int dev, int format, const char __user *addr,
830 return -EINVAL; 830 return -EINVAL;
831 } 831 }
832 832
833 /* 833 if (copy_from_user(&ins, addr, sizeof(ins)))
834 * What the fuck is going on here? We leave junk in the beginning
835 * of ins and then check the field pretty close to that beginning?
836 */
837 if(copy_from_user(&((char *) &ins)[offs], addr + offs, sizeof(ins) - offs))
838 return -EFAULT; 834 return -EFAULT;
839 835
840 if (ins.channel < 0 || ins.channel >= SBFM_MAXINSTR) 836 if (ins.channel < 0 || ins.channel >= SBFM_MAXINSTR)
diff --git a/sound/oss/sequencer.c b/sound/oss/sequencer.c
index 5ea1098ac427..30bcfe470f83 100644
--- a/sound/oss/sequencer.c
+++ b/sound/oss/sequencer.c
@@ -241,7 +241,7 @@ int sequencer_write(int dev, struct file *file, const char __user *buf, int coun
241 return -ENXIO; 241 return -ENXIO;
242 242
243 fmt = (*(short *) &event_rec[0]) & 0xffff; 243 fmt = (*(short *) &event_rec[0]) & 0xffff;
244 err = synth_devs[dev]->load_patch(dev, fmt, buf, p + 4, c, 0); 244 err = synth_devs[dev]->load_patch(dev, fmt, buf + p, c, 0);
245 if (err < 0) 245 if (err < 0)
246 return err; 246 return err;
247 247