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>
This commit is contained in:
committed by
Takashi Iwai
parent
ce24f58a11
commit
b769f49463
@ -476,7 +476,7 @@ EXPORT_SYMBOL(midi_synth_hw_control);
|
||||
|
||||
int
|
||||
midi_synth_load_patch(int dev, int format, const char __user *addr,
|
||||
int offs, int count, int pmgr_flag)
|
||||
int count, int pmgr_flag)
|
||||
{
|
||||
int orig_dev = synth_devs[dev]->midi_dev;
|
||||
|
||||
@ -491,33 +491,29 @@ midi_synth_load_patch(int dev, int format, const char __user *addr,
|
||||
if (!prefix_cmd(orig_dev, 0xf0))
|
||||
return 0;
|
||||
|
||||
/* Invalid patch format */
|
||||
if (format != SYSEX_PATCH)
|
||||
{
|
||||
/* printk("MIDI Error: Invalid patch format (key) 0x%x\n", format);*/
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Patch header too short */
|
||||
if (count < hdr_size)
|
||||
{
|
||||
/* printk("MIDI Error: Patch header too short\n");*/
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
count -= hdr_size;
|
||||
|
||||
/*
|
||||
* Copy the header from user space but ignore the first bytes which have
|
||||
* been transferred already.
|
||||
* Copy the header from user space
|
||||
*/
|
||||
|
||||
if(copy_from_user(&((char *) &sysex)[offs], &(addr)[offs], hdr_size - offs))
|
||||
if (copy_from_user(&sysex, addr, hdr_size))
|
||||
return -EFAULT;
|
||||
|
||||
if (count < sysex.len)
|
||||
{
|
||||
/* printk(KERN_WARNING "MIDI Warning: Sysex record too short (%d<%d)\n", count, (int) sysex.len);*/
|
||||
|
||||
/* Sysex record too short */
|
||||
if ((unsigned)count < (unsigned)sysex.len)
|
||||
sysex.len = count;
|
||||
}
|
||||
left = sysex.len;
|
||||
src_offs = 0;
|
||||
|
||||
left = sysex.len;
|
||||
src_offs = 0;
|
||||
|
||||
for (i = 0; i < left && !signal_pending(current); i++)
|
||||
{
|
||||
|
Reference in New Issue
Block a user